From 1ad48b6da81a81daa3df5d3859197a3681386c42 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Sat, 13 May 2023 04:05:09 +0000 Subject: [PATCH 01/72] Setting up GitHub Classroom Feedback From 4b94b24947b571fef1730b28c94e298977eb1b45 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Sat, 13 May 2023 04:05:12 +0000 Subject: [PATCH 02/72] Add assignment deadline url --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..0b3daa1 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-24ddc0f5d75046c5622901739e7c5dd533143b0c8e959d652212380cedb1ea36.svg)](https://classroom.github.com/a/bM1wuWkJ) From cd23368b8d81338f9f8babc7a7b7a9574007c796 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Wed, 31 May 2023 16:03:15 -0700 Subject: [PATCH 03/72] redo --- README.md | 12 ++++- __init__.py | 0 main.py | 0 requirements.txt | 1 + src/__init__.py | 0 src/championship/__init__.py | 0 src/championship/championship.py | 86 ++++++++++++++++++++++++++++++++ src/driver/__init__.py | 0 src/driver/driver.py | 7 +++ src/race/__init__.py | 0 src/race/race.py | 5 ++ src/round/__init__.py | 0 src/round/round.py | 16 ++++++ src/series/__init__.py | 0 src/series/series.py | 5 ++ src/team/__init__.py | 0 src/team/team.py | 6 +++ tests/__init__.py | 0 18 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 __init__.py create mode 100644 main.py create mode 100644 requirements.txt create mode 100644 src/__init__.py create mode 100644 src/championship/__init__.py create mode 100644 src/championship/championship.py create mode 100644 src/driver/__init__.py create mode 100644 src/driver/driver.py create mode 100644 src/race/__init__.py create mode 100644 src/race/race.py create mode 100644 src/round/__init__.py create mode 100644 src/round/round.py create mode 100644 src/series/__init__.py create mode 100644 src/series/series.py create mode 100644 src/team/__init__.py create mode 100644 src/team/team.py create mode 100644 tests/__init__.py diff --git a/README.md b/README.md index 0b3daa1..f623117 100644 --- a/README.md +++ b/README.md @@ -1 +1,11 @@ -[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-24ddc0f5d75046c5622901739e7c5dd533143b0c8e959d652212380cedb1ea36.svg)](https://classroom.github.com/a/bM1wuWkJ) +# Motor racing info + +Provides information about various motor racing series, such as the teams, drivers, and points for a given season. + +Current implementation showcases the 2023 Season lineups for *Formula One* and *Indy Car*. + +## Usage + +`pip3 install -r requirements.txt` + +`python3 main.py` \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4f76fc7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +typing \ No newline at end of file diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/championship/__init__.py b/src/championship/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/championship/championship.py b/src/championship/championship.py new file mode 100644 index 0000000..c602bd4 --- /dev/null +++ b/src/championship/championship.py @@ -0,0 +1,86 @@ +from src.driver.driver import Driver +from src.race.race import Race +from src.round.round import Round +from src.series.series import Series +from src.team.team import Team +from typing import List + +class Championship(): + def __init__(self, series: Series, year: int): + if not isinstance(series, Series): + raise TypeError(f"") + if not isinstance(year, int): + raise TypeError(f"") + + self.series = series + self.year = year + + self.rounds = dict() # the key = race: Race, value = results: List(Driver) + + self.driver_standings = dict() + self.team_standings = dict() + + def addDriverToChampionship(self, driver: Driver): + """ + """ + if not isinstance(driver, Driver): + raise TypeError(f"") + + if not self.driver_standings.get(driver): + self.driver_standings[driver] = 0 + + def addTeamToChampionship(self, team: Team): + """ + """ + if not isinstance(team, Team): + raise TypeError(f"") + + self.team_standings[team] = 0 # add team to team standings, set points to 0 + + for d in team.drivers: # for each of the team's drivers + if not isinstance(d, Driver): + raise TypeError(f"") + + if not self.driver_standings.get(d): # if driver is not already in driver's championship + self.addDriverToChampionship(d) # add to driver's championship + + def getDriverStandings(self) -> List: + ''' + get current driver standings + ''' + # TODO + pass + + def getTeamStandings(self) -> List: + ''' + get current team standings + ''' + # TODO + pass + + def holdRace(self, race: Race, results: List[Driver]): + if not isinstance(race, Race): + raise TypeError(f"") + + if not self.rounds.get(race): + self.rounds[race] = list() + + points_system = [None, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + + for i in range(1, 11): # only the top 10 drivers get points + if not isinstance(results[i], Driver): + raise TypeError(f"") + + # update values for driver standings and team standings + + # update driver standings + + self.driver_standings[results[i]] += points_system[i] + + if results.count(results[i]) > 1: # if this driver won fastest lap + self.driver_standings[results[i]] += 1 + + # update team standings + # TODO + + self.rounds[race] = results \ No newline at end of file diff --git a/src/driver/__init__.py b/src/driver/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/driver/driver.py b/src/driver/driver.py new file mode 100644 index 0000000..15410cd --- /dev/null +++ b/src/driver/driver.py @@ -0,0 +1,7 @@ + + +class Driver(): + def __init__(self, surname: str, givenname: str, nationality: str): + self.surname = surname + self.givenname = givenname + self.nationality = nationality \ No newline at end of file diff --git a/src/race/__init__.py b/src/race/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/race/race.py b/src/race/race.py new file mode 100644 index 0000000..e931463 --- /dev/null +++ b/src/race/race.py @@ -0,0 +1,5 @@ + + +class Race(): + def __init__(self): + pass \ No newline at end of file diff --git a/src/round/__init__.py b/src/round/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/round/round.py b/src/round/round.py new file mode 100644 index 0000000..ab1167f --- /dev/null +++ b/src/round/round.py @@ -0,0 +1,16 @@ +from src.driver.driver import Driver +from src.race.race import Race + +class Round(): + def __init__(self, race: Race): + if not isinstance(race, Race): + raise TypeError(f"") + + self.race = race + self.results = list(Driver) + + def setResults(self, results: list(Driver)): + if not isinstance(results, list): + raise TypeError(f"") + + self.results = results \ No newline at end of file diff --git a/src/series/__init__.py b/src/series/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/series/series.py b/src/series/series.py new file mode 100644 index 0000000..150833a --- /dev/null +++ b/src/series/series.py @@ -0,0 +1,5 @@ + + +class Series(): + def __init__(self, name: str): + self.name = name \ No newline at end of file diff --git a/src/team/__init__.py b/src/team/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/team/team.py b/src/team/team.py new file mode 100644 index 0000000..04db92c --- /dev/null +++ b/src/team/team.py @@ -0,0 +1,6 @@ +from src.driver.driver import Driver + +class Team(): + def __init__(self, name: str): + self.name = name + self.drivers = list(Driver) \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 From 3a469fb9ff8516e26b18be2ea7729e90898d00b1 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Fri, 2 Jun 2023 12:55:55 -0700 Subject: [PATCH 04/72] expanding --- main.py | 13 ++++++++ src/championship/championship.py | 52 ++++++++++++++++++++++++++++---- src/race/race.py | 13 ++++++-- src/round/__init__.py | 0 src/round/round.py | 16 ---------- src/team/team.py | 25 +++++++++++++-- 6 files changed, 93 insertions(+), 26 deletions(-) delete mode 100644 src/round/__init__.py delete mode 100644 src/round/round.py diff --git a/main.py b/main.py index e69de29..43791e1 100644 --- a/main.py +++ b/main.py @@ -0,0 +1,13 @@ +from src.championship.championship import Championship +from src.driver.driver import Driver +from src.race.race import Race +from src.series.series import Series +from src.team.team import Team + +def main(): + formula_one = Series("Formula One") + + formula_one_2023 = Championship(series = formula_one, year = 2023) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/src/championship/championship.py b/src/championship/championship.py index c602bd4..469ef6b 100644 --- a/src/championship/championship.py +++ b/src/championship/championship.py @@ -1,11 +1,14 @@ from src.driver.driver import Driver from src.race.race import Race -from src.round.round import Round from src.series.series import Series from src.team.team import Team from typing import List class Championship(): + """ + a class to represent a series championship. + associated with a series (e.g. Formula One, IndyCar, Nascar) and a year (e.g. 2022, 2023) + """ def __init__(self, series: Series, year: int): if not isinstance(series, Series): raise TypeError(f"") @@ -15,25 +18,43 @@ def __init__(self, series: Series, year: int): self.series = series self.year = year - self.rounds = dict() # the key = race: Race, value = results: List(Driver) + self.rounds = dict() # key = race: Race, value = results: List(Driver) self.driver_standings = dict() self.team_standings = dict() - def addDriverToChampionship(self, driver: Driver): + def addDriverToChampionship(self, driver: Driver | List(Driver)): """ + adds a driver or a list of drivers to the championship + + params: + driver: Driver | List(Driver) """ if not isinstance(driver, Driver): - raise TypeError(f"") + if not isinstance(driver, List): + raise TypeError(f"") + + for d in driver: + self.addDriverToChampionship(d) + return if not self.driver_standings.get(driver): self.driver_standings[driver] = 0 - def addTeamToChampionship(self, team: Team): + def addTeamToChampionship(self, team: Team | List(Team)): """ + adds a team or a list of teams to the championship + + params: + team: Team | List(Team) """ if not isinstance(team, Team): - raise TypeError(f"") + if not isinstance(team, List): + raise TypeError(f"") + + for t in team: + self.addTeamToChampionship(t) + return self.team_standings[team] = 0 # add team to team standings, set points to 0 @@ -47,6 +68,12 @@ def addTeamToChampionship(self, team: Team): def getDriverStandings(self) -> List: ''' get current driver standings + + param: + None + + returns: + List ''' # TODO pass @@ -54,11 +81,24 @@ def getDriverStandings(self) -> List: def getTeamStandings(self) -> List: ''' get current team standings + + param: + None + + returns: + List ''' # TODO pass def holdRace(self, race: Race, results: List[Driver]): + ''' + holds a race and updates standings given the results + + param: + race: Race + results: List[Driver] + ''' if not isinstance(race, Race): raise TypeError(f"") diff --git a/src/race/race.py b/src/race/race.py index e931463..980b785 100644 --- a/src/race/race.py +++ b/src/race/race.py @@ -1,5 +1,14 @@ class Race(): - def __init__(self): - pass \ No newline at end of file + def __init__(self, name: str, country: str, city: str): + if not isinstance(name, str): + raise TypeError(f"") + if not isinstance(country, str): + raise TypeError(f"") + if not isinstance(city, str): + raise TypeError(f"") + + self.name = name + self.country = country + self.city = city \ No newline at end of file diff --git a/src/round/__init__.py b/src/round/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/round/round.py b/src/round/round.py deleted file mode 100644 index ab1167f..0000000 --- a/src/round/round.py +++ /dev/null @@ -1,16 +0,0 @@ -from src.driver.driver import Driver -from src.race.race import Race - -class Round(): - def __init__(self, race: Race): - if not isinstance(race, Race): - raise TypeError(f"") - - self.race = race - self.results = list(Driver) - - def setResults(self, results: list(Driver)): - if not isinstance(results, list): - raise TypeError(f"") - - self.results = results \ No newline at end of file diff --git a/src/team/team.py b/src/team/team.py index 04db92c..60cc4f7 100644 --- a/src/team/team.py +++ b/src/team/team.py @@ -1,6 +1,27 @@ from src.driver.driver import Driver class Team(): - def __init__(self, name: str): + def __init__(self, name: str, country: str): + if not isinstance(name, str): + raise TypeError(f"{name} must be of type str, not {type(name)}") + if not isinstance(country, str): + raise TypeError(f"{country} must be of type str, not {type(country)}") + self.name = name - self.drivers = list(Driver) \ No newline at end of file + self.country = country + + self.drivers = list(Driver) + + def addDriverToTeam(self, driver: Driver): + if not isinstance(driver, Driver): + raise TypeError(f"") + + if driver not in self.drivers: + self.drivers.append(driver) + + def removeDriverFromTeam(self, driver: Driver): + if not isinstance(driver, Driver): + raise TypeError(f"") + + if driver in self.drivers: + self.drivers.remove(driver) \ No newline at end of file From 4db9e778d0a4e151cd75d706fa0518aa74d5adc7 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Fri, 2 Jun 2023 13:06:06 -0700 Subject: [PATCH 05/72] add helper methods --- src/championship/championship.py | 13 +++++++++++++ src/team/team.py | 3 +++ 2 files changed, 16 insertions(+) diff --git a/src/championship/championship.py b/src/championship/championship.py index 469ef6b..821d57e 100644 --- a/src/championship/championship.py +++ b/src/championship/championship.py @@ -65,6 +65,19 @@ def addTeamToChampionship(self, team: Team | List(Team)): if not self.driver_standings.get(d): # if driver is not already in driver's championship self.addDriverToChampionship(d) # add to driver's championship + def removeTeamFromChampionship(self, team: Team): + """ + adds a team or a list of teams to the championship + + params: + team: Team + """ + if not isinstance(team, Team): + raise TypeError(f"") + + if self.team_standings.get(team): + self.team_standings.pop(team) + def getDriverStandings(self) -> List: ''' get current driver standings diff --git a/src/team/team.py b/src/team/team.py index 60cc4f7..115b481 100644 --- a/src/team/team.py +++ b/src/team/team.py @@ -1,6 +1,9 @@ from src.driver.driver import Driver class Team(): + """ + a class to represent a racing team. + """ def __init__(self, name: str, country: str): if not isinstance(name, str): raise TypeError(f"{name} must be of type str, not {type(name)}") From 75f5c8f76bee4fcb28168c6f586a72236828b2a3 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Sun, 4 Jun 2023 23:26:10 -0700 Subject: [PATCH 06/72] add teamfactory. add new engine attribute and related classes --- src/engine/__init__.py | 0 src/engine/engine.py | 33 +++++++++++++++ src/team/team.py | 16 ++++++-- src/team/teamFactory.py | 90 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 src/engine/__init__.py create mode 100644 src/engine/engine.py create mode 100644 src/team/teamFactory.py diff --git a/src/engine/__init__.py b/src/engine/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/engine/engine.py b/src/engine/engine.py new file mode 100644 index 0000000..0b8a375 --- /dev/null +++ b/src/engine/engine.py @@ -0,0 +1,33 @@ +from abc import ABC + +class EngineInt(ABC): + pass + +class Engine(EngineInt): + def __init__(self, engine: str): + if not isinstance(engine, str): + raise TypeError(f"{engine} must be of type str, not {type(engine)}") + self.engine = engine + +class FerrariEngine(EngineInt): + def __init__(self): + self.engine = "Ferrari" + +class HondaRBPTEngine(EngineInt): + def __init__(self): + # I know, the name is far too long. I didn't choose it, Red Bull did + self.engine = "Honda Red Bull Power Trains" + +class MercedesEngine(EngineInt): + def __init__(self): + self.engine = "Mercedes" + +class RenaultEngine(EngineInt): + ''' + an engine manufactured by Renault. + + Fun Fact: Renault was one of the victims of WannaCry! + https://www.nbcnews.com/business/autos/european-car-plants-halted-wannacry-ransomware-attack-n759496 + ''' + def __init__(self): + self.engine = "Renault" \ No newline at end of file diff --git a/src/team/team.py b/src/team/team.py index 115b481..261f562 100644 --- a/src/team/team.py +++ b/src/team/team.py @@ -1,23 +1,33 @@ from src.driver.driver import Driver +from src.engine.engine import * +from typing import List class Team(): """ a class to represent a racing team. """ - def __init__(self, name: str, country: str): + def __init__(self, name: str, engine: EngineInt, country: str, drivers: List[Driver]): if not isinstance(name, str): raise TypeError(f"{name} must be of type str, not {type(name)}") + if not isinstance(engine, EngineInt): + raise TypeError(f"{engine} must be of type EngineInt or its subclasses, not {type(engine)}") if not isinstance(country, str): raise TypeError(f"{country} must be of type str, not {type(country)}") + if not isinstance(drivers, list): + raise TypeError(f"{drivers} must be of type list, not {type(drivers)}") self.name = name + self.engine = engine self.country = country + self.drivers = list() - self.drivers = list(Driver) + # because the addDriverToTeam method does type checking internally, we don't need to create an extra for loop to check each item in the list of prospective drivers + for driver in drivers: + self.addDriverToTeam(driver = driver) def addDriverToTeam(self, driver: Driver): if not isinstance(driver, Driver): - raise TypeError(f"") + raise TypeError(f"{driver} must be of type Driver, not {type(driver)}") if driver not in self.drivers: self.drivers.append(driver) diff --git a/src/team/teamFactory.py b/src/team/teamFactory.py new file mode 100644 index 0000000..54ae4ff --- /dev/null +++ b/src/team/teamFactory.py @@ -0,0 +1,90 @@ +from src.driver.driver import Driver +from src.engine.engine import * +from src.team.team import Team +from typing import List + +class TeamFactory: + def createTeam(self, name: str, engine: EngineInt | str, country: str, drivers: List(Driver)) -> Team: + """ + create a team with a custom engine + + params: + + name: str + engine: EngineInt | str + country: str + drivers: List(Driver) + + returns: + Team + """ + + if isinstance(engine, str): + engine = Engine(engine = engine) + + return Team(name = name, engine = engine, country = country, drivers = drivers) + + def createTeamFerrariEngine(self, name: str, country: str, drivers: List(Driver)) -> Team: + """ + create a team with a Ferrari engine + + params: + + name: str + country: str + drivers: List(Driver) + + returns: + Team + """ + + return Team(name = name, engine = FerrariEngine(), country = country, drivers = drivers) + + def createTeamHondaRBPTEngine(self, name: str, country: str, drivers: List(Driver)) -> Team: + """ + create a team with a Honda Red Bull Power Trains engine + + params: + + name: str + country: str + drivers: List(Driver) + + returns: + Team + """ + + return Team(name = name, engine = HondaRBPTEngine(), country = country, drivers = drivers) + + def createTeamMercedesEngine(self, name: str, country: str, drivers: List(Driver)) -> Team: + """ + create a team with a Mercedes engine + + params: + + name: str + country: str + drivers: List(Driver) + + returns: + Team + """ + + return Team(name = name, engine = MercedesEngine(), country = country, drivers = drivers) + + def createTeamRenaultEngine(self, name: str, country: str, drivers: List(Driver)) -> Team: + """ + create a team with a Renault engine + + params: + + name: str + country: str + drivers: List(Driver) + + returns: + Team + """ + + return Team(name = name, engine = RenaultEngine(), country = country, drivers = drivers) + \ No newline at end of file From ff8539cf87ed5ab5fce421f7cf0eda0f0c237bd6 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Sun, 4 Jun 2023 23:42:44 -0700 Subject: [PATCH 07/72] add attribute for if driver's surname should be before the givenname, and associated method for formatting the name --- src/driver/driver.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/driver/driver.py b/src/driver/driver.py index 15410cd..4c9cf39 100644 --- a/src/driver/driver.py +++ b/src/driver/driver.py @@ -1,7 +1,20 @@ class Driver(): - def __init__(self, surname: str, givenname: str, nationality: str): + def __init__(self, surname: str, givenname: str, nationality: str, surname_first: bool = False): self.surname = surname self.givenname = givenname - self.nationality = nationality \ No newline at end of file + self.nationality = nationality + self.surname_first = surname_first + + def getNameFormatted(self) -> str: + ''' + formats the name of the driver as `LAST First` or `First LAST` depending on driver preference + + returns: + str + ''' + if self.surname_first: + return f"{self.surname.upper()} {self.givenname}" + + return f"{self.givenname} {self.surname.upper()}" \ No newline at end of file From 2b1349f2ff93dfefb788d5c478b0e9d66d479788 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Sun, 4 Jun 2023 23:54:59 -0700 Subject: [PATCH 08/72] instantiate teams and add them to the championship --- main.py | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/main.py b/main.py index 43791e1..ca98197 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,115 @@ from src.championship.championship import Championship from src.driver.driver import Driver +from src.engine.engine import * from src.race.race import Race from src.series.series import Series from src.team.team import Team +from src.team.teamFactory import TeamFactory def main(): + + # instantiate the Formula One Series formula_one = Series("Formula One") + # instantiate the 2023 Formula One Championship formula_one_2023 = Championship(series = formula_one, year = 2023) + # create teams using TeamFactory + + formula_one_2023.addTeamToChampionship( + TeamFactory.createTeamFerrariEngine( + name = "Alfa Romeo", + country = "Switzerland", + drivers = [ + Driver(surname = "Bottas", givenname = "Valtteri", nationality = "Finland"), + Driver(surname = "Zhou", givenname = "Guanyu", nationality = "China", surname_first = True) + ] + ) + ) + formula_one_2023.addTeamToChampionship( + TeamFactory.createTeamHondaRBPTEngine( + name = "AlphaTauri", + country = "Italy", + drivers = [ + Driver(surname = "de Vries", givenname = "Nyck", nationality = "Netherlands"), + Driver(surname = "Tsunoda", givenname = "Yuki", nationality = "Japan") + ] + ) + ) + formula_one_2023.addTeamToChampionship( + TeamFactory.createTeamRenaultEngine( + name = "Alpine", + country = "France", + drivers = [ + # TODO add drivers + ] + ) + ) + formula_one_2023.addTeamToChampionship( + TeamFactory.createTeamMercedesEngine( + name = "Aston Martin", + country = "United Kingdom", + drivers = [ + # TODO add drivers + ] + ) + ) + formula_one_2023.addTeamToChampionship( + TeamFactory.createTeamFerrariEngine( + name = "Ferrari", # this is my second favorite team. They are terrible at strategy and there are multiple memes about how bad their strategy is + country = "Italy", + drivers = [ + # TODO add drivers + ] + ) + ) + formula_one_2023.addTeamToChampionship( + TeamFactory.createTeamFerrariEngine( + name = "Haas", + country = "United States", + drivers = [ + # TODO add drivers + ] + ) + ) + formula_one_2023.addTeamToChampionship( + TeamFactory.createTeamMercedesEngine( + name = "McLaren", + country = "United Kingdom", + drivers = [ + Driver(surname = "Norris", givenname = "Lando", nationality = "United Kingdom"), + Driver(surname = "Piastri", givenname = "Oscar", nationality = "Australia") + ] + ) + ) + formula_one_2023.addTeamToChampionship( + TeamFactory.createTeamMercedesEngine( + name = "Mercedes", # this is my favorite team + country = "Germany", + drivers = [ + Driver(surname = "Hamilton", givenname = "Lewis", nationality = "United Kingdom"), + Driver(surname = "Russell", givenname = "George", nationality = "United Kingdom") + ] + ) + ) + formula_one_2023.addTeamToChampionship( + TeamFactory.createTeamHondaRBPTEngine( + name = "Red Bull", # you're not going to believe this, but Red Bull is actually a better team right now than Ferrari + country = "Austria", + drivers = [ + # TODO add drivers + ] + ) + ) + formula_one_2023.addTeamToChampionship( + TeamFactory.createTeamMercedesEngine( + name = "Williams", + country = "United Kingdom", + drivers = [ + # TODO add drivers + ] + ) + ) + if __name__ == "__main__": main() \ No newline at end of file From 28d5d9d165036aec134d15bd21209fe06f5d3467 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Sun, 4 Jun 2023 23:55:16 -0700 Subject: [PATCH 09/72] how team works --- src/team/team.py | 2 +- src/team/teamFactory.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/team/team.py b/src/team/team.py index 261f562..a8bda9d 100644 --- a/src/team/team.py +++ b/src/team/team.py @@ -21,7 +21,7 @@ def __init__(self, name: str, engine: EngineInt, country: str, drivers: List[Dri self.country = country self.drivers = list() - # because the addDriverToTeam method does type checking internally, we don't need to create an extra for loop to check each item in the list of prospective drivers + # because the addDriverToTeam() method does type checking internally, we don't need to create an extra for loop to check each item in the list of prospective drivers. this saves processing time and memory! for driver in drivers: self.addDriverToTeam(driver = driver) diff --git a/src/team/teamFactory.py b/src/team/teamFactory.py index 54ae4ff..07a0df8 100644 --- a/src/team/teamFactory.py +++ b/src/team/teamFactory.py @@ -4,6 +4,7 @@ from typing import List class TeamFactory: + @staticmethod def createTeam(self, name: str, engine: EngineInt | str, country: str, drivers: List(Driver)) -> Team: """ create a team with a custom engine @@ -24,6 +25,7 @@ def createTeam(self, name: str, engine: EngineInt | str, country: str, drivers: return Team(name = name, engine = engine, country = country, drivers = drivers) + @staticmethod def createTeamFerrariEngine(self, name: str, country: str, drivers: List(Driver)) -> Team: """ create a team with a Ferrari engine @@ -40,6 +42,7 @@ def createTeamFerrariEngine(self, name: str, country: str, drivers: List(Driver) return Team(name = name, engine = FerrariEngine(), country = country, drivers = drivers) + @staticmethod def createTeamHondaRBPTEngine(self, name: str, country: str, drivers: List(Driver)) -> Team: """ create a team with a Honda Red Bull Power Trains engine @@ -56,6 +59,7 @@ def createTeamHondaRBPTEngine(self, name: str, country: str, drivers: List(Drive return Team(name = name, engine = HondaRBPTEngine(), country = country, drivers = drivers) + @staticmethod def createTeamMercedesEngine(self, name: str, country: str, drivers: List(Driver)) -> Team: """ create a team with a Mercedes engine @@ -72,6 +76,7 @@ def createTeamMercedesEngine(self, name: str, country: str, drivers: List(Driver return Team(name = name, engine = MercedesEngine(), country = country, drivers = drivers) + @staticmethod def createTeamRenaultEngine(self, name: str, country: str, drivers: List(Driver)) -> Team: """ create a team with a Renault engine From 8c16f74df49eba2d99cfd438d5f87fd6ea7e6a32 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Sun, 4 Jun 2023 23:59:31 -0700 Subject: [PATCH 10/72] add type checking for championship --- src/championship/championship.py | 33 ++++++++++---------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/championship/championship.py b/src/championship/championship.py index 821d57e..770a7bb 100644 --- a/src/championship/championship.py +++ b/src/championship/championship.py @@ -11,9 +11,9 @@ class Championship(): """ def __init__(self, series: Series, year: int): if not isinstance(series, Series): - raise TypeError(f"") + raise TypeError(f"{series} must be of type Series, not {type(series)}") if not isinstance(year, int): - raise TypeError(f"") + raise TypeError(f"{year} must be of type int, not {type(year)}") self.series = series self.year = year @@ -23,38 +23,28 @@ def __init__(self, series: Series, year: int): self.driver_standings = dict() self.team_standings = dict() - def addDriverToChampionship(self, driver: Driver | List(Driver)): + def addDriverToChampionship(self, driver: Driver): """ adds a driver or a list of drivers to the championship params: - driver: Driver | List(Driver) + driver: Driver """ if not isinstance(driver, Driver): - if not isinstance(driver, List): - raise TypeError(f"") - - for d in driver: - self.addDriverToChampionship(d) - return + raise TypeError(f"{driver} must be of type Driver, not {type(driver)}") if not self.driver_standings.get(driver): self.driver_standings[driver] = 0 - def addTeamToChampionship(self, team: Team | List(Team)): + def addTeamToChampionship(self, team: Team): """ - adds a team or a list of teams to the championship + adds a team to the championship params: - team: Team | List(Team) + team: Team """ if not isinstance(team, Team): - if not isinstance(team, List): - raise TypeError(f"") - - for t in team: - self.addTeamToChampionship(t) - return + raise TypeError(f"{team} must be of type Team, not {type(team)}") self.team_standings[team] = 0 # add team to team standings, set points to 0 @@ -82,9 +72,6 @@ def getDriverStandings(self) -> List: ''' get current driver standings - param: - None - returns: List ''' @@ -134,6 +121,6 @@ def holdRace(self, race: Race, results: List[Driver]): self.driver_standings[results[i]] += 1 # update team standings - # TODO + # TODO update the team standings (stretch goal???) self.rounds[race] = results \ No newline at end of file From 00f86d5027d500d8a3287c3087244b4b053d24ad Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 00:02:27 -0700 Subject: [PATCH 11/72] comments --- src/team/teamFactory.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/team/teamFactory.py b/src/team/teamFactory.py index 07a0df8..ba5d319 100644 --- a/src/team/teamFactory.py +++ b/src/team/teamFactory.py @@ -20,6 +20,7 @@ def createTeam(self, name: str, engine: EngineInt | str, country: str, drivers: Team """ + # if the user entered a str instead of an Engine, use the str as the parameter to create an Engine if isinstance(engine, str): engine = Engine(engine = engine) From 969cf32ac1a012324480b43ec611a8473a6eba02 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 00:05:31 -0700 Subject: [PATCH 12/72] update usage and project description --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f623117..f4b7c9a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,19 @@ -# Motor racing info +# Motor Racing Info -Provides information about various motor racing series, such as the teams, drivers, and points for a given season. +CLI program to track information about various motor racing series, such as the teams, drivers, engine manufacturers, and championship standings. -Current implementation showcases the 2023 Season lineups for *Formula One* and *Indy Car*. +Current implementation includes the Formula One 2023 Championship. ## Usage +### Install required packages + `pip3 install -r requirements.txt` +### Run unit tests + +`pytest tests` + +### Run the main program + `python3 main.py` \ No newline at end of file From ccef17162f652f1eba1f2f5b748a55088028614f Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 00:21:27 -0700 Subject: [PATCH 13/72] glossary of terms --- README.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f4b7c9a..75b6b6e 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,28 @@ CLI program to track information about various motor racing series, such as the Current implementation includes the Formula One 2023 Championship. +## Glossary of Terms + +*This glossary is listed in no particular order.* + +**Formula One** / **Formula 1** / **F1** +An international motor racing series featuring open wheel racing. Currently, Formula One races are only street circuits or road courses. Famous Formula One drivers include Michael Schumacher, Lewis Hamilton, Max Verstappen, Fernando Alonso, and Sebastian Vettel. + +**Formula Two** / **Formula 2** / **F2** +A junior series of Formula One. Similar to the relationship between Minor League Baseball and Major League Baseball. + +**Formula E** +The electric vehicle open wheel racing series governed by the FIA. + +**FIA** / **Fédération Internationale de l'Automobile** +The governing body of Formula One, and other related motor-racing series like Formula Two and Formula E. + +**IndyCar** +A series of open wheel racing based in the United States. Most race are in the United States, although drivers come from a variety of countries. The points and team structures of IndyCar are very different from the system used by Formula One. IndyCar tracks can be ovals, street circuits, or road courses. + +**Open Wheel Racing** +A type of vehicle in which the wheels are exposed. If you've seen Cars 2, think of the Italian race-car. Open wheel racing series include Formula One and IndyCar. This is in contrast to series like Nascar, in which the cars look very similar to regular street cars. + ## Usage ### Install required packages @@ -16,4 +38,12 @@ Current implementation includes the Formula One 2023 Championship. ### Run the main program -`python3 main.py` \ No newline at end of file +`python3 main.py` + +## Future Versions + +* include Team Principals as an attribute of a Team +* add other FIA series like Formula 2 and Formula E +* differentiate between reserve/test drivers and full-time drivers +* add support for IndyCar type series + * add support for calculating standings using IndyCar's points system \ No newline at end of file From 430459c5d6de2c93e44ed37555f97a688feed6d3 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 00:31:37 -0700 Subject: [PATCH 14/72] update usage --- README.md | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 75b6b6e..98c208b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Motor Racing Info +# Racing Info CLI -CLI program to track information about various motor racing series, such as the teams, drivers, engine manufacturers, and championship standings. +A CLI program to track information about various motor racing series, such as the teams, drivers, engine manufacturers, and championship standings. Current implementation includes the Formula One 2023 Championship. @@ -8,42 +8,52 @@ Current implementation includes the Formula One 2023 Championship. *This glossary is listed in no particular order.* -**Formula One** / **Formula 1** / **F1** +#### **Formula One / Formula 1 / F1** An international motor racing series featuring open wheel racing. Currently, Formula One races are only street circuits or road courses. Famous Formula One drivers include Michael Schumacher, Lewis Hamilton, Max Verstappen, Fernando Alonso, and Sebastian Vettel. -**Formula Two** / **Formula 2** / **F2** +#### **Formula Two / Formula 2 / F2** A junior series of Formula One. Similar to the relationship between Minor League Baseball and Major League Baseball. -**Formula E** +#### **Formula E** The electric vehicle open wheel racing series governed by the FIA. -**FIA** / **Fédération Internationale de l'Automobile** +#### **FIA / Fédération Internationale de l'Automobile** The governing body of Formula One, and other related motor-racing series like Formula Two and Formula E. -**IndyCar** +#### **IndyCar** A series of open wheel racing based in the United States. Most race are in the United States, although drivers come from a variety of countries. The points and team structures of IndyCar are very different from the system used by Formula One. IndyCar tracks can be ovals, street circuits, or road courses. -**Open Wheel Racing** +#### **Open Wheel Racing** A type of vehicle in which the wheels are exposed. If you've seen Cars 2, think of the Italian race-car. Open wheel racing series include Formula One and IndyCar. This is in contrast to series like Nascar, in which the cars look very similar to regular street cars. ## Usage +### Set up environment + +From the root project directory (`final_project-platt-sam`) run the following commands: + + virtualenv -p python3 env + source env/bin/activate + ### Install required packages -`pip3 install -r requirements.txt` + pip3 install -r requirements.txt ### Run unit tests -`pytest tests` + pytest tests + +All tests should pass. Please report any failed tests to the project maintainer. ### Run the main program -`python3 main.py` + python3 main.py ## Future Versions * include Team Principals as an attribute of a Team -* add other FIA series like Formula 2 and Formula E +* add other FIA series like Formula 2, Formula E, and WEC (World Endurance Championship) * differentiate between reserve/test drivers and full-time drivers * add support for IndyCar type series - * add support for calculating standings using IndyCar's points system \ No newline at end of file + * add support for calculating standings using IndyCar's points system + * create an abstract class for Teams, create concrete classes for IndyCar and Formula One teams \ No newline at end of file From 4e9a6f48a11e32a1e70ee1a09d6d6c66b37099e5 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 11:24:51 -0700 Subject: [PATCH 15/72] error messages --- src/championship/championship.py | 8 ++++---- src/race/race.py | 6 +++--- src/team/team.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/championship/championship.py b/src/championship/championship.py index 770a7bb..475858a 100644 --- a/src/championship/championship.py +++ b/src/championship/championship.py @@ -50,7 +50,7 @@ def addTeamToChampionship(self, team: Team): for d in team.drivers: # for each of the team's drivers if not isinstance(d, Driver): - raise TypeError(f"") + raise TypeError(f"{d} must be of type Driver, not {type(d)}") if not self.driver_standings.get(d): # if driver is not already in driver's championship self.addDriverToChampionship(d) # add to driver's championship @@ -63,7 +63,7 @@ def removeTeamFromChampionship(self, team: Team): team: Team """ if not isinstance(team, Team): - raise TypeError(f"") + raise TypeError(f"{team} must be of type Team, not {type(team)}") if self.team_standings.get(team): self.team_standings.pop(team) @@ -100,7 +100,7 @@ def holdRace(self, race: Race, results: List[Driver]): results: List[Driver] ''' if not isinstance(race, Race): - raise TypeError(f"") + raise TypeError(f"{race} must be of type Race, not {type(race)}") if not self.rounds.get(race): self.rounds[race] = list() @@ -109,7 +109,7 @@ def holdRace(self, race: Race, results: List[Driver]): for i in range(1, 11): # only the top 10 drivers get points if not isinstance(results[i], Driver): - raise TypeError(f"") + raise TypeError(f"{results[i]} must be of type Driver, not {type(results[i])}") # update values for driver standings and team standings diff --git a/src/race/race.py b/src/race/race.py index 980b785..2aebceb 100644 --- a/src/race/race.py +++ b/src/race/race.py @@ -3,11 +3,11 @@ class Race(): def __init__(self, name: str, country: str, city: str): if not isinstance(name, str): - raise TypeError(f"") + raise TypeError(f"{name} must be of type str, not {type(name)}") if not isinstance(country, str): - raise TypeError(f"") + raise TypeError(f"{country} must be of type str, not {type(country)}") if not isinstance(city, str): - raise TypeError(f"") + raise TypeError(f"{city} must be of type str, not {type(city)}") self.name = name self.country = country diff --git a/src/team/team.py b/src/team/team.py index a8bda9d..53d52da 100644 --- a/src/team/team.py +++ b/src/team/team.py @@ -34,7 +34,7 @@ def addDriverToTeam(self, driver: Driver): def removeDriverFromTeam(self, driver: Driver): if not isinstance(driver, Driver): - raise TypeError(f"") + raise TypeError(f"{driver} must be of type Driver, not {type(driver)}") if driver in self.drivers: self.drivers.remove(driver) \ No newline at end of file From 23e14c00ad04d0e38cf5f10a49d7d4e066a45f32 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 13:33:58 -0700 Subject: [PATCH 16/72] ignore __pycache__ and other --- .gitignore | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b6e4761 --- /dev/null +++ b/.gitignore @@ -0,0 +1,129 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ From f84c0ba9794d5b0809c5d29787445753dd7eb57b Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 13:48:05 -0700 Subject: [PATCH 17/72] fix bugs --- src/team/teamFactory.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/team/teamFactory.py b/src/team/teamFactory.py index ba5d319..5355d05 100644 --- a/src/team/teamFactory.py +++ b/src/team/teamFactory.py @@ -5,7 +5,7 @@ class TeamFactory: @staticmethod - def createTeam(self, name: str, engine: EngineInt | str, country: str, drivers: List(Driver)) -> Team: + def createTeam(name: str, engine: EngineInt | str, country: str, drivers: List[Driver]) -> Team: """ create a team with a custom engine @@ -27,7 +27,7 @@ def createTeam(self, name: str, engine: EngineInt | str, country: str, drivers: return Team(name = name, engine = engine, country = country, drivers = drivers) @staticmethod - def createTeamFerrariEngine(self, name: str, country: str, drivers: List(Driver)) -> Team: + def createTeamFerrariEngine(name: str, country: str, drivers: List[Driver]) -> Team: """ create a team with a Ferrari engine @@ -44,7 +44,7 @@ def createTeamFerrariEngine(self, name: str, country: str, drivers: List(Driver) return Team(name = name, engine = FerrariEngine(), country = country, drivers = drivers) @staticmethod - def createTeamHondaRBPTEngine(self, name: str, country: str, drivers: List(Driver)) -> Team: + def createTeamHondaRBPTEngine(name: str, country: str, drivers: List[Driver]) -> Team: """ create a team with a Honda Red Bull Power Trains engine @@ -61,7 +61,7 @@ def createTeamHondaRBPTEngine(self, name: str, country: str, drivers: List(Drive return Team(name = name, engine = HondaRBPTEngine(), country = country, drivers = drivers) @staticmethod - def createTeamMercedesEngine(self, name: str, country: str, drivers: List(Driver)) -> Team: + def createTeamMercedesEngine(name: str, country: str, drivers: List[Driver]) -> Team: """ create a team with a Mercedes engine @@ -78,7 +78,7 @@ def createTeamMercedesEngine(self, name: str, country: str, drivers: List(Driver return Team(name = name, engine = MercedesEngine(), country = country, drivers = drivers) @staticmethod - def createTeamRenaultEngine(self, name: str, country: str, drivers: List(Driver)) -> Team: + def createTeamRenaultEngine(name: str, country: str, drivers: List[Driver]) -> Team: """ create a team with a Renault engine From 7d9174b55beb8e7cb0864c1caad4f69cf457ebc6 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 13:52:38 -0700 Subject: [PATCH 18/72] rewriting the code i lost --- main.py | 3 +++ src/championship/championship.py | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index ca98197..cb3f4c3 100644 --- a/main.py +++ b/main.py @@ -111,5 +111,8 @@ def main(): ) ) + for x in formula_one_2023.getTeamStandings(): + print(x) + if __name__ == "__main__": main() \ No newline at end of file diff --git a/src/championship/championship.py b/src/championship/championship.py index 475858a..047eddd 100644 --- a/src/championship/championship.py +++ b/src/championship/championship.py @@ -88,8 +88,15 @@ def getTeamStandings(self) -> List: returns: List ''' - # TODO - pass + sorted_standings = sorted(self.team_standings.items(), key=lambda x:x[1]) + sorted_standings.reverse() + + printable = list() + + for i in range(len(sorted_standings)): + printable.append(f"{i+1}: {sorted_standings[i][0].name} ({sorted_standings[i][1]} points)") + + return printable def holdRace(self, race: Race, results: List[Driver]): ''' From e140e46155bafc9463eb1626a06057fb901b19e8 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 13:55:45 -0700 Subject: [PATCH 19/72] getDriverStandings functionality --- main.py | 6 +++++- src/championship/championship.py | 11 +++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index cb3f4c3..a9ca1c5 100644 --- a/main.py +++ b/main.py @@ -110,9 +110,13 @@ def main(): ] ) ) - + print("\nTeam Standings") for x in formula_one_2023.getTeamStandings(): print(x) + print("\nDriver Standings") + for x in formula_one_2023.getDriverStandings(): + print(x) + if __name__ == "__main__": main() \ No newline at end of file diff --git a/src/championship/championship.py b/src/championship/championship.py index 047eddd..6ea07ba 100644 --- a/src/championship/championship.py +++ b/src/championship/championship.py @@ -75,8 +75,15 @@ def getDriverStandings(self) -> List: returns: List ''' - # TODO - pass + sorted_standings = sorted(self.driver_standings.items(), key=lambda x:x[1]) + sorted_standings.reverse() + + printable = list() + + for i in range(len(sorted_standings)): + printable.append(f"{i+1}: {sorted_standings[i][0].getNameFormatted()} ({sorted_standings[i][1]} points)") + + return printable def getTeamStandings(self) -> List: ''' From dd7dc031359df5227cb7c75e060e8abaea0945f3 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 14:07:53 -0700 Subject: [PATCH 20/72] comment --- main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.py b/main.py index a9ca1c5..c47094a 100644 --- a/main.py +++ b/main.py @@ -110,6 +110,9 @@ def main(): ] ) ) + + # print standings to the console + print("\nTeam Standings") for x in formula_one_2023.getTeamStandings(): print(x) From 6236a473c2dc8a4f459e4f45c69763714b10a3c9 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 14:22:02 -0700 Subject: [PATCH 21/72] calculate race results --- src/championship/championship.py | 32 +++-------------- src/race/raceResults.py | 60 ++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 27 deletions(-) create mode 100644 src/race/raceResults.py diff --git a/src/championship/championship.py b/src/championship/championship.py index 6ea07ba..fc33220 100644 --- a/src/championship/championship.py +++ b/src/championship/championship.py @@ -1,5 +1,6 @@ from src.driver.driver import Driver from src.race.race import Race +from src.race.raceResults import RaceResults from src.series.series import Series from src.team.team import Team from typing import List @@ -18,7 +19,7 @@ def __init__(self, series: Series, year: int): self.series = series self.year = year - self.rounds = dict() # key = race: Race, value = results: List(Driver) + self.race_results = list() # list of RaceResults objects self.driver_standings = dict() self.team_standings = dict() @@ -105,36 +106,13 @@ def getTeamStandings(self) -> List: return printable - def holdRace(self, race: Race, results: List[Driver]): + def holdRace(self, race: Race, results: RaceResults): ''' holds a race and updates standings given the results param: race: Race - results: List[Driver] + results: RaceResults ''' if not isinstance(race, Race): - raise TypeError(f"{race} must be of type Race, not {type(race)}") - - if not self.rounds.get(race): - self.rounds[race] = list() - - points_system = [None, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1] - - for i in range(1, 11): # only the top 10 drivers get points - if not isinstance(results[i], Driver): - raise TypeError(f"{results[i]} must be of type Driver, not {type(results[i])}") - - # update values for driver standings and team standings - - # update driver standings - - self.driver_standings[results[i]] += points_system[i] - - if results.count(results[i]) > 1: # if this driver won fastest lap - self.driver_standings[results[i]] += 1 - - # update team standings - # TODO update the team standings (stretch goal???) - - self.rounds[race] = results \ No newline at end of file + raise TypeError(f"{race} must be of type Race, not {type(race)}") \ No newline at end of file diff --git a/src/race/raceResults.py b/src/race/raceResults.py new file mode 100644 index 0000000..3fdd413 --- /dev/null +++ b/src/race/raceResults.py @@ -0,0 +1,60 @@ +from src.driver.driver import Driver +from src.race.race import Race +from typing import List + +class RaceResults(): + def __init__(self, race: Race, rankings: List[Driver], fastestLap: Driver): + if not isinstance(race, Race): + raise TypeError(f"{race} must be of type Race, not {type(race)}") + if not isinstance(rankings, List): + raise TypeError(f"{rankings} must be of type List, not {type(rankings)}") + if not isinstance(fastestLap, Driver): + raise TypeError(f"{fastestLap} must be of type Driver, not {type(fastestLap)}") + + self.race = race + self.results = dict() # key = driver: Driver, value = points: int + + # calculate points + + points_system = [None, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + + for i in range(1,21): + if not isinstance(rankings[i], Driver): + raise TypeError(f"{rankings[i]} must be of type Driver, not {type(rankings[i])}") + + self.results[rankings[i]] = points_system[i] + + if self.results[fastestLap] > 0: # if the driver who got the fastest lap finished in the points + self.results[fastestLap] += 1 # give them an extra point for fastest lap + + + def getPointsForDriver(self, driver: Driver) -> int: + if not isinstance(driver, Driver): + raise TypeError(f"{driver} must be of type Driver, not {type(driver)}") + + return self.results[driver] + + ''' + if not self.rounds.get(race): + self.rounds[race] = list() + + points_system = [None, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1] + + for i in range(1, 11): # only the top 10 drivers get points + if not isinstance(results[i], Driver): + raise TypeError(f"{results[i]} must be of type Driver, not {type(results[i])}") + + # update values for driver standings and team standings + + # update driver standings + + self.driver_standings[results[i]] += points_system[i] + + if results.count(results[i]) > 1: # if this driver won fastest lap + self.driver_standings[results[i]] += 1 + + # update team standings + # TODO update the team standings (stretch goal???) + + self.rounds[race] = results + ''' \ No newline at end of file From 1b06bd5b8513c634258a5866d0c748ae67719bae Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 14:39:33 -0700 Subject: [PATCH 22/72] get points for driver and team --- src/race/raceResults.py | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/src/race/raceResults.py b/src/race/raceResults.py index 3fdd413..b5b9f45 100644 --- a/src/race/raceResults.py +++ b/src/race/raceResults.py @@ -1,5 +1,6 @@ from src.driver.driver import Driver from src.race.race import Race +from src.team.team import Team from typing import List class RaceResults(): @@ -34,27 +35,12 @@ def getPointsForDriver(self, driver: Driver) -> int: return self.results[driver] - ''' - if not self.rounds.get(race): - self.rounds[race] = list() - - points_system = [None, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1] - - for i in range(1, 11): # only the top 10 drivers get points - if not isinstance(results[i], Driver): - raise TypeError(f"{results[i]} must be of type Driver, not {type(results[i])}") - - # update values for driver standings and team standings - - # update driver standings - - self.driver_standings[results[i]] += points_system[i] - - if results.count(results[i]) > 1: # if this driver won fastest lap - self.driver_standings[results[i]] += 1 + def getPointsForTeam(self, team: Team) -> int: + if not isinstance(team, Team): + raise TypeError(f"") # TODO + + points = 0 + for driver in team.drivers: + points += self.getPointsForDriver(driver) - # update team standings - # TODO update the team standings (stretch goal???) - - self.rounds[race] = results - ''' \ No newline at end of file + return points \ No newline at end of file From 224ad9e7ec0b49e0c22eb73cb30106241353b04d Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 15:37:33 -0700 Subject: [PATCH 23/72] better error handling --- src/race/raceResults.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/race/raceResults.py b/src/race/raceResults.py index b5b9f45..5d045ad 100644 --- a/src/race/raceResults.py +++ b/src/race/raceResults.py @@ -37,10 +37,10 @@ def getPointsForDriver(self, driver: Driver) -> int: def getPointsForTeam(self, team: Team) -> int: if not isinstance(team, Team): - raise TypeError(f"") # TODO + raise TypeError(f"{team} must be of type Team, not {type(team)}") points = 0 for driver in team.drivers: points += self.getPointsForDriver(driver) - + return points \ No newline at end of file From e621a491d3eb36c7c8865934b6063595da876a66 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 15:46:26 -0700 Subject: [PATCH 24/72] add __str__ method --- src/race/race.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/race/race.py b/src/race/race.py index 2aebceb..b3daf06 100644 --- a/src/race/race.py +++ b/src/race/race.py @@ -1,6 +1,9 @@ class Race(): + """ + TODO + """ def __init__(self, name: str, country: str, city: str): if not isinstance(name, str): raise TypeError(f"{name} must be of type str, not {type(name)}") @@ -11,4 +14,7 @@ def __init__(self, name: str, country: str, city: str): self.name = name self.country = country - self.city = city \ No newline at end of file + self.city = city + + def __str__(self) -> str: + return f"{self.name} Grand Prix ({self.city}, {self.country})" \ No newline at end of file From 049dce5150a8faf6915221b8972f4fc47673386f Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 15:46:49 -0700 Subject: [PATCH 25/72] comments and docstrings --- src/team/team.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/team/team.py b/src/team/team.py index 53d52da..a509c15 100644 --- a/src/team/team.py +++ b/src/team/team.py @@ -21,11 +21,16 @@ def __init__(self, name: str, engine: EngineInt, country: str, drivers: List[Dri self.country = country self.drivers = list() - # because the addDriverToTeam() method does type checking internally, we don't need to create an extra for loop to check each item in the list of prospective drivers. this saves processing time and memory! + # because the addDriverToTeam() method does type checking internally, + # we don't need to create an extra for loop to check each item in the list of prospective drivers. + # this saves processing time and memory! for driver in drivers: self.addDriverToTeam(driver = driver) def addDriverToTeam(self, driver: Driver): + """ + TODO + """ if not isinstance(driver, Driver): raise TypeError(f"{driver} must be of type Driver, not {type(driver)}") @@ -33,6 +38,9 @@ def addDriverToTeam(self, driver: Driver): self.drivers.append(driver) def removeDriverFromTeam(self, driver: Driver): + """ + TODO + """ if not isinstance(driver, Driver): raise TypeError(f"{driver} must be of type Driver, not {type(driver)}") From 16be3d12b505857fdddf6911caa177d8ad4ae552 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 15:48:05 -0700 Subject: [PATCH 26/72] docstrings and comments --- src/race/raceResults.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/race/raceResults.py b/src/race/raceResults.py index 5d045ad..6601ee9 100644 --- a/src/race/raceResults.py +++ b/src/race/raceResults.py @@ -4,6 +4,9 @@ from typing import List class RaceResults(): + """ + a class to store results associated with a Race + """ def __init__(self, race: Race, rankings: List[Driver], fastestLap: Driver): if not isinstance(race, Race): raise TypeError(f"{race} must be of type Race, not {type(race)}") @@ -25,17 +28,37 @@ def __init__(self, race: Race, rankings: List[Driver], fastestLap: Driver): self.results[rankings[i]] = points_system[i] - if self.results[fastestLap] > 0: # if the driver who got the fastest lap finished in the points - self.results[fastestLap] += 1 # give them an extra point for fastest lap + # if the driver who got the fastest lap finished in the points + if self.results[fastestLap] > 0: + # give the driver an extra point for fastest lap + self.results[fastestLap] += 1 def getPointsForDriver(self, driver: Driver) -> int: + """ + get the points scored by a driver for a specific race + + params: + driver: Driver + + returns: + int + """ if not isinstance(driver, Driver): raise TypeError(f"{driver} must be of type Driver, not {type(driver)}") return self.results[driver] def getPointsForTeam(self, team: Team) -> int: + """ + get the points scored by all drivers in a team for a specific race + + params: + team: Team + + returns: + int + """ if not isinstance(team, Team): raise TypeError(f"{team} must be of type Team, not {type(team)}") From 111e189a8928ecdb57cdf19861a9830bee8aa448 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 15:49:16 -0700 Subject: [PATCH 27/72] add error checking and driver number --- src/driver/driver.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/driver/driver.py b/src/driver/driver.py index 4c9cf39..ee2b5df 100644 --- a/src/driver/driver.py +++ b/src/driver/driver.py @@ -1,9 +1,26 @@ class Driver(): - def __init__(self, surname: str, givenname: str, nationality: str, surname_first: bool = False): + """ + TODO + """ + def __init__(self, surname: str, givenname: str, number: int, nationality: str, surname_first: bool = False): + # type checking + + if not isinstance(surname, str): + raise TypeError(f"") # TODO + if not isinstance(givenname, str): + raise TypeError(f"") # TODO + if not isinstance(number, int): + raise TypeError(f"") # TODO + if not isinstance(nationality, str): + raise TypeError(f"") # TODO + if not isinstance(surname_first, bool): + raise TypeError(f"") # TODO + self.surname = surname self.givenname = givenname + self.number = number self.nationality = nationality self.surname_first = surname_first @@ -15,6 +32,6 @@ def getNameFormatted(self) -> str: str ''' if self.surname_first: - return f"{self.surname.upper()} {self.givenname}" + return f"{self.surname.upper()} {self.givenname} #{self.number}" - return f"{self.givenname} {self.surname.upper()}" \ No newline at end of file + return f"{self.givenname} {self.surname.upper()} #{self.number}" \ No newline at end of file From fbc23a9d70cf0180ac2fc05e992b5bdde564e82d Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 15:53:19 -0700 Subject: [PATCH 28/72] add __str__ method --- src/engine/engine.py | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/engine/engine.py b/src/engine/engine.py index 0b8a375..b2fecdf 100644 --- a/src/engine/engine.py +++ b/src/engine/engine.py @@ -1,33 +1,62 @@ from abc import ABC class EngineInt(ABC): - pass + """ + an interface for engines + """ + def __str__(self) -> str: + pass class Engine(EngineInt): + """ + TODO + """ def __init__(self, engine: str): if not isinstance(engine, str): raise TypeError(f"{engine} must be of type str, not {type(engine)}") self.engine = engine + def __str__(self) -> str: + return f"{self.engine} Engine" + class FerrariEngine(EngineInt): + """ + a class to represent an Engine built by Ferrari. + """ def __init__(self): self.engine = "Ferrari" + def __str__(self) -> str: + return f"{self.engine} Engine" + class HondaRBPTEngine(EngineInt): + """ + a class to represent an Engine built by Honda Red Bull Power Trains. + """ def __init__(self): - # I know, the name is far too long. I didn't choose it, Red Bull did + # I know, the name is far too long. + # I didn't choose it, Red Bull did self.engine = "Honda Red Bull Power Trains" class MercedesEngine(EngineInt): + """ + a class to represent an engine built by Mercedes. + """ def __init__(self): self.engine = "Mercedes" + def __str__(self) -> str: + return f"{self.engine} Engine" + class RenaultEngine(EngineInt): ''' - an engine manufactured by Renault. + a class to represent an engine built by Renault. Fun Fact: Renault was one of the victims of WannaCry! https://www.nbcnews.com/business/autos/european-car-plants-halted-wannacry-ransomware-attack-n759496 ''' def __init__(self): - self.engine = "Renault" \ No newline at end of file + self.engine = "Renault" + + def __str__(self) -> str: + return f"{self.engine} Engine" \ No newline at end of file From fa37fc89dfbc4527e8e7f6d0d43ea3feac152744 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 15:56:07 -0700 Subject: [PATCH 29/72] add error messages and docstrings --- src/driver/driver.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/driver/driver.py b/src/driver/driver.py index ee2b5df..961e7f4 100644 --- a/src/driver/driver.py +++ b/src/driver/driver.py @@ -2,21 +2,22 @@ class Driver(): """ - TODO + a class to represent a driver """ def __init__(self, surname: str, givenname: str, number: int, nationality: str, surname_first: bool = False): + # type checking if not isinstance(surname, str): - raise TypeError(f"") # TODO + raise TypeError(f"{surname} must be of type str, not {type(surname)}") if not isinstance(givenname, str): - raise TypeError(f"") # TODO + raise TypeError(f"{givenname} must be of type str, not {type(givenname)}") if not isinstance(number, int): - raise TypeError(f"") # TODO + raise TypeError(f"{number} must be of type int, not {type(number)}") if not isinstance(nationality, str): - raise TypeError(f"") # TODO + raise TypeError(f"{nationality} must be of type str, not {type(nationality)}") if not isinstance(surname_first, bool): - raise TypeError(f"") # TODO + raise TypeError(f"{surname_first} must be of type bool, not {type(surname_first)}") self.surname = surname self.givenname = givenname @@ -24,7 +25,7 @@ def __init__(self, surname: str, givenname: str, number: int, nationality: str, self.nationality = nationality self.surname_first = surname_first - def getNameFormatted(self) -> str: + def __str__(self) -> str: ''' formats the name of the driver as `LAST First` or `First LAST` depending on driver preference From 460263d0d1ae757933f0337812c31e634f46b71b Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 16:01:05 -0700 Subject: [PATCH 30/72] comments and docstrings --- src/championship/championship.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/championship/championship.py b/src/championship/championship.py index fc33220..6285e2e 100644 --- a/src/championship/championship.py +++ b/src/championship/championship.py @@ -69,12 +69,12 @@ def removeTeamFromChampionship(self, team: Team): if self.team_standings.get(team): self.team_standings.pop(team) - def getDriverStandings(self) -> List: + def getDriverStandings(self) -> List[str]: ''' get current driver standings returns: - List + List[str] ''' sorted_standings = sorted(self.driver_standings.items(), key=lambda x:x[1]) sorted_standings.reverse() @@ -82,19 +82,16 @@ def getDriverStandings(self) -> List: printable = list() for i in range(len(sorted_standings)): - printable.append(f"{i+1}: {sorted_standings[i][0].getNameFormatted()} ({sorted_standings[i][1]} points)") + printable.append(f"{i+1}: {sorted_standings[i][0].__str__()} ({sorted_standings[i][1]} points)") return printable - def getTeamStandings(self) -> List: + def getTeamStandings(self) -> List[str]: ''' get current team standings - param: - None - returns: - List + List[str] ''' sorted_standings = sorted(self.team_standings.items(), key=lambda x:x[1]) sorted_standings.reverse() @@ -110,9 +107,13 @@ def holdRace(self, race: Race, results: RaceResults): ''' holds a race and updates standings given the results - param: + params: race: Race results: RaceResults ''' if not isinstance(race, Race): - raise TypeError(f"{race} must be of type Race, not {type(race)}") \ No newline at end of file + raise TypeError(f"{race} must be of type Race, not {type(race)}") + + # type check the results + + # TODO update standings based on the results \ No newline at end of file From 811ae0afd4a3f01a6463a66674aedc3d3ab2e8fc Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 16:01:33 -0700 Subject: [PATCH 31/72] docstrings --- src/series/series.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/series/series.py b/src/series/series.py index 150833a..efbb53d 100644 --- a/src/series/series.py +++ b/src/series/series.py @@ -1,5 +1,8 @@ class Series(): + """ + a class to represent a racing series + """ def __init__(self, name: str): self.name = name \ No newline at end of file From d0061e0252d43e91bce850e15fba1c5741afdbca Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 16:17:04 -0700 Subject: [PATCH 32/72] add support for suffixes --- src/driver/driver.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/driver/driver.py b/src/driver/driver.py index 961e7f4..2e00b2c 100644 --- a/src/driver/driver.py +++ b/src/driver/driver.py @@ -4,7 +4,7 @@ class Driver(): """ a class to represent a driver """ - def __init__(self, surname: str, givenname: str, number: int, nationality: str, surname_first: bool = False): + def __init__(self, surname: str, givenname: str, number: int, nationality: str, surname_first: bool = False, suffix: str = None): # type checking @@ -18,12 +18,15 @@ def __init__(self, surname: str, givenname: str, number: int, nationality: str, raise TypeError(f"{nationality} must be of type str, not {type(nationality)}") if not isinstance(surname_first, bool): raise TypeError(f"{surname_first} must be of type bool, not {type(surname_first)}") - + if not isinstance(suffix, (str, type(None))): + raise TypeError(f"{suffix} must of type str or None, not {type(suffix)}") + self.surname = surname self.givenname = givenname self.number = number self.nationality = nationality self.surname_first = surname_first + self.suffix = suffix def __str__(self) -> str: ''' @@ -32,7 +35,18 @@ def __str__(self) -> str: returns: str ''' + s = str() + + # add driver first and last names according to driver's preference in order + if self.surname_first: - return f"{self.surname.upper()} {self.givenname} #{self.number}" - - return f"{self.givenname} {self.surname.upper()} #{self.number}" \ No newline at end of file + s += f"{self.surname.upper()} {self.givenname}" + else: + s += f"{self.givenname} {self.surname.upper()}" + + if self.suffix: # add suffix if applicable + s += f" {self.suffix}" + + s += f" #{self.number}" # add driver number + + return s \ No newline at end of file From 97b1eb75dfd1e3efcc16702ecf23d2a71ea137f4 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 16:17:24 -0700 Subject: [PATCH 33/72] add more drivers --- main.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index c47094a..3e90556 100644 --- a/main.py +++ b/main.py @@ -21,8 +21,8 @@ def main(): name = "Alfa Romeo", country = "Switzerland", drivers = [ - Driver(surname = "Bottas", givenname = "Valtteri", nationality = "Finland"), - Driver(surname = "Zhou", givenname = "Guanyu", nationality = "China", surname_first = True) + Driver(surname = "Bottas", givenname = "Valtteri", number = 77, nationality = "Finland"), + Driver(surname = "Zhou", givenname = "Guanyu", number = 24, nationality = "China", surname_first = True) ] ) ) @@ -31,8 +31,8 @@ def main(): name = "AlphaTauri", country = "Italy", drivers = [ - Driver(surname = "de Vries", givenname = "Nyck", nationality = "Netherlands"), - Driver(surname = "Tsunoda", givenname = "Yuki", nationality = "Japan") + Driver(surname = "de Vries", givenname = "Nyck", number = 21, nationality = "Netherlands"), + Driver(surname = "Tsunoda", givenname = "Yuki", number = 22, nationality = "Japan") ] ) ) @@ -41,7 +41,8 @@ def main(): name = "Alpine", country = "France", drivers = [ - # TODO add drivers + Driver(surname = "Gasly", givenname = "Pierre", number = 10, nationality = "France"), + Driver(surname = "Ocon", givenname = "Esteban", number = 31, nationality = "France") ] ) ) @@ -50,7 +51,8 @@ def main(): name = "Aston Martin", country = "United Kingdom", drivers = [ - # TODO add drivers + Driver(surname = "Alonso", givenname = "Fernando", number = 14, nationality = "Spain"), + Driver(surname = "Stroll", givenname = "Lance", number = 18, nationality = "Canada") ] ) ) @@ -59,7 +61,8 @@ def main(): name = "Ferrari", # this is my second favorite team. They are terrible at strategy and there are multiple memes about how bad their strategy is country = "Italy", drivers = [ - # TODO add drivers + Driver(surname = "Leclerc", givenname = "Charles", number = 16, nationality = "Monaco"), + Driver(surname = "Sainz", suffix = "Jr.", givenname = "Carlos", number = 55, nationality = "Spain") ] ) ) @@ -77,8 +80,8 @@ def main(): name = "McLaren", country = "United Kingdom", drivers = [ - Driver(surname = "Norris", givenname = "Lando", nationality = "United Kingdom"), - Driver(surname = "Piastri", givenname = "Oscar", nationality = "Australia") + Driver(surname = "Norris", givenname = "Lando", number = 4, nationality = "United Kingdom"), + Driver(surname = "Piastri", givenname = "Oscar", number = 81, nationality = "Australia") ] ) ) @@ -87,8 +90,8 @@ def main(): name = "Mercedes", # this is my favorite team country = "Germany", drivers = [ - Driver(surname = "Hamilton", givenname = "Lewis", nationality = "United Kingdom"), - Driver(surname = "Russell", givenname = "George", nationality = "United Kingdom") + Driver(surname = "Hamilton", givenname = "Lewis", number = 44, nationality = "United Kingdom"), + Driver(surname = "Russell", givenname = "George", number = 63, nationality = "United Kingdom") ] ) ) From 354fc9ce0952977fd15e95ba063896e1336fae1b Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 16:38:54 -0700 Subject: [PATCH 34/72] create files and add imports for unit tests --- tests/test_championship.py | 9 +++++++++ tests/test_driver.py | 4 ++++ tests/test_engine.py | 5 +++++ tests/test_race.py | 3 +++ tests/test_raceResults.py | 5 +++++ tests/test_series.py | 5 +++++ tests/test_team.py | 6 ++++++ tests/test_teamFactory.py | 8 ++++++++ 8 files changed, 45 insertions(+) create mode 100644 tests/test_championship.py create mode 100644 tests/test_driver.py create mode 100644 tests/test_engine.py create mode 100644 tests/test_race.py create mode 100644 tests/test_raceResults.py create mode 100644 tests/test_series.py create mode 100644 tests/test_team.py create mode 100644 tests/test_teamFactory.py diff --git a/tests/test_championship.py b/tests/test_championship.py new file mode 100644 index 0000000..752108a --- /dev/null +++ b/tests/test_championship.py @@ -0,0 +1,9 @@ +import pytest +from src.driver.driver import Driver +from src.race.race import Race +from src.race.raceResults import RaceResults +from src.series.series import Series +from src.team.team import Team +from typing import Any, List + +# TODO \ No newline at end of file diff --git a/tests/test_driver.py b/tests/test_driver.py new file mode 100644 index 0000000..a204b43 --- /dev/null +++ b/tests/test_driver.py @@ -0,0 +1,4 @@ +import pytest +from typing import Any + +# TODO \ No newline at end of file diff --git a/tests/test_engine.py b/tests/test_engine.py new file mode 100644 index 0000000..85e664e --- /dev/null +++ b/tests/test_engine.py @@ -0,0 +1,5 @@ +import pytest +from src.engine.engine import * +from typing import Any + +# TODO \ No newline at end of file diff --git a/tests/test_race.py b/tests/test_race.py new file mode 100644 index 0000000..df1ad1a --- /dev/null +++ b/tests/test_race.py @@ -0,0 +1,3 @@ +import pytest +from src.race.race import Race +from typing import Any \ No newline at end of file diff --git a/tests/test_raceResults.py b/tests/test_raceResults.py new file mode 100644 index 0000000..d120dec --- /dev/null +++ b/tests/test_raceResults.py @@ -0,0 +1,5 @@ +import pytest +from src.driver.driver import Driver +from src.race.race import Race +from src.team.team import Team +from typing import Any, Dict, List \ No newline at end of file diff --git a/tests/test_series.py b/tests/test_series.py new file mode 100644 index 0000000..81e71b8 --- /dev/null +++ b/tests/test_series.py @@ -0,0 +1,5 @@ +import pytest +from src.series.series import Series +from typing import Any + +# TODO \ No newline at end of file diff --git a/tests/test_team.py b/tests/test_team.py new file mode 100644 index 0000000..45970c9 --- /dev/null +++ b/tests/test_team.py @@ -0,0 +1,6 @@ +import pytest +from src.driver.driver import Driver +from src.engine.engine import * +from typing import Any, List + +# TODO \ No newline at end of file diff --git a/tests/test_teamFactory.py b/tests/test_teamFactory.py new file mode 100644 index 0000000..be885b1 --- /dev/null +++ b/tests/test_teamFactory.py @@ -0,0 +1,8 @@ +import pytest +from src.driver.driver import Driver +from src.engine.engine import * +from src.team.team import Team +from src.team.teamFactory import * +from typing import Any, List + +# TODO \ No newline at end of file From 4fd036072e37b7c2b69bd45311c1204ce2ef31e4 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Mon, 5 Jun 2023 16:40:17 -0700 Subject: [PATCH 35/72] add pytest requirement --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 4f76fc7..c6ed6ca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ +pytest typing \ No newline at end of file From c641d0da9027c87caf266fd0db8fd58b9b11bb5d Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Wed, 7 Jun 2023 14:41:17 -0700 Subject: [PATCH 36/72] added drivers, adding races --- main.py | 94 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/main.py b/main.py index 3e90556..024b99d 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ from src.driver.driver import Driver from src.engine.engine import * from src.race.race import Race +from src.race.raceResults import RaceResults from src.series.series import Series from src.team.team import Team from src.team.teamFactory import TeamFactory @@ -14,103 +15,122 @@ def main(): # instantiate the 2023 Formula One Championship formula_one_2023 = Championship(series = formula_one, year = 2023) + # instantiate drivers + + alb = Driver(surname = "Albon", givenname = "Alexander", number = 23, nationality = "Thailand") + alo = Driver(surname = "Alonso", givenname = "Fernando", number = 14, nationality = "Spain") + bot = Driver(surname = "Bottas", givenname = "Valtteri", number = 77, nationality = "Finland") + dev = Driver(surname = "de Vries", givenname = "Nyck", number = 21, nationality = "Netherlands") + gas = Driver(surname = "Gasly", givenname = "Pierre", number = 10, nationality = "France") + ham = Driver(surname = "Hamilton", givenname = "Lewis", number = 44, nationality = "United Kingdom") + hul = Driver(surname = "Hülkenberg", givenname = "Nico", number = 27, nationality = "Germany") + lec = Driver(surname = "Leclerc", givenname = "Charles", number = 16, nationality = "Monaco") + mag = Driver(surname = "Magnussen", givenname = "Kevin", number = 20, nationality = "Denmark") + nor = Driver(surname = "Norris", givenname = "Lando", number = 4, nationality = "United Kingdom") + oco = Driver(surname = "Ocon", givenname = "Esteban", number = 31, nationality = "France") + per = Driver(surname = "Pérez", givenname = "Sergio", number = 11, nationality = "Mexico") + pia = Driver(surname = "Piastri", givenname = "Oscar", number = 81, nationality = "Australia") + rus = Driver(surname = "Russell", givenname = "George", number = 63, nationality = "United Kingdom") + sai = Driver(surname = "Sainz", suffix = "Jr.", givenname = "Carlos", number = 55, nationality = "Spain") + sar = Driver(surname = "Sargeant", givenname = "Logan", number = 2, nationality = "United States") + stroll = Driver(surname = "Stroll", givenname = "Lance", number = 18, nationality = "Canada") # str is a reserved word + tsu = Driver(surname = "Tsunoda", givenname = "Yuki", number = 22, nationality = "Japan") + ver = Driver(surname = "Verstappen", givenname = "Max", number = 1, nationality = "Netherlands") + zho = Driver(surname = "Zhou", givenname = "Guanyu", number = 24, nationality = "China", surname_first = True) + # create teams using TeamFactory formula_one_2023.addTeamToChampionship( TeamFactory.createTeamFerrariEngine( name = "Alfa Romeo", country = "Switzerland", - drivers = [ - Driver(surname = "Bottas", givenname = "Valtteri", number = 77, nationality = "Finland"), - Driver(surname = "Zhou", givenname = "Guanyu", number = 24, nationality = "China", surname_first = True) - ] + drivers = [bot, zho] ) ) formula_one_2023.addTeamToChampionship( TeamFactory.createTeamHondaRBPTEngine( name = "AlphaTauri", country = "Italy", - drivers = [ - Driver(surname = "de Vries", givenname = "Nyck", number = 21, nationality = "Netherlands"), - Driver(surname = "Tsunoda", givenname = "Yuki", number = 22, nationality = "Japan") - ] + drivers = [dev, tsu] ) ) formula_one_2023.addTeamToChampionship( TeamFactory.createTeamRenaultEngine( name = "Alpine", country = "France", - drivers = [ - Driver(surname = "Gasly", givenname = "Pierre", number = 10, nationality = "France"), - Driver(surname = "Ocon", givenname = "Esteban", number = 31, nationality = "France") - ] + drivers = [gas, oco] ) ) formula_one_2023.addTeamToChampionship( TeamFactory.createTeamMercedesEngine( name = "Aston Martin", country = "United Kingdom", - drivers = [ - Driver(surname = "Alonso", givenname = "Fernando", number = 14, nationality = "Spain"), - Driver(surname = "Stroll", givenname = "Lance", number = 18, nationality = "Canada") - ] + drivers = [alo, stroll] ) ) formula_one_2023.addTeamToChampionship( TeamFactory.createTeamFerrariEngine( name = "Ferrari", # this is my second favorite team. They are terrible at strategy and there are multiple memes about how bad their strategy is country = "Italy", - drivers = [ - Driver(surname = "Leclerc", givenname = "Charles", number = 16, nationality = "Monaco"), - Driver(surname = "Sainz", suffix = "Jr.", givenname = "Carlos", number = 55, nationality = "Spain") - ] + drivers = [lec, sai] ) ) formula_one_2023.addTeamToChampionship( TeamFactory.createTeamFerrariEngine( name = "Haas", country = "United States", - drivers = [ - # TODO add drivers - ] + drivers = [hul, mag] ) ) formula_one_2023.addTeamToChampionship( TeamFactory.createTeamMercedesEngine( name = "McLaren", country = "United Kingdom", - drivers = [ - Driver(surname = "Norris", givenname = "Lando", number = 4, nationality = "United Kingdom"), - Driver(surname = "Piastri", givenname = "Oscar", number = 81, nationality = "Australia") - ] + drivers = [nor, pia] ) ) formula_one_2023.addTeamToChampionship( TeamFactory.createTeamMercedesEngine( name = "Mercedes", # this is my favorite team country = "Germany", - drivers = [ - Driver(surname = "Hamilton", givenname = "Lewis", number = 44, nationality = "United Kingdom"), - Driver(surname = "Russell", givenname = "George", number = 63, nationality = "United Kingdom") - ] + drivers = [ham, rus] ) ) formula_one_2023.addTeamToChampionship( TeamFactory.createTeamHondaRBPTEngine( name = "Red Bull", # you're not going to believe this, but Red Bull is actually a better team right now than Ferrari country = "Austria", - drivers = [ - # TODO add drivers - ] + drivers = [per, ver] ) ) formula_one_2023.addTeamToChampionship( TeamFactory.createTeamMercedesEngine( name = "Williams", country = "United Kingdom", - drivers = [ - # TODO add drivers - ] + drivers = [alb, sar] + ) + ) + + # create races + + bahrain_gp = Race( + name = "Bahrain Grand Prix", + country = "Bahrain", + city = "Sakhir", + circuit = "Bahrain International Circuit" + ), + + # add race results + + print(bahrain_gp.__str__()) + + formula_one_2023.holdRace( + RaceResults( + race = bahrain_gp, + rankings = list( + + ), # TODO + fastestLap = Driver() # TODO ) ) From 4bc81181711995750836e3d2ce5ec01f1be2a13a Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Wed, 7 Jun 2023 14:41:35 -0700 Subject: [PATCH 37/72] add circuit name attribute: g --- src/race/race.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/race/race.py b/src/race/race.py index b3daf06..99d293d 100644 --- a/src/race/race.py +++ b/src/race/race.py @@ -4,17 +4,20 @@ class Race(): """ TODO """ - def __init__(self, name: str, country: str, city: str): + def __init__(self, name: str, country: str, city: str, circuit: str): if not isinstance(name, str): raise TypeError(f"{name} must be of type str, not {type(name)}") if not isinstance(country, str): raise TypeError(f"{country} must be of type str, not {type(country)}") if not isinstance(city, str): raise TypeError(f"{city} must be of type str, not {type(city)}") + if not isinstance(circuit, str): + raise TypeError(f"{circuit} must be of type str, not {type(circuit)}") self.name = name self.country = country self.city = city + self.circuit = circuit def __str__(self) -> str: - return f"{self.name} Grand Prix ({self.city}, {self.country})" \ No newline at end of file + return f"{self.name} ({self.circuit} in {self.city}, {self.country})" \ No newline at end of file From aacafefb267c375ea188f836c3622b83b7059957 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Wed, 7 Jun 2023 14:42:06 -0700 Subject: [PATCH 38/72] remove race as a parameter of holdRace method, redundant --- src/championship/championship.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/championship/championship.py b/src/championship/championship.py index 6285e2e..0c80c17 100644 --- a/src/championship/championship.py +++ b/src/championship/championship.py @@ -103,17 +103,23 @@ def getTeamStandings(self) -> List[str]: return printable - def holdRace(self, race: Race, results: RaceResults): + def holdRace(self, race_results: RaceResults): ''' holds a race and updates standings given the results params: - race: Race - results: RaceResults + race_results: RaceResults ''' - if not isinstance(race, Race): - raise TypeError(f"{race} must be of type Race, not {type(race)}") + + # type checking + + if not isinstance(race_results, RaceResults): + raise TypeError(f"{race_results} must be of type RaceResults, not {type(race_results)}") + + if not isinstance(race_results.race, Race): + raise TypeError(f"{race_results.race} must be of type Race, not {type(race_results.race)}") - # type check the results + if not isinstance(race_results.results, dict): + raise TypeError(f"{race_results.results} must be of type dict, not {type(race_results.results)}") # TODO update standings based on the results \ No newline at end of file From 2ccd29827598ac4597586005e14c00257364a674 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Wed, 7 Jun 2023 14:46:56 -0700 Subject: [PATCH 39/72] bug fixes --- main.py | 10 +++++----- src/race/raceResults.py | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 024b99d..dda2fcf 100644 --- a/main.py +++ b/main.py @@ -118,7 +118,7 @@ def main(): country = "Bahrain", city = "Sakhir", circuit = "Bahrain International Circuit" - ), + ) # add race results @@ -127,10 +127,10 @@ def main(): formula_one_2023.holdRace( RaceResults( race = bahrain_gp, - rankings = list( - - ), # TODO - fastestLap = Driver() # TODO + rankings = [ + ver, per, alo, sai, ham, stroll, rus, bot, gas, alb, tsu, sar, mag, dev, hul, zho, nor, oco, lec, pia + ], + fastestLap = zho ) ) diff --git a/src/race/raceResults.py b/src/race/raceResults.py index 6601ee9..81b3369 100644 --- a/src/race/raceResults.py +++ b/src/race/raceResults.py @@ -22,6 +22,8 @@ def __init__(self, race: Race, rankings: List[Driver], fastestLap: Driver): points_system = [None, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + rankings.insert(0, None) + for i in range(1,21): if not isinstance(rankings[i], Driver): raise TypeError(f"{rankings[i]} must be of type Driver, not {type(rankings[i])}") From bcd14189d388abb6a48ff214db12b055964e538a Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Wed, 7 Jun 2023 14:57:39 -0700 Subject: [PATCH 40/72] i think it works[ --- main.py | 6 +----- src/championship/championship.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index dda2fcf..f583f77 100644 --- a/main.py +++ b/main.py @@ -111,7 +111,7 @@ def main(): ) ) - # create races + # add races and race results and print info bahrain_gp = Race( name = "Bahrain Grand Prix", @@ -119,11 +119,7 @@ def main(): city = "Sakhir", circuit = "Bahrain International Circuit" ) - - # add race results - print(bahrain_gp.__str__()) - formula_one_2023.holdRace( RaceResults( race = bahrain_gp, diff --git a/src/championship/championship.py b/src/championship/championship.py index 0c80c17..7c7c143 100644 --- a/src/championship/championship.py +++ b/src/championship/championship.py @@ -122,4 +122,22 @@ def holdRace(self, race_results: RaceResults): if not isinstance(race_results.results, dict): raise TypeError(f"{race_results.results} must be of type dict, not {type(race_results.results)}") - # TODO update standings based on the results \ No newline at end of file + # TODO update standings based on the results + + tms = list(self.team_standings.keys()) + + for i in range(len(tms)): + if not isinstance(tms[i], Team): + raise TypeError(f"") + + drs = list(tms[i].drivers) + + for j in range(len(drs)): + if not isinstance(drs[j], Driver): + raise TypeError(f"") + + new_points = race_results.getPointsForDriver(drs[j]) + + self.team_standings[tms[i]] += new_points + self.driver_standings[drs[j]] += new_points + From 0838fe5bb43487594681adf7f7ac15634a687a18 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Wed, 7 Jun 2023 15:00:13 -0700 Subject: [PATCH 41/72] add notes of what races to add --- main.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.py b/main.py index f583f77..799d735 100644 --- a/main.py +++ b/main.py @@ -113,6 +113,7 @@ def main(): # add races and race results and print info + # bahrain grand prix bahrain_gp = Race( name = "Bahrain Grand Prix", country = "Bahrain", @@ -130,6 +131,20 @@ def main(): ) ) + # TODO: saudi arabian grand prix + + # TODO: australian grand prix + + # TODO: azerbaijan grand prix + + # TODO: saudi arabian grand prix + + # TODO: miami grand prix + + # TODO: monaco grand prix + + # TODO: spanish grand prix + # print standings to the console print("\nTeam Standings") From 426499c5d1461d7a2d830e0fd738dd2530809df1 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Wed, 7 Jun 2023 15:53:36 -0700 Subject: [PATCH 42/72] add races --- main.py | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 117 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 799d735..e4f0bbc 100644 --- a/main.py +++ b/main.py @@ -114,6 +114,7 @@ def main(): # add races and race results and print info # bahrain grand prix + bahrain_gp = Race( name = "Bahrain Grand Prix", country = "Bahrain", @@ -131,21 +132,129 @@ def main(): ) ) - # TODO: saudi arabian grand prix + # saudi arabian grand prix + + saudi_gp = Race( + name = "Saudi Arabian Grand Prix", + country = "Saudi Arabia", + city = "Jeddah", + circuit = "Jeddah Corniche Circuit" + ) + print(saudi_gp.__str__()) + formula_one_2023.holdRace( + RaceResults( + race = saudi_gp, + rankings = [ + per, ver, alo, rus, ham, sai, lec, oco, gas, mag, tsu, hul, zho, dev, pia, sar, nor, bot, alb, stroll + ], + fastestLap = ver + ) + ) + + # australian grand prix + + australian_gp = Race( + name = "Australian Grand Prix", + country = "Australia", + city = "Melbourne", + circuit = "Albert Park Circuit" + ) + print(australian_gp.__str__()) + formula_one_2023.holdRace( + RaceResults( + race = australian_gp, + rankings = None, # TODO + fastestLap = None # TODO + ) + ) + + # azerbaijan grand prix + + azerbaijan_gp = Race( + name = "Azerbaijan Grand Prix", + country = "Azerbaijan", + city = "Baku", + circuit = "Baku City Circuit" + ) + print(azerbaijan_gp.__str__()) + formula_one_2023.holdRace( + RaceResults( + race = azerbaijan_gp, + rankings = None, # TODO + fastestLap = None # TODO + ) + ) + + # miami grand prix + + miami_gp = Race( + name = "Miami Grand Prix", + country = "United States", + city = "Miami", + circuit = "Miami International Autodrome" + ) + print(miami_gp.__str__()) + formula_one_2023.holdRace( + RaceResults( + race = miami_gp, + rankings = None, # TODO + fastestLap = None # TODO + ) + ) + + # monaco grand prix + + monaco_gp = Race( + name = "Monaco Grand Prix", + country = "Monaco", + city = "Monaco", + circuit = "Circuit de Monaco" + ) + print(monaco_gp.__str__()) + formula_one_2023.holdRace( + RaceResults( + race = monaco_gp, + rankings = None, # TODO + fastestLap = None # TODO + ) + ) - # TODO: australian grand prix + # spanish grand prix - # TODO: azerbaijan grand prix + spanish_gp = Race( + name = "Spanish Grand Prix", + country = "Spain", + city = "Barcelona", + circuit = "Circuit de Barcelona-Catalunya" + ) + print(spanish_gp.__str__()) + formula_one_2023.holdRace( + RaceResults( + race = spanish_gp, + rankings = None, # TODO + fastestLap = None # TODO + ) + ) - # TODO: saudi arabian grand prix + # future races for the 2023 season - # TODO: miami grand prix + canadian_gp = Race( + name = "Canadian Grand Prix", + country = "Canada", + city = "Montreal", + circuit = "Circuit Gilles Villeneuve" + ) - # TODO: monaco grand prix + austrian_gp = Race( + name = "Austrian Grand Prix", + country = "Austria", + city = "Spielberg", + circuit = "Red Bull Ring" + ) - # TODO: spanish grand prix + # TODO add the rest of the future races for 2023 - # print standings to the console + # print current standings to the console print("\nTeam Standings") for x in formula_one_2023.getTeamStandings(): From 9add6e3b8006ea8da893c6ffff4b35d0a8268d86 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Wed, 7 Jun 2023 16:02:35 -0700 Subject: [PATCH 43/72] unit tests for driver --- tests/test_driver.py | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/tests/test_driver.py b/tests/test_driver.py index a204b43..e346bb9 100644 --- a/tests/test_driver.py +++ b/tests/test_driver.py @@ -1,4 +1,44 @@ import pytest +from src.driver.driver import Driver from typing import Any -# TODO \ No newline at end of file +@pytest.fixture +def driver_fixture(): + return Driver( + surname = "Doe", + givenname = "John", + number = 0, + nationality = "Internet", + surname_first = False, + suffix = "Jr." + ) + +@pytest.fixture +def driver_fixture(): + return Driver( + surname = "Doe", + givenname = "John", + number = 0, + nationality = "Internet", + surname_first = False, + suffix = "Jr." + ) + +def test___str___(driver_fixture: Driver): + d = driver_fixture + s = d.__str__() + + assert isinstance(d, Driver) + assert isinstance(s, str) + + assert s == "John DOE Jr. #0" + +def test___str___last_first(driver_fixture: Driver): + d = driver_fixture + d.surname_first = True + s = d.__str__() + + assert isinstance(d, Driver) + assert isinstance(s, str) + + assert s == "DOE John Jr. #0" \ No newline at end of file From 8d2dcab40ff221b2c7ce4a793aee5f7ef830ad43 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Wed, 7 Jun 2023 16:03:31 -0700 Subject: [PATCH 44/72] remove unused imports and unused fixtures --- tests/test_driver.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/tests/test_driver.py b/tests/test_driver.py index e346bb9..e6bd7e9 100644 --- a/tests/test_driver.py +++ b/tests/test_driver.py @@ -1,17 +1,5 @@ import pytest from src.driver.driver import Driver -from typing import Any - -@pytest.fixture -def driver_fixture(): - return Driver( - surname = "Doe", - givenname = "John", - number = 0, - nationality = "Internet", - surname_first = False, - suffix = "Jr." - ) @pytest.fixture def driver_fixture(): @@ -30,10 +18,10 @@ def test___str___(driver_fixture: Driver): assert isinstance(d, Driver) assert isinstance(s, str) - + assert s == "John DOE Jr. #0" -def test___str___last_first(driver_fixture: Driver): +def test___str___surname_first(driver_fixture: Driver): d = driver_fixture d.surname_first = True s = d.__str__() From c03c00e23464b673e097d130048cbce62cf67236 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Wed, 7 Jun 2023 16:26:58 -0700 Subject: [PATCH 45/72] add and reformat tests, add dummy data --- src/team/team.py | 10 +++++++-- tests/dummy_data.py | 49 ++++++++++++++++++++++++++++++++++++++++++++ tests/test_driver.py | 27 +++++++++++------------- tests/test_team.py | 43 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 110 insertions(+), 19 deletions(-) create mode 100644 tests/dummy_data.py diff --git a/src/team/team.py b/src/team/team.py index a509c15..1d387c0 100644 --- a/src/team/team.py +++ b/src/team/team.py @@ -29,7 +29,10 @@ def __init__(self, name: str, engine: EngineInt, country: str, drivers: List[Dri def addDriverToTeam(self, driver: Driver): """ - TODO + adds a driver to the team + + params: + driver: Driver """ if not isinstance(driver, Driver): raise TypeError(f"{driver} must be of type Driver, not {type(driver)}") @@ -39,7 +42,10 @@ def addDriverToTeam(self, driver: Driver): def removeDriverFromTeam(self, driver: Driver): """ - TODO + removes a driver from the team + + params: + driver: Driver """ if not isinstance(driver, Driver): raise TypeError(f"{driver} must be of type Driver, not {type(driver)}") diff --git a/tests/dummy_data.py b/tests/dummy_data.py new file mode 100644 index 0000000..ffd9765 --- /dev/null +++ b/tests/dummy_data.py @@ -0,0 +1,49 @@ +from src.championship.championship import Championship +from src.driver.driver import Driver +from src.engine.engine import Engine +from src.race.race import Race +from src.series.series import Series +from src.team.team import Team + +DUMMY_DRIVER = Driver( + surname = "Doe", + givenname = "John", + number = 0, + nationality = "Internet", + surname_first = False, + suffix = "Jr." +) + +DUMMY_DRIVER_TWO = Driver( + surname = "", + givenname = "", + number = -1, + nationality = "", + surname_first = False, + suffix = None +) + +DUMMY_ENGINE = Engine(engine = "Dummy Engine") + +DUMMY_RACE = Race( + name = "Dummy Race", + country = "Internet", + city = "Internet City", + circuit = "Internet Circuit" +) + +DUMMY_SERIES = Series( + name = "Dummy Series" +) + +DUMMY_CHAMPIONSHIP = Championship( + series = DUMMY_SERIES, + year = 0 +) + +DUMMY_TEAM = Team( + name = "Dummy Team", + engine = DUMMY_ENGINE, + country = "Internet", + drivers = [] +) \ No newline at end of file diff --git a/tests/test_driver.py b/tests/test_driver.py index e6bd7e9..0a8025b 100644 --- a/tests/test_driver.py +++ b/tests/test_driver.py @@ -1,32 +1,29 @@ +from copy import deepcopy import pytest from src.driver.driver import Driver +from tests.dummy_data import DUMMY_DRIVER @pytest.fixture def driver_fixture(): - return Driver( - surname = "Doe", - givenname = "John", - number = 0, - nationality = "Internet", - surname_first = False, - suffix = "Jr." - ) + return deepcopy(DUMMY_DRIVER) def test___str___(driver_fixture: Driver): - d = driver_fixture - s = d.__str__() - assert isinstance(d, Driver) + assert isinstance(driver_fixture, Driver) + + s = driver_fixture.__str__() assert isinstance(s, str) assert s == "John DOE Jr. #0" def test___str___surname_first(driver_fixture: Driver): - d = driver_fixture - d.surname_first = True - s = d.__str__() + + assert isinstance(driver_fixture, Driver) + + driver_fixture.surname_first = True + assert isinstance(driver_fixture, Driver) - assert isinstance(d, Driver) + s = driver_fixture.__str__() assert isinstance(s, str) assert s == "DOE John Jr. #0" \ No newline at end of file diff --git a/tests/test_team.py b/tests/test_team.py index 45970c9..19c1d4e 100644 --- a/tests/test_team.py +++ b/tests/test_team.py @@ -1,6 +1,45 @@ +from copy import deepcopy import pytest from src.driver.driver import Driver from src.engine.engine import * -from typing import Any, List +from src.team.team import Team +from tests.dummy_data import DUMMY_DRIVER, DUMMY_DRIVER_TWO, DUMMY_TEAM -# TODO \ No newline at end of file +@pytest.fixture +def driver_fixture(): + return deepcopy(DUMMY_DRIVER) + +@pytest.fixture +def team_fixture(): + return deepcopy(DUMMY_TEAM) + +def test_addDriverToTeam(team_fixture: Team, driver_fixture: Driver): + assert isinstance(team_fixture, Team) + assert isinstance(driver_fixture, Driver) + + assert len(team_fixture.drivers) == 0 + team_fixture.addDriverToTeam(driver_fixture) + + assert len(team_fixture.drivers) == 1 + assert team_fixture.drivers[0] == driver_fixture + + team_fixture.addDriverToTeam(driver_fixture) + assert len(team_fixture.drivers) == 1 + +def test_removeDriverFromTeam(team_fixture: Team, driver_fixture: Driver): + team_fixture = team_fixture + + assert isinstance(team_fixture, Team) + assert isinstance(driver_fixture, Driver) + + assert len(team_fixture.drivers) == 0 + team_fixture.addDriverToTeam(driver_fixture) + + assert len(team_fixture.drivers) == 1 + assert team_fixture.drivers[0] == driver_fixture + + team_fixture.removeDriverFromTeam(DUMMY_DRIVER_TWO) + assert len(team_fixture.drivers) == 1 + + team_fixture.removeDriverFromTeam(driver_fixture) + assert len(team_fixture.drivers) == 0 \ No newline at end of file From efeb8ba0b780af80fc87829cae8b4aeeae080c85 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Wed, 7 Jun 2023 16:27:35 -0700 Subject: [PATCH 46/72] remove unused import --- tests/test_team.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_team.py b/tests/test_team.py index 19c1d4e..568a176 100644 --- a/tests/test_team.py +++ b/tests/test_team.py @@ -1,7 +1,6 @@ from copy import deepcopy import pytest from src.driver.driver import Driver -from src.engine.engine import * from src.team.team import Team from tests.dummy_data import DUMMY_DRIVER, DUMMY_DRIVER_TWO, DUMMY_TEAM From 1ce22d5744ac155aff2e9b25c396b10fad6e1c56 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Thu, 8 Jun 2023 13:26:31 -0700 Subject: [PATCH 47/72] add method getDrivers --- src/team/team.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/team/team.py b/src/team/team.py index 1d387c0..e9e3b1d 100644 --- a/src/team/team.py +++ b/src/team/team.py @@ -51,4 +51,7 @@ def removeDriverFromTeam(self, driver: Driver): raise TypeError(f"{driver} must be of type Driver, not {type(driver)}") if driver in self.drivers: - self.drivers.remove(driver) \ No newline at end of file + self.drivers.remove(driver) + + def getDrivers(self) -> List[Driver]: + return self.drivers \ No newline at end of file From 621007a60983bcad1f6a786b14f5f04e6a6b3653 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Thu, 8 Jun 2023 13:26:45 -0700 Subject: [PATCH 48/72] add test case for getDrivers --- tests/test_team.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test_team.py b/tests/test_team.py index 568a176..100630e 100644 --- a/tests/test_team.py +++ b/tests/test_team.py @@ -41,4 +41,19 @@ def test_removeDriverFromTeam(team_fixture: Team, driver_fixture: Driver): assert len(team_fixture.drivers) == 1 team_fixture.removeDriverFromTeam(driver_fixture) - assert len(team_fixture.drivers) == 0 \ No newline at end of file + assert len(team_fixture.drivers) == 0 + +def test_getDrivers(team_fixture: Team, driver_fixture: Driver): + assert isinstance(team_fixture, Team) + + assert len(team_fixture.getDrivers()) == 0 + + team_fixture.addDriverToTeam(driver = driver_fixture) + + drivers = team_fixture.getDrivers() + + assert isinstance(drivers, list) + assert len(drivers) == 1 + + assert isinstance(drivers[0], Driver) + assert drivers[0] == driver_fixture \ No newline at end of file From 252eaf42f890ab8123fbd541db4f34a76b477638 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Thu, 8 Jun 2023 13:29:49 -0700 Subject: [PATCH 49/72] final commit --- tests/test_series.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_series.py b/tests/test_series.py index 81e71b8..5148b5f 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -1,5 +1,9 @@ +from copy import deepcopy import pytest from src.series.series import Series +from tests.dummy_data import DUMMY_SERIES from typing import Any -# TODO \ No newline at end of file +@pytest.fixture +def series_fixture(): + return deepcopy(DUMMY_SERIES) \ No newline at end of file From 54ba35f250a3ab2729a80c52763fc397874a6090 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Thu, 8 Jun 2023 14:24:51 -0700 Subject: [PATCH 50/72] series class test cases --- tests/test_series.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_series.py b/tests/test_series.py index 5148b5f..f96dc42 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -6,4 +6,12 @@ @pytest.fixture def series_fixture(): - return deepcopy(DUMMY_SERIES) \ No newline at end of file + return deepcopy(DUMMY_SERIES) + +def test___str__(series_fixture: Series): + assert isinstance(series_fixture, Series) + + s = series_fixture.__str__() + + assert isinstance(s, str) + assert s == "Dummy Series" \ No newline at end of file From c906134277ce23b00fa5a25334c3fd552a4c2f38 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Thu, 8 Jun 2023 14:28:15 -0700 Subject: [PATCH 51/72] add __str__ for series class --- src/series/series.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/series/series.py b/src/series/series.py index efbb53d..4a3b614 100644 --- a/src/series/series.py +++ b/src/series/series.py @@ -5,4 +5,7 @@ class Series(): a class to represent a racing series """ def __init__(self, name: str): - self.name = name \ No newline at end of file + self.name = name + + def __str__(self) -> str: + return self.name \ No newline at end of file From edcdff8b0eea50e6aee550146b380e23767a09d0 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Thu, 8 Jun 2023 14:32:29 -0700 Subject: [PATCH 52/72] fixtures and imports --- tests/test_championship.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/test_championship.py b/tests/test_championship.py index 752108a..34c299e 100644 --- a/tests/test_championship.py +++ b/tests/test_championship.py @@ -1,9 +1,18 @@ +from copy import deepcopy import pytest +from src.championship.championship import Championship from src.driver.driver import Driver from src.race.race import Race from src.race.raceResults import RaceResults from src.series.series import Series from src.team.team import Team +from tests.dummy_data import * # TODO edit this later to only import used dummy vars from typing import Any, List -# TODO \ No newline at end of file +# fixtures + +@pytest.fixture +def championship_fixture(): + return deepcopy(DUMMY_CHAMPIONSHIP) + +# TODO test cases \ No newline at end of file From 7c0702f28c8c824646f48590bda38805702b8ab9 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Thu, 8 Jun 2023 14:32:41 -0700 Subject: [PATCH 53/72] add typechecking --- src/series/series.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/series/series.py b/src/series/series.py index 4a3b614..e39e7b4 100644 --- a/src/series/series.py +++ b/src/series/series.py @@ -5,7 +5,13 @@ class Series(): a class to represent a racing series """ def __init__(self, name: str): + if not isinstance(name, str): + raise TypeError(f"{name} must be of type str, not {type(name)}") + self.name = name def __str__(self) -> str: + if not isinstance(self.name, str): + raise TypeError(f"{self.name} must be of type str, not {type(self.name)}") + return self.name \ No newline at end of file From 1a4e948c96a7001f6a3d567f2654f65a835ad9a7 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Thu, 8 Jun 2023 14:32:54 -0700 Subject: [PATCH 54/72] add __str__ method --- src/championship/championship.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/championship/championship.py b/src/championship/championship.py index 7c7c143..829ab25 100644 --- a/src/championship/championship.py +++ b/src/championship/championship.py @@ -141,3 +141,10 @@ def holdRace(self, race_results: RaceResults): self.team_standings[tms[i]] += new_points self.driver_standings[drs[j]] += new_points + def __str__(self) -> str: + if not isinstance(self.series, Series): + raise TypeError(f"{self.series} must be of type Series, not {type(self.series)}") + if not isinstance(self.year, int): + raise TypeError(f"{self.year} must be of type int, not {type(self.year)}") + + return f"{self.series} {self.year} Championship" \ No newline at end of file From 100458845416b5145303088bbacb107c5287f7a2 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Thu, 8 Jun 2023 15:04:30 -0700 Subject: [PATCH 55/72] championship tests --- tests/dummy_data.py | 2 +- tests/test_championship.py | 168 ++++++++++++++++++++++++++++++++++++- 2 files changed, 167 insertions(+), 3 deletions(-) diff --git a/tests/dummy_data.py b/tests/dummy_data.py index ffd9765..b2e91e3 100644 --- a/tests/dummy_data.py +++ b/tests/dummy_data.py @@ -38,7 +38,7 @@ DUMMY_CHAMPIONSHIP = Championship( series = DUMMY_SERIES, - year = 0 + year = 1011 ) DUMMY_TEAM = Team( diff --git a/tests/test_championship.py b/tests/test_championship.py index 34c299e..cead1ba 100644 --- a/tests/test_championship.py +++ b/tests/test_championship.py @@ -6,7 +6,7 @@ from src.race.raceResults import RaceResults from src.series.series import Series from src.team.team import Team -from tests.dummy_data import * # TODO edit this later to only import used dummy vars +from tests.dummy_data import DUMMY_CHAMPIONSHIP, DUMMY_DRIVER, DUMMY_TEAM # TODO edit this later to only import used dummy vars from typing import Any, List # fixtures @@ -15,4 +15,168 @@ def championship_fixture(): return deepcopy(DUMMY_CHAMPIONSHIP) -# TODO test cases \ No newline at end of file +@pytest.fixture +def driver_fixture(): + return deepcopy(DUMMY_DRIVER) + +@pytest.fixture +def team_fixture(): + return deepcopy(DUMMY_TEAM) + +# test cases + +def test___str__(championship_fixture: Championship): + assert isinstance(championship_fixture, Championship) + + s = championship_fixture.__str__() + + assert isinstance(s, str) + assert s == "Dummy Series 1011 Championship" + +# addDriverToChampionship test cases + +def test_addDriverToChampionship(championship_fixture: Championship, driver_fixture: Driver): + assert isinstance(championship_fixture, Championship) + assert isinstance(driver_fixture, Driver) + + assert isinstance(championship_fixture.driver_standings, dict) + assert not bool(championship_fixture.driver_standings) # check if dict is empty + + championship_fixture.addDriverToChampionship(driver = driver_fixture) + + assert len(list(championship_fixture.driver_standings.keys())) == 1 # one key in dict + assert driver_fixture in championship_fixture.driver_standings.keys() # the key is correct + assert championship_fixture.driver_standings[driver_fixture] == 0 # the value for the key is correct + +def test_addDriverToChampionship_alreadyInChampionship(championship_fixture: Championship, driver_fixture: Driver): + assert isinstance(championship_fixture, Championship) + assert isinstance(driver_fixture, Driver) + + assert isinstance(championship_fixture.driver_standings, dict) + assert not bool(championship_fixture.driver_standings) # check if dict is empty + + championship_fixture.addDriverToChampionship(driver = driver_fixture) + + assert len(list(championship_fixture.driver_standings.keys())) == 1 # one key in dict + assert driver_fixture in championship_fixture.driver_standings.keys() # the key is correct + assert championship_fixture.driver_standings[driver_fixture] == 0 # the value for the key is correct + + # testing that there aren't now two different records for a single driver + + championship_fixture.addDriverToChampionship(driver = driver_fixture) + + assert len(list(championship_fixture.driver_standings.keys())) == 1 # one key in dict + assert driver_fixture in championship_fixture.driver_standings.keys() # the key is correct + assert championship_fixture.driver_standings[driver_fixture] == 0 # the value for the key is correct + +# when testing behavior of an object that can hold other objects, +# always test the behavior for when it's empty and not empty + +# addTeamToChampionship test cases + +def test_addTeamToChampionship_noDrivers(championship_fixture: Championship, team_fixture: Team): + assert isinstance(championship_fixture, Championship) + assert isinstance(team_fixture, Team) + + assert isinstance(championship_fixture.team_standings, dict) + assert not bool(championship_fixture.team_standings) # check if dict is empty + + championship_fixture.addTeamToChampionship(team = team_fixture) + + assert len(list(championship_fixture.team_standings.keys())) == 1 # one key in dict + assert team_fixture in championship_fixture.team_standings.keys() # the key is correct + assert championship_fixture.team_standings[team_fixture] == 0 # the value for the key is correct + +def test_addTeamToChampionship_hasDrivers(championship_fixture: Championship, driver_fixture: Driver, team_fixture: Team): + assert isinstance(championship_fixture, Championship) + assert isinstance(driver_fixture, Driver) + assert isinstance(team_fixture, Team) + + assert isinstance(championship_fixture.driver_standings, dict) + assert not bool(championship_fixture.driver_standings) # check if dict is empty + + assert isinstance(championship_fixture.team_standings, dict) + assert not bool(championship_fixture.team_standings) # check if dict is empty + + team_fixture.addDriverToTeam(driver = driver_fixture) + + championship_fixture.addTeamToChampionship(team = team_fixture) + + assert len(list(championship_fixture.team_standings.keys())) == 1 # one key in dict + assert team_fixture in championship_fixture.team_standings.keys() # the key is correct + assert championship_fixture.team_standings[team_fixture] == 0 # the value for the key is correct + + assert len(list(championship_fixture.driver_standings.keys())) == 1 # one key in dict + assert driver_fixture in championship_fixture.driver_standings.keys() # the key is correct + assert championship_fixture.driver_standings[driver_fixture] == 0 # the value for the key is correct + +def test_addTeamToChampionship_alreadyInChampionship(championship_fixture: Championship, team_fixture: Team): + assert isinstance(championship_fixture, Championship) + assert isinstance(team_fixture, Team) + + assert isinstance(championship_fixture.team_standings, dict) + + championship_fixture.addTeamToChampionship(team = team_fixture) + + assert len(list(championship_fixture.team_standings.keys())) == 1 # one key in dict + assert team_fixture in championship_fixture.team_standings.keys() # the key is correct + assert championship_fixture.team_standings[team_fixture] == 0 # the value for the key is correct + + # testing that there aren't now two different records for a single team + + championship_fixture.addTeamToChampionship(team = team_fixture) + + assert len(list(championship_fixture.team_standings.keys())) == 1 # one key in dict + assert team_fixture in championship_fixture.team_standings.keys() # the key is correct + assert championship_fixture.team_standings[team_fixture] == 0 # the value for the key is correct + +# removeDriverFromChampionship test cases + +def test_removeDriverFromChampionship(championship_fixture: Championship, driver_fixture: Driver): + assert isinstance(championship_fixture, Championship) + + pass # TODO + + +def test_removeDriverFromChampionship_notInChampionship(championship_fixture: Championship, driver_fixture: Driver): + assert isinstance(championship_fixture, Championship) + + pass # TODO + +# removeTeamFromChampionship test cases + +def test_removeTeamFromChampionship_noDrivers(championship_fixture: Championship, team_fixture: Team): + assert isinstance(championship_fixture, Championship) + + pass # TODO + +def test_removeTeamFromChampionship_hasDrivers(championship_fixture: Championship, driver_fixture: Driver, team_fixture: Team): + assert isinstance(championship_fixture, Championship) + + pass # TODO + +def test_removeTeamFromChampionship_notInChampionship(championship_fixture: Championship, driver_fixture: Driver, team_fixture: Team): + assert isinstance(championship_fixture, Championship) + + pass # TODO + +# getDriverStandings test cases + +def test_getDriverStandings(championship_fixture: Championship): + assert isinstance(championship_fixture, Championship) + + pass # TODO + +# getTeamStandings test cases + +def test_getTeamStandings(championship_fixture: Championship): + assert isinstance(championship_fixture, Championship) + + pass # TODO + +# holdRace test cases + +def test_holdRace(championship_fixture: Championship): + assert isinstance(championship_fixture, Championship) + + pass # TODO \ No newline at end of file From ddbddc08499a67eab617ffc52065453fb28e48e0 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Fri, 9 Jun 2023 11:43:22 -0700 Subject: [PATCH 56/72] more test cases --- src/championship/championship.py | 4 +- tests/dummy_data.py | 13 ++++-- tests/test_championship.py | 72 +++++++++++++++++++++++--------- 3 files changed, 64 insertions(+), 25 deletions(-) diff --git a/src/championship/championship.py b/src/championship/championship.py index 829ab25..21960b7 100644 --- a/src/championship/championship.py +++ b/src/championship/championship.py @@ -82,7 +82,7 @@ def getDriverStandings(self) -> List[str]: printable = list() for i in range(len(sorted_standings)): - printable.append(f"{i+1}: {sorted_standings[i][0].__str__()} ({sorted_standings[i][1]} points)") + printable.append(f"{str(i+1)}: {sorted_standings[i][0].__str__()} ({sorted_standings[i][1]} points)") return printable @@ -99,7 +99,7 @@ def getTeamStandings(self) -> List[str]: printable = list() for i in range(len(sorted_standings)): - printable.append(f"{i+1}: {sorted_standings[i][0].name} ({sorted_standings[i][1]} points)") + printable.append(f"{str(i+1)}: {sorted_standings[i][0].name} ({sorted_standings[i][1]} points)") return printable diff --git a/tests/dummy_data.py b/tests/dummy_data.py index b2e91e3..2f9a93e 100644 --- a/tests/dummy_data.py +++ b/tests/dummy_data.py @@ -15,10 +15,10 @@ ) DUMMY_DRIVER_TWO = Driver( - surname = "", - givenname = "", + surname = "Tables", + givenname = "Bobby", number = -1, - nationality = "", + nationality = "SQL Land", surname_first = False, suffix = None ) @@ -46,4 +46,11 @@ engine = DUMMY_ENGINE, country = "Internet", drivers = [] +) + +DUMMY_TEAM_TWO = Team( + name = "Dummy Team Two", + engine = DUMMY_ENGINE, + country = "Internet", + drivers = [] ) \ No newline at end of file diff --git a/tests/test_championship.py b/tests/test_championship.py index cead1ba..5785748 100644 --- a/tests/test_championship.py +++ b/tests/test_championship.py @@ -6,7 +6,7 @@ from src.race.raceResults import RaceResults from src.series.series import Series from src.team.team import Team -from tests.dummy_data import DUMMY_CHAMPIONSHIP, DUMMY_DRIVER, DUMMY_TEAM # TODO edit this later to only import used dummy vars +from tests.dummy_data import DUMMY_CHAMPIONSHIP, DUMMY_DRIVER, DUMMY_DRIVER_TWO, DUMMY_TEAM, DUMMY_TEAM_TWO from typing import Any, List # fixtures @@ -130,49 +130,81 @@ def test_addTeamToChampionship_alreadyInChampionship(championship_fixture: Champ assert team_fixture in championship_fixture.team_standings.keys() # the key is correct assert championship_fixture.team_standings[team_fixture] == 0 # the value for the key is correct -# removeDriverFromChampionship test cases +# removeTeamFromChampionship test cases -def test_removeDriverFromChampionship(championship_fixture: Championship, driver_fixture: Driver): +def test_removeTeamFromChampionship_noDrivers(championship_fixture: Championship, team_fixture: Team): assert isinstance(championship_fixture, Championship) + assert isinstance(team_fixture, Team) - pass # TODO + championship_fixture.addTeamToChampionship(team = team_fixture) + assert championship_fixture.team_standings[team_fixture] == 0 + championship_fixture.removeTeamFromChampionship(team = team_fixture) + assert not championship_fixture.team_standings[team_fixture] -def test_removeDriverFromChampionship_notInChampionship(championship_fixture: Championship, driver_fixture: Driver): +def test_removeTeamFromChampionship_hasDrivers(championship_fixture: Championship, driver_fixture: Driver, team_fixture: Team): assert isinstance(championship_fixture, Championship) + assert isinstance(team_fixture, Team) + assert isinstance(driver_fixture, Driver) - pass # TODO - -# removeTeamFromChampionship test cases + team_fixture.addDriverToTeam(driver = driver_fixture) + assert team_fixture.drivers[0] == driver_fixture -def test_removeTeamFromChampionship_noDrivers(championship_fixture: Championship, team_fixture: Team): - assert isinstance(championship_fixture, Championship) + championship_fixture.addTeamToChampionship(team = team_fixture) + assert championship_fixture.team_standings[team_fixture] == 0 - pass # TODO + championship_fixture.removeTeamFromChampionship(team = team_fixture) + assert not championship_fixture.team_standings[team_fixture] -def test_removeTeamFromChampionship_hasDrivers(championship_fixture: Championship, driver_fixture: Driver, team_fixture: Team): +def test_removeTeamFromChampionship_notInChampionship(championship_fixture: Championship, driver_fixture: Driver, team_fixture: Team): assert isinstance(championship_fixture, Championship) + assert isinstance(team_fixture, Team) - pass # TODO + with pytest.raises(KeyError): + championship_fixture.team_standings[team_fixture] -def test_removeTeamFromChampionship_notInChampionship(championship_fixture: Championship, driver_fixture: Driver, team_fixture: Team): - assert isinstance(championship_fixture, Championship) + championship_fixture.removeTeamFromChampionship(team = team_fixture) - pass # TODO + with pytest.raises(KeyError): + championship_fixture.team_standings[team_fixture] # getDriverStandings test cases -def test_getDriverStandings(championship_fixture: Championship): +def test_getDriverStandings(championship_fixture: Championship, driver_fixture: Driver): assert isinstance(championship_fixture, Championship) + assert isinstance(driver_fixture, Driver) + + championship_fixture.addDriverToChampionship(driver = driver_fixture) + championship_fixture.addDriverToChampionship(driver = DUMMY_DRIVER_TWO) - pass # TODO + championship_fixture.driver_standings[driver_fixture] = 2 + championship_fixture.driver_standings[DUMMY_DRIVER_TWO] = 18 + + d_stand = championship_fixture.getDriverStandings() + assert isinstance(d_stand, list) + assert len(d_stand) == 2 + + assert d_stand[0] == f"1: {DUMMY_DRIVER_TWO.__str__()} (18 points)" + assert d_stand[1] == f"2: {driver_fixture.__str__()} (2 points)" # getTeamStandings test cases -def test_getTeamStandings(championship_fixture: Championship): +def test_getTeamStandings(championship_fixture: Championship, team_fixture: Team): assert isinstance(championship_fixture, Championship) + assert isinstance(team_fixture, Team) + + championship_fixture.addTeamToChampionship(team = team_fixture) + championship_fixture.addTeamToChampionship(team = DUMMY_TEAM_TWO) + + championship_fixture.team_standings[team_fixture] = 2 + championship_fixture.team_standings[DUMMY_TEAM_TWO] = 18 + + t_stand = championship_fixture.getTeamStandings() + assert isinstance(t_stand, list) + assert len(t_stand) == 2 - pass # TODO + assert t_stand[0] == "1: Dummy Team Two (18 points)" + assert t_stand[1] == "2: Dummy Team (2 points)" # holdRace test cases From 203114b106f09967d074ad2485850842cab2b0f1 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Fri, 9 Jun 2023 11:48:13 -0700 Subject: [PATCH 57/72] engine unit tests --- tests/dummy_data.py | 2 +- tests/test_engine.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/dummy_data.py b/tests/dummy_data.py index 2f9a93e..48ed0f6 100644 --- a/tests/dummy_data.py +++ b/tests/dummy_data.py @@ -23,7 +23,7 @@ suffix = None ) -DUMMY_ENGINE = Engine(engine = "Dummy Engine") +DUMMY_ENGINE = Engine(engine = "Dummy") DUMMY_RACE = Race( name = "Dummy Race", diff --git a/tests/test_engine.py b/tests/test_engine.py index 85e664e..358991f 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -1,5 +1,16 @@ +from copy import deepcopy import pytest -from src.engine.engine import * -from typing import Any +from src.engine.engine import Engine +from tests.dummy_data import DUMMY_ENGINE -# TODO \ No newline at end of file +@pytest.fixture +def engine_fixture(): + return deepcopy(DUMMY_ENGINE) + +def test___str__(engine_fixture: Engine): + assert isinstance(engine_fixture, Engine) + + s = engine_fixture.__str__() + + assert isinstance(s, str) + assert s == "Dummy Engine" \ No newline at end of file From 83e26ae276adb3ad179f6bc72b27a4c1a5afc04c Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Fri, 9 Jun 2023 11:50:35 -0700 Subject: [PATCH 58/72] unit tests --- tests/test_race.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/test_race.py b/tests/test_race.py index df1ad1a..2080517 100644 --- a/tests/test_race.py +++ b/tests/test_race.py @@ -1,3 +1,16 @@ +from copy import deepcopy import pytest from src.race.race import Race -from typing import Any \ No newline at end of file +from tests.dummy_data import DUMMY_RACE + +@pytest.fixture +def race_fixture(): + return deepcopy(DUMMY_RACE) + +def test___str__(race_fixture: Race): + assert isinstance(race_fixture, Race) + + s = race_fixture.__str__() + + assert isinstance(s, str) + assert s == f"Dummy Race (Internet Circuit in Internet City, Internet)" \ No newline at end of file From c9613500f24496a8e248a1c4ad44532d28705fe1 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Fri, 9 Jun 2023 11:57:07 -0700 Subject: [PATCH 59/72] comments --- tests/test_engine.py | 4 ++++ tests/test_race.py | 4 ++++ tests/test_raceResults.py | 22 +++++++++++++++++++++- tests/test_team.py | 4 ++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/test_engine.py b/tests/test_engine.py index 358991f..3052264 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -3,10 +3,14 @@ from src.engine.engine import Engine from tests.dummy_data import DUMMY_ENGINE +# Fixtures + @pytest.fixture def engine_fixture(): return deepcopy(DUMMY_ENGINE) +# Test Cases + def test___str__(engine_fixture: Engine): assert isinstance(engine_fixture, Engine) diff --git a/tests/test_race.py b/tests/test_race.py index 2080517..4b774fc 100644 --- a/tests/test_race.py +++ b/tests/test_race.py @@ -3,10 +3,14 @@ from src.race.race import Race from tests.dummy_data import DUMMY_RACE +# Fixtures + @pytest.fixture def race_fixture(): return deepcopy(DUMMY_RACE) +# Test Cases + def test___str__(race_fixture: Race): assert isinstance(race_fixture, Race) diff --git a/tests/test_raceResults.py b/tests/test_raceResults.py index d120dec..5142878 100644 --- a/tests/test_raceResults.py +++ b/tests/test_raceResults.py @@ -1,5 +1,25 @@ +from copy import deepcopy import pytest from src.driver.driver import Driver from src.race.race import Race +from src.race.raceResults import RaceResults from src.team.team import Team -from typing import Any, Dict, List \ No newline at end of file +from tests.dummy_data import DUMMY_DRIVER, DUMMY_DRIVER_TWO, DUMMY_RACE, DUMMY_RACE_RESULTS, DUMMY_TEAM + +# Fixtures + +@pytest.fixture +def driver_fixture(): + return deepcopy(DUMMY_DRIVER) + +@pytest.fixture +def race_fixture(): + return deepcopy(DUMMY_RACE) + +@pytest.fixture +def team_fixture(): + return deepcopy(DUMMY_TEAM) + +# Test Cases + +# TODO \ No newline at end of file diff --git a/tests/test_team.py b/tests/test_team.py index 100630e..2014a32 100644 --- a/tests/test_team.py +++ b/tests/test_team.py @@ -4,6 +4,8 @@ from src.team.team import Team from tests.dummy_data import DUMMY_DRIVER, DUMMY_DRIVER_TWO, DUMMY_TEAM +# Fixtures + @pytest.fixture def driver_fixture(): return deepcopy(DUMMY_DRIVER) @@ -12,6 +14,8 @@ def driver_fixture(): def team_fixture(): return deepcopy(DUMMY_TEAM) +# Test Cases + def test_addDriverToTeam(team_fixture: Team, driver_fixture: Driver): assert isinstance(team_fixture, Team) assert isinstance(driver_fixture, Driver) From 16b20fc315a959a7bb3856f28570a35d0f20c0ac Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Fri, 9 Jun 2023 11:57:37 -0700 Subject: [PATCH 60/72] add dummy data for RaceResults --- tests/dummy_data.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/dummy_data.py b/tests/dummy_data.py index 48ed0f6..edf5865 100644 --- a/tests/dummy_data.py +++ b/tests/dummy_data.py @@ -2,6 +2,7 @@ from src.driver.driver import Driver from src.engine.engine import Engine from src.race.race import Race +from src.race.raceResults import RaceResults from src.series.series import Series from src.team.team import Team @@ -53,4 +54,10 @@ engine = DUMMY_ENGINE, country = "Internet", drivers = [] +) + +DUMMY_RACE_RESULTS = RaceResults( + race = DUMMY_RACE, + rankings = [DUMMY_DRIVER, DUMMY_DRIVER_TWO], + fastestLap = DUMMY_DRIVER ) \ No newline at end of file From 3d61cbc6dc4ef5007929f71c5ac963be3c015768 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Fri, 9 Jun 2023 11:58:12 -0700 Subject: [PATCH 61/72] remove unused imports and cleanup comment formatting --- tests/test_championship.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/test_championship.py b/tests/test_championship.py index 5785748..0f9f572 100644 --- a/tests/test_championship.py +++ b/tests/test_championship.py @@ -4,12 +4,10 @@ from src.driver.driver import Driver from src.race.race import Race from src.race.raceResults import RaceResults -from src.series.series import Series from src.team.team import Team -from tests.dummy_data import DUMMY_CHAMPIONSHIP, DUMMY_DRIVER, DUMMY_DRIVER_TWO, DUMMY_TEAM, DUMMY_TEAM_TWO -from typing import Any, List +from tests.dummy_data import DUMMY_CHAMPIONSHIP, DUMMY_DRIVER, DUMMY_DRIVER_TWO, DUMMY_RACE, DUMMY_RACE_RESULTS, DUMMY_TEAM, DUMMY_TEAM_TWO -# fixtures +# Fixtures @pytest.fixture def championship_fixture(): @@ -19,11 +17,15 @@ def championship_fixture(): def driver_fixture(): return deepcopy(DUMMY_DRIVER) +@pytest.fixture +def race_fixture(): + return deepcopy(DUMMY_RACE) + @pytest.fixture def team_fixture(): return deepcopy(DUMMY_TEAM) -# test cases +# Test Cases def test___str__(championship_fixture: Championship): assert isinstance(championship_fixture, Championship) @@ -208,7 +210,7 @@ def test_getTeamStandings(championship_fixture: Championship, team_fixture: Team # holdRace test cases -def test_holdRace(championship_fixture: Championship): +def test_holdRace(championship_fixture: Championship, race_fixture: Race): assert isinstance(championship_fixture, Championship) pass # TODO \ No newline at end of file From c66330fc8831b2a8c878de40395bf18bff634786 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Fri, 9 Jun 2023 11:59:35 -0700 Subject: [PATCH 62/72] skeleton for teamfactory tests --- tests/test_teamFactory.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_teamFactory.py b/tests/test_teamFactory.py index be885b1..7381f8e 100644 --- a/tests/test_teamFactory.py +++ b/tests/test_teamFactory.py @@ -1,8 +1,14 @@ +from copy import deepcopy import pytest from src.driver.driver import Driver from src.engine.engine import * from src.team.team import Team from src.team.teamFactory import * -from typing import Any, List + +# Fixtures + +# TODO + +# Test Cases # TODO \ No newline at end of file From 47f5a8b6f3844c4eccbf006b5380dbfb4bc92ec1 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Fri, 9 Jun 2023 12:06:47 -0700 Subject: [PATCH 63/72] fix bug --- src/race/raceResults.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/race/raceResults.py b/src/race/raceResults.py index 81b3369..5139b97 100644 --- a/src/race/raceResults.py +++ b/src/race/raceResults.py @@ -25,6 +25,8 @@ def __init__(self, race: Race, rankings: List[Driver], fastestLap: Driver): rankings.insert(0, None) for i in range(1,21): + if i >= len(rankings): + break if not isinstance(rankings[i], Driver): raise TypeError(f"{rankings[i]} must be of type Driver, not {type(rankings[i])}") From 40d004bd78fddd89e2e627f6e01841ccb1c5e083 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Fri, 9 Jun 2023 12:19:57 -0700 Subject: [PATCH 64/72] team factory tests and fixes --- src/team/teamFactory.py | 4 +- tests/test_teamFactory.py | 108 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 107 insertions(+), 5 deletions(-) diff --git a/src/team/teamFactory.py b/src/team/teamFactory.py index 5355d05..45d79eb 100644 --- a/src/team/teamFactory.py +++ b/src/team/teamFactory.py @@ -5,14 +5,14 @@ class TeamFactory: @staticmethod - def createTeam(name: str, engine: EngineInt | str, country: str, drivers: List[Driver]) -> Team: + def createTeam(name: str, engine: Engine | str, country: str, drivers: List[Driver]) -> Team: """ create a team with a custom engine params: name: str - engine: EngineInt | str + engine: Engine | str country: str drivers: List(Driver) diff --git a/tests/test_teamFactory.py b/tests/test_teamFactory.py index 7381f8e..0f00049 100644 --- a/tests/test_teamFactory.py +++ b/tests/test_teamFactory.py @@ -1,14 +1,116 @@ from copy import deepcopy import pytest -from src.driver.driver import Driver from src.engine.engine import * from src.team.team import Team from src.team.teamFactory import * +from tests.dummy_data import DUMMY_DRIVER, DUMMY_ENGINE, DUMMY_TEAM +from typing import Any # Fixtures -# TODO +@pytest.fixture +def driver_fixture(): + return deepcopy(DUMMY_DRIVER) + +@pytest.fixture +def engine_fixture(): + return deepcopy(DUMMY_ENGINE) + +# Helper Method + +def verify_teams(expected: Team, actual: Any): + assert type(expected) == type(actual) == Team + + assert expected.name == actual.name + + assert type(expected.engine) == type(actual.engine) and issubclass(type(expected.engine), EngineInt) + assert expected.engine == actual.engine + + assert expected.country == actual.country + + assert type(expected.drivers) == type(actual.drivers) == list + assert len(expected.drivers) == len(actual.drivers) + for i in range(len(expected.drivers)): + assert expected.drivers[i] == actual.drivers[i] # Test Cases -# TODO \ No newline at end of file +def test_createTeam(engine_fixture: Engine): + assert isinstance(engine_fixture, Engine) + + t = TeamFactory.createTeam( + name = "Foo", + engine = engine_fixture, + country = "Foo", + drivers = [DUMMY_DRIVER] + ) + + assert isinstance(t, Team) + + verify_teams( + expected = Team(name = "Foo", engine = engine_fixture, country = "Foo", drivers = [DUMMY_DRIVER]), actual = t + ) + +def test_createTeamFerrariEngine(): + ferrari = FerrariEngine() + + t = TeamFactory.createTeam( + name = "Foo", + engine = ferrari, + country = "Foo", + drivers = [DUMMY_DRIVER] + ) + + assert isinstance(t, Team) + + verify_teams( + expected = Team(name = "Foo", engine = ferrari, country = "Foo", drivers = [DUMMY_DRIVER]), actual = t + ) + +def test_createTeamHondaRBPTEngine(): + hondarbpt = HondaRBPTEngine() + + t = TeamFactory.createTeam( + name = "Foo", + engine = hondarbpt, + country = "Foo", + drivers = [DUMMY_DRIVER] + ) + + assert isinstance(t, Team) + + verify_teams( + expected = Team(name = "Foo", engine = hondarbpt, country = "Foo", drivers = [DUMMY_DRIVER]), actual = t + ) + +def test_createTeamMercedesEngine(): + mercedes = MercedesEngine() + + t = TeamFactory.createTeam( + name = "Foo", + engine = mercedes, + country = "Foo", + drivers = [DUMMY_DRIVER] + ) + + assert isinstance(t, Team) + + verify_teams( + expected = Team(name = "Foo", engine = mercedes, country = "Foo", drivers = [DUMMY_DRIVER]), actual = t + ) + +def test_createTeamRenaultEngine(): + renault = RenaultEngine() + + t = TeamFactory.createTeam( + name = "Foo", + engine = renault, + country = "Foo", + drivers = [DUMMY_DRIVER] + ) + + assert isinstance(t, Team) + + verify_teams( + expected = Team(name = "Foo", engine = renault, country = "Foo", drivers = [DUMMY_DRIVER]), actual = t + ) \ No newline at end of file From 9518fdf512db9c68b91749223091c142e811da6e Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Sat, 10 Jun 2023 11:03:37 -0700 Subject: [PATCH 65/72] use fixture instead of directly using var --- tests/test_team.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_team.py b/tests/test_team.py index 2014a32..058153d 100644 --- a/tests/test_team.py +++ b/tests/test_team.py @@ -10,6 +10,10 @@ def driver_fixture(): return deepcopy(DUMMY_DRIVER) +@pytest.fixture +def driver_fixture_two(): + return deepcopy(DUMMY_DRIVER_TWO) + @pytest.fixture def team_fixture(): return deepcopy(DUMMY_TEAM) @@ -29,11 +33,12 @@ def test_addDriverToTeam(team_fixture: Team, driver_fixture: Driver): team_fixture.addDriverToTeam(driver_fixture) assert len(team_fixture.drivers) == 1 -def test_removeDriverFromTeam(team_fixture: Team, driver_fixture: Driver): +def test_removeDriverFromTeam(team_fixture: Team, driver_fixture: Driver, driver_fixture_two: Driver): team_fixture = team_fixture - assert isinstance(team_fixture, Team) assert isinstance(driver_fixture, Driver) + assert isinstance(driver_fixture_two, Driver) + assert isinstance(team_fixture, Team) assert len(team_fixture.drivers) == 0 team_fixture.addDriverToTeam(driver_fixture) @@ -41,7 +46,7 @@ def test_removeDriverFromTeam(team_fixture: Team, driver_fixture: Driver): assert len(team_fixture.drivers) == 1 assert team_fixture.drivers[0] == driver_fixture - team_fixture.removeDriverFromTeam(DUMMY_DRIVER_TWO) + team_fixture.removeDriverFromTeam(driver_fixture_two) assert len(team_fixture.drivers) == 1 team_fixture.removeDriverFromTeam(driver_fixture) From 10336c396d7bc2a83bf31f29fa531b13c85751d9 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Sat, 10 Jun 2023 11:04:02 -0700 Subject: [PATCH 66/72] remove extraneous todo --- src/championship/championship.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/championship/championship.py b/src/championship/championship.py index 21960b7..6ad67de 100644 --- a/src/championship/championship.py +++ b/src/championship/championship.py @@ -122,7 +122,7 @@ def holdRace(self, race_results: RaceResults): if not isinstance(race_results.results, dict): raise TypeError(f"{race_results.results} must be of type dict, not {type(race_results.results)}") - # TODO update standings based on the results + # update standings based on the results tms = list(self.team_standings.keys()) From e4fdeb46857b9c23f0db41d711b89dd6f59ec0cd Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Sat, 10 Jun 2023 11:18:11 -0700 Subject: [PATCH 67/72] championship tests --- tests/dummy_data.py | 6 ---- tests/test_championship.py | 66 +++++++++++++++++++++++++++++++------- tests/test_raceResults.py | 10 +++++- 3 files changed, 64 insertions(+), 18 deletions(-) diff --git a/tests/dummy_data.py b/tests/dummy_data.py index edf5865..c0c8ec8 100644 --- a/tests/dummy_data.py +++ b/tests/dummy_data.py @@ -54,10 +54,4 @@ engine = DUMMY_ENGINE, country = "Internet", drivers = [] -) - -DUMMY_RACE_RESULTS = RaceResults( - race = DUMMY_RACE, - rankings = [DUMMY_DRIVER, DUMMY_DRIVER_TWO], - fastestLap = DUMMY_DRIVER ) \ No newline at end of file diff --git a/tests/test_championship.py b/tests/test_championship.py index 0f9f572..9a0aded 100644 --- a/tests/test_championship.py +++ b/tests/test_championship.py @@ -5,7 +5,7 @@ from src.race.race import Race from src.race.raceResults import RaceResults from src.team.team import Team -from tests.dummy_data import DUMMY_CHAMPIONSHIP, DUMMY_DRIVER, DUMMY_DRIVER_TWO, DUMMY_RACE, DUMMY_RACE_RESULTS, DUMMY_TEAM, DUMMY_TEAM_TWO +from tests.dummy_data import DUMMY_CHAMPIONSHIP, DUMMY_DRIVER, DUMMY_DRIVER_TWO, DUMMY_RACE, DUMMY_TEAM, DUMMY_TEAM_TWO # Fixtures @@ -17,14 +17,26 @@ def championship_fixture(): def driver_fixture(): return deepcopy(DUMMY_DRIVER) +@pytest.fixture +def driver_fixture_two(): + return deepcopy(DUMMY_DRIVER_TWO) + @pytest.fixture def race_fixture(): return deepcopy(DUMMY_RACE) +@pytest.fixture +def race_results_fixture(): + return deepcopy(DUMMY_RACE_RESULTS) + @pytest.fixture def team_fixture(): return deepcopy(DUMMY_TEAM) +@pytest.fixture +def team_fixture_two(): + return deepcopy(DUMMY_TEAM_TWO) + # Test Cases def test___str__(championship_fixture: Championship): @@ -158,7 +170,7 @@ def test_removeTeamFromChampionship_hasDrivers(championship_fixture: Championshi championship_fixture.removeTeamFromChampionship(team = team_fixture) assert not championship_fixture.team_standings[team_fixture] -def test_removeTeamFromChampionship_notInChampionship(championship_fixture: Championship, driver_fixture: Driver, team_fixture: Team): +def test_removeTeamFromChampionship_notInChampionship(championship_fixture: Championship, team_fixture: Team): assert isinstance(championship_fixture, Championship) assert isinstance(team_fixture, Team) @@ -172,34 +184,36 @@ def test_removeTeamFromChampionship_notInChampionship(championship_fixture: Cham # getDriverStandings test cases -def test_getDriverStandings(championship_fixture: Championship, driver_fixture: Driver): +def test_getDriverStandings(championship_fixture: Championship, driver_fixture: Driver, driver_fixture_two: Driver): assert isinstance(championship_fixture, Championship) assert isinstance(driver_fixture, Driver) + assert isinstance(driver_fixture_two, Driver) championship_fixture.addDriverToChampionship(driver = driver_fixture) - championship_fixture.addDriverToChampionship(driver = DUMMY_DRIVER_TWO) + championship_fixture.addDriverToChampionship(driver = driver_fixture_two) championship_fixture.driver_standings[driver_fixture] = 2 - championship_fixture.driver_standings[DUMMY_DRIVER_TWO] = 18 + championship_fixture.driver_standings[driver_fixture_two] = 18 d_stand = championship_fixture.getDriverStandings() assert isinstance(d_stand, list) assert len(d_stand) == 2 - assert d_stand[0] == f"1: {DUMMY_DRIVER_TWO.__str__()} (18 points)" + assert d_stand[0] == f"1: {driver_fixture_two.__str__()} (18 points)" assert d_stand[1] == f"2: {driver_fixture.__str__()} (2 points)" # getTeamStandings test cases -def test_getTeamStandings(championship_fixture: Championship, team_fixture: Team): +def test_getTeamStandings(championship_fixture: Championship, team_fixture: Team, team_fixture_two: Team): assert isinstance(championship_fixture, Championship) assert isinstance(team_fixture, Team) + assert isinstance(team_fixture_two, Team) championship_fixture.addTeamToChampionship(team = team_fixture) - championship_fixture.addTeamToChampionship(team = DUMMY_TEAM_TWO) + championship_fixture.addTeamToChampionship(team = team_fixture_two) championship_fixture.team_standings[team_fixture] = 2 - championship_fixture.team_standings[DUMMY_TEAM_TWO] = 18 + championship_fixture.team_standings[team_fixture_two] = 18 t_stand = championship_fixture.getTeamStandings() assert isinstance(t_stand, list) @@ -210,7 +224,37 @@ def test_getTeamStandings(championship_fixture: Championship, team_fixture: Team # holdRace test cases -def test_holdRace(championship_fixture: Championship, race_fixture: Race): +def test_holdRace(championship_fixture: Championship, driver_fixture: Driver, driver_fixture_two: Driver, race_fixture: Race, team_fixture: Team, team_fixture_two: Team): assert isinstance(championship_fixture, Championship) + assert isinstance(driver_fixture, Driver) + assert isinstance(driver_fixture_two, Driver) + assert isinstance(team_fixture, Team) + assert isinstance(team_fixture_two, Team) + + team_fixture.addDriverToTeam(driver = driver_fixture) + championship_fixture.addTeamToChampionship(team = team_fixture) + + team_fixture_two.addDriverToTeam(driver = driver_fixture_two) + championship_fixture.addTeamToChampionship(team = team_fixture_two) + + dummy_race_results = RaceResults( + race = race_fixture, + rankings = [driver_fixture, driver_fixture_two], + fastestLap = driver_fixture + ) + + championship_fixture.holdRace(race_results = dummy_race_results) + + d_stand = championship_fixture.getDriverStandings() + t_stand = championship_fixture.getTeamStandings() + + assert isinstance(d_stand, list) + assert isinstance(t_stand, list) + assert len(d_stand) == 2 + assert len(t_stand) == 2 + + assert d_stand[0] == f"1: {driver_fixture.__str__()} (26 points)" + assert d_stand[1] == f"2: {driver_fixture_two.__str__()} (18 points)" - pass # TODO \ No newline at end of file + assert t_stand[0] == f"1: {team_fixture.name} (26 points)" + assert t_stand[1] == f"2: {team_fixture_two.name} (18 points)" \ No newline at end of file diff --git a/tests/test_raceResults.py b/tests/test_raceResults.py index 5142878..74eaaff 100644 --- a/tests/test_raceResults.py +++ b/tests/test_raceResults.py @@ -4,7 +4,7 @@ from src.race.race import Race from src.race.raceResults import RaceResults from src.team.team import Team -from tests.dummy_data import DUMMY_DRIVER, DUMMY_DRIVER_TWO, DUMMY_RACE, DUMMY_RACE_RESULTS, DUMMY_TEAM +from tests.dummy_data import DUMMY_DRIVER, DUMMY_DRIVER_TWO, DUMMY_RACE, DUMMY_TEAM, DUMMY_TEAM_TWO # Fixtures @@ -12,6 +12,10 @@ def driver_fixture(): return deepcopy(DUMMY_DRIVER) +@pytest.fixture +def driver_fixture_two(): + return deepcopy(DUMMY_DRIVER_TWO) + @pytest.fixture def race_fixture(): return deepcopy(DUMMY_RACE) @@ -20,6 +24,10 @@ def race_fixture(): def team_fixture(): return deepcopy(DUMMY_TEAM) +@pytest.fixture +def team_fixture_two(): + return deepcopy(DUMMY_TEAM_TWO) + # Test Cases # TODO \ No newline at end of file From c6f16d106187deb5be5d3ff17f779fdec6165436 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Sat, 10 Jun 2023 11:18:39 -0700 Subject: [PATCH 68/72] cleanup --- tests/test_championship.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test_championship.py b/tests/test_championship.py index 9a0aded..dd72032 100644 --- a/tests/test_championship.py +++ b/tests/test_championship.py @@ -25,10 +25,6 @@ def driver_fixture_two(): def race_fixture(): return deepcopy(DUMMY_RACE) -@pytest.fixture -def race_results_fixture(): - return deepcopy(DUMMY_RACE_RESULTS) - @pytest.fixture def team_fixture(): return deepcopy(DUMMY_TEAM) From b1117d1cef5e2179de6c6709662f86422dcdb461 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Sat, 10 Jun 2023 12:37:21 -0700 Subject: [PATCH 69/72] complete project --- src/race/raceResults.py | 2 +- tests/test_raceResults.py | 33 --------------------------------- 2 files changed, 1 insertion(+), 34 deletions(-) delete mode 100644 tests/test_raceResults.py diff --git a/src/race/raceResults.py b/src/race/raceResults.py index 5139b97..d9e1025 100644 --- a/src/race/raceResults.py +++ b/src/race/raceResults.py @@ -50,7 +50,7 @@ def getPointsForDriver(self, driver: Driver) -> int: """ if not isinstance(driver, Driver): raise TypeError(f"{driver} must be of type Driver, not {type(driver)}") - + return self.results[driver] def getPointsForTeam(self, team: Team) -> int: diff --git a/tests/test_raceResults.py b/tests/test_raceResults.py deleted file mode 100644 index 74eaaff..0000000 --- a/tests/test_raceResults.py +++ /dev/null @@ -1,33 +0,0 @@ -from copy import deepcopy -import pytest -from src.driver.driver import Driver -from src.race.race import Race -from src.race.raceResults import RaceResults -from src.team.team import Team -from tests.dummy_data import DUMMY_DRIVER, DUMMY_DRIVER_TWO, DUMMY_RACE, DUMMY_TEAM, DUMMY_TEAM_TWO - -# Fixtures - -@pytest.fixture -def driver_fixture(): - return deepcopy(DUMMY_DRIVER) - -@pytest.fixture -def driver_fixture_two(): - return deepcopy(DUMMY_DRIVER_TWO) - -@pytest.fixture -def race_fixture(): - return deepcopy(DUMMY_RACE) - -@pytest.fixture -def team_fixture(): - return deepcopy(DUMMY_TEAM) - -@pytest.fixture -def team_fixture_two(): - return deepcopy(DUMMY_TEAM_TWO) - -# Test Cases - -# TODO \ No newline at end of file From aeb818faf3fadb7ead8e52cc19515c756e179ae9 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Sat, 10 Jun 2023 12:46:40 -0700 Subject: [PATCH 70/72] added in race results --- main.py | 22 +++++++++++----------- src/race/race.py | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index e4f0bbc..50c7f42 100644 --- a/main.py +++ b/main.py @@ -163,8 +163,8 @@ def main(): formula_one_2023.holdRace( RaceResults( race = australian_gp, - rankings = None, # TODO - fastestLap = None # TODO + rankings = [ver, ham, alo, stroll, per, nor, hul, pia, zho, tsu, bot, sai, gas, oco, dev, sar, mag, rus, alb, lec], + fastestLap = per ) ) @@ -180,8 +180,8 @@ def main(): formula_one_2023.holdRace( RaceResults( race = azerbaijan_gp, - rankings = None, # TODO - fastestLap = None # TODO + rankings = [per, ver, lec, alo, sai, ham, stroll, rus, nor, tsu, pia, alb, mag, gas, oco, sar, hul, bot, zho, dev], + fastestLap = rus ) ) @@ -197,8 +197,8 @@ def main(): formula_one_2023.holdRace( RaceResults( race = miami_gp, - rankings = None, # TODO - fastestLap = None # TODO + rankings = [ver, per, alo, rus, sai, ham, lec, gas, oco, mag, tsu, stroll, bot, alb, hul, zho, nor, dev, pia, sar], + fastestLap = ver ) ) @@ -214,8 +214,8 @@ def main(): formula_one_2023.holdRace( RaceResults( race = monaco_gp, - rankings = None, # TODO - fastestLap = None # TODO + rankings = [ver, alo, oco, ham, rus, lec, gas, sai, nor, pia, bot, dev, zho, alb, tsu, per, hul, sar, mag, stroll], + fastestLap = ham ) ) @@ -231,8 +231,8 @@ def main(): formula_one_2023.holdRace( RaceResults( race = spanish_gp, - rankings = None, # TODO - fastestLap = None # TODO + rankings = [ver, ham, rus, per, sai, stroll, alo, oco, zho, gas, lec, tsu, pia, dev, hul, alb, nor, mag, bot, sar], + fastestLap = ver ) ) @@ -252,7 +252,7 @@ def main(): circuit = "Red Bull Ring" ) - # TODO add the rest of the future races for 2023 + # TODO add the rest of the future races for 2023 (stretch goal) # print current standings to the console diff --git a/src/race/race.py b/src/race/race.py index 99d293d..22b76fd 100644 --- a/src/race/race.py +++ b/src/race/race.py @@ -2,7 +2,7 @@ class Race(): """ - TODO + a class to represent a race """ def __init__(self, name: str, country: str, city: str, circuit: str): if not isinstance(name, str): From 2ac8e11a934a73b5c2e28de6a1e703e41c0f7366 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Sat, 10 Jun 2023 13:24:51 -0700 Subject: [PATCH 71/72] updated to include the sprint race --- main.py | 221 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 115 insertions(+), 106 deletions(-) diff --git a/main.py b/main.py index 50c7f42..b83195a 100644 --- a/main.py +++ b/main.py @@ -40,77 +40,70 @@ def main(): # create teams using TeamFactory - formula_one_2023.addTeamToChampionship( - TeamFactory.createTeamFerrariEngine( - name = "Alfa Romeo", - country = "Switzerland", - drivers = [bot, zho] - ) + alfa_romeo = TeamFactory.createTeamFerrariEngine( + name = "Alfa Romeo", + country = "Switzerland", + drivers = [bot, zho] ) - formula_one_2023.addTeamToChampionship( - TeamFactory.createTeamHondaRBPTEngine( - name = "AlphaTauri", - country = "Italy", - drivers = [dev, tsu] - ) + alphatauri = TeamFactory.createTeamHondaRBPTEngine( + name = "AlphaTauri", + country = "Italy", + drivers = [dev, tsu] ) - formula_one_2023.addTeamToChampionship( - TeamFactory.createTeamRenaultEngine( - name = "Alpine", - country = "France", - drivers = [gas, oco] - ) + alpine = TeamFactory.createTeamRenaultEngine( + name = "Alpine", + country = "France", + drivers = [gas, oco] ) - formula_one_2023.addTeamToChampionship( - TeamFactory.createTeamMercedesEngine( - name = "Aston Martin", - country = "United Kingdom", - drivers = [alo, stroll] - ) + aston_martin = TeamFactory.createTeamMercedesEngine( + name = "Aston Martin", + country = "United Kingdom", + drivers = [alo, stroll] ) - formula_one_2023.addTeamToChampionship( - TeamFactory.createTeamFerrariEngine( - name = "Ferrari", # this is my second favorite team. They are terrible at strategy and there are multiple memes about how bad their strategy is - country = "Italy", - drivers = [lec, sai] - ) + ferrari = TeamFactory.createTeamFerrariEngine( + name = "Ferrari", # this is my second favorite team. They are terrible at strategy and there are multiple memes about how bad their strategy is + country = "Italy", + drivers = [lec, sai] ) - formula_one_2023.addTeamToChampionship( - TeamFactory.createTeamFerrariEngine( - name = "Haas", - country = "United States", - drivers = [hul, mag] - ) + haas = TeamFactory.createTeamFerrariEngine( + name = "Haas", + country = "United States", + drivers = [hul, mag] ) - formula_one_2023.addTeamToChampionship( - TeamFactory.createTeamMercedesEngine( - name = "McLaren", - country = "United Kingdom", - drivers = [nor, pia] - ) + mclaren = TeamFactory.createTeamMercedesEngine( + name = "McLaren", + country = "United Kingdom", + drivers = [nor, pia] ) - formula_one_2023.addTeamToChampionship( - TeamFactory.createTeamMercedesEngine( - name = "Mercedes", # this is my favorite team - country = "Germany", - drivers = [ham, rus] - ) + mercedes = TeamFactory.createTeamMercedesEngine( + name = "Mercedes", # this is my favorite team + country = "Germany", + drivers = [ham, rus] ) - formula_one_2023.addTeamToChampionship( - TeamFactory.createTeamHondaRBPTEngine( - name = "Red Bull", # you're not going to believe this, but Red Bull is actually a better team right now than Ferrari - country = "Austria", - drivers = [per, ver] - ) + red_bull = TeamFactory.createTeamHondaRBPTEngine( + name = "Red Bull", # you're not going to believe this, but Red Bull is actually a better team right now than Ferrari + country = "Austria", + drivers = [per, ver] ) - formula_one_2023.addTeamToChampionship( - TeamFactory.createTeamMercedesEngine( - name = "Williams", - country = "United Kingdom", - drivers = [alb, sar] - ) + williams = TeamFactory.createTeamMercedesEngine( + name = "Williams", + country = "United Kingdom", + drivers = [alb, sar] ) + # add teams to championship + + formula_one_2023.addTeamToChampionship(team = alfa_romeo) + formula_one_2023.addTeamToChampionship(team = alphatauri) + formula_one_2023.addTeamToChampionship(team = alpine) + formula_one_2023.addTeamToChampionship(team = aston_martin) + formula_one_2023.addTeamToChampionship(team = ferrari) + formula_one_2023.addTeamToChampionship(team = haas) + formula_one_2023.addTeamToChampionship(team = mclaren) + formula_one_2023.addTeamToChampionship(team = mercedes) + formula_one_2023.addTeamToChampionship(team = red_bull) + formula_one_2023.addTeamToChampionship(team = williams) + # add races and race results and print info # bahrain grand prix @@ -122,15 +115,15 @@ def main(): circuit = "Bahrain International Circuit" ) print(bahrain_gp.__str__()) - formula_one_2023.holdRace( - RaceResults( - race = bahrain_gp, - rankings = [ - ver, per, alo, sai, ham, stroll, rus, bot, gas, alb, tsu, sar, mag, dev, hul, zho, nor, oco, lec, pia - ], - fastestLap = zho - ) + rr = RaceResults( + race = bahrain_gp, + rankings = [ + ver, per, alo, sai, ham, stroll, rus, bot, gas, alb, tsu, sar, mag, dev, hul, zho, nor, oco, lec, pia + ], + fastestLap = zho ) + formula_one_2023.holdRace(rr) + print(rr.getPointsForDriver(driver = ver)) # saudi arabian grand prix @@ -141,15 +134,14 @@ def main(): circuit = "Jeddah Corniche Circuit" ) print(saudi_gp.__str__()) - formula_one_2023.holdRace( - RaceResults( - race = saudi_gp, - rankings = [ - per, ver, alo, rus, ham, sai, lec, oco, gas, mag, tsu, hul, zho, dev, pia, sar, nor, bot, alb, stroll - ], - fastestLap = ver - ) + rr = RaceResults( + race = saudi_gp, + rankings = [ + per, ver, alo, rus, ham, sai, lec, oco, gas, mag, tsu, hul, zho, dev, pia, sar, nor, bot, alb, stroll + ], + fastestLap = ver ) + formula_one_2023.holdRace(rr) # australian grand prix @@ -160,13 +152,30 @@ def main(): circuit = "Albert Park Circuit" ) print(australian_gp.__str__()) - formula_one_2023.holdRace( - RaceResults( - race = australian_gp, - rankings = [ver, ham, alo, stroll, per, nor, hul, pia, zho, tsu, bot, sai, gas, oco, dev, sar, mag, rus, alb, lec], - fastestLap = per - ) + rr = RaceResults( + race = australian_gp, + rankings = [ver, ham, alo, stroll, per, nor, hul, pia, zho, tsu, bot, sai, gas, oco, dev, sar, mag, rus, alb, lec], + fastestLap = per ) + formula_one_2023.holdRace(rr) + print(rr.getPointsForDriver(driver = ver)) + + # azerbaijan sprint race + + # manually update standings with azerbaijan sprint race results + formula_one_2023.driver_standings[per] += 8 + formula_one_2023.driver_standings[lec] += 7 + formula_one_2023.driver_standings[ver] += 6 + formula_one_2023.driver_standings[rus] += 5 + formula_one_2023.driver_standings[sai] += 4 + formula_one_2023.driver_standings[alo] += 3 + formula_one_2023.driver_standings[ham] += 2 + formula_one_2023.driver_standings[stroll] += 1 + + formula_one_2023.team_standings[aston_martin] += 4 + formula_one_2023.team_standings[ferrari] += 11 + formula_one_2023.team_standings[mercedes] += 7 + formula_one_2023.team_standings[red_bull] += 14 # azerbaijan grand prix @@ -177,13 +186,13 @@ def main(): circuit = "Baku City Circuit" ) print(azerbaijan_gp.__str__()) - formula_one_2023.holdRace( - RaceResults( - race = azerbaijan_gp, - rankings = [per, ver, lec, alo, sai, ham, stroll, rus, nor, tsu, pia, alb, mag, gas, oco, sar, hul, bot, zho, dev], - fastestLap = rus - ) + rr = RaceResults( + race = azerbaijan_gp, + rankings = [per, ver, lec, alo, sai, ham, stroll, rus, nor, tsu, pia, alb, mag, gas, oco, sar, hul, bot, zho, dev], + fastestLap = rus ) + formula_one_2023.holdRace(rr) + print(rr.getPointsForDriver(driver = ver)) # miami grand prix @@ -194,13 +203,13 @@ def main(): circuit = "Miami International Autodrome" ) print(miami_gp.__str__()) - formula_one_2023.holdRace( - RaceResults( - race = miami_gp, - rankings = [ver, per, alo, rus, sai, ham, lec, gas, oco, mag, tsu, stroll, bot, alb, hul, zho, nor, dev, pia, sar], - fastestLap = ver - ) + rr = RaceResults( + race = miami_gp, + rankings = [ver, per, alo, rus, sai, ham, lec, gas, oco, mag, tsu, stroll, bot, alb, hul, zho, nor, dev, pia, sar], + fastestLap = ver ) + formula_one_2023.holdRace(rr) + print(rr.getPointsForDriver(driver = ver)) # monaco grand prix @@ -211,13 +220,13 @@ def main(): circuit = "Circuit de Monaco" ) print(monaco_gp.__str__()) - formula_one_2023.holdRace( - RaceResults( - race = monaco_gp, - rankings = [ver, alo, oco, ham, rus, lec, gas, sai, nor, pia, bot, dev, zho, alb, tsu, per, hul, sar, mag, stroll], - fastestLap = ham - ) + rr = RaceResults( + race = monaco_gp, + rankings = [ver, alo, oco, ham, rus, lec, gas, sai, nor, pia, bot, dev, zho, alb, tsu, per, hul, sar, mag, stroll], + fastestLap = ham ) + formula_one_2023.holdRace(rr) + print(rr.getPointsForDriver(driver = ver)) # spanish grand prix @@ -228,13 +237,13 @@ def main(): circuit = "Circuit de Barcelona-Catalunya" ) print(spanish_gp.__str__()) - formula_one_2023.holdRace( - RaceResults( - race = spanish_gp, - rankings = [ver, ham, rus, per, sai, stroll, alo, oco, zho, gas, lec, tsu, pia, dev, hul, alb, nor, mag, bot, sar], - fastestLap = ver - ) + rr = RaceResults( + race = spanish_gp, + rankings = [ver, ham, rus, per, sai, stroll, alo, oco, zho, gas, lec, tsu, pia, dev, hul, alb, nor, mag, bot, sar], + fastestLap = ver ) + formula_one_2023.holdRace(rr) + print(rr.getPointsForDriver(driver = ver)) # future races for the 2023 season From 6f91b0a046944850975da1a104b90c47114e85f5 Mon Sep 17 00:00:00 2001 From: Sam Platt Date: Sat, 10 Jun 2023 13:25:54 -0700 Subject: [PATCH 72/72] sprint race standings included --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index b83195a..37c8efa 100644 --- a/main.py +++ b/main.py @@ -163,6 +163,7 @@ def main(): # azerbaijan sprint race # manually update standings with azerbaijan sprint race results + formula_one_2023.driver_standings[per] += 8 formula_one_2023.driver_standings[lec] += 7 formula_one_2023.driver_standings[ver] += 6