added more tests for double elimination and seeding
added eq and nq functions for Position class in de fixed error in de function that would occur if the game has not started yet
This commit is contained in:
parent
c325a2c7c2
commit
f6b27971c4
3 changed files with 88 additions and 12 deletions
|
@ -44,11 +44,19 @@ class Position:
|
|||
self.degrees = degrees
|
||||
|
||||
def __repr__(self):
|
||||
return "{x=%s, y=%s, degrees=%s}" % self.x, self.y, self.degrees
|
||||
return "{x=%s, y=%s, degrees=%s}" % (self.x, self.y, self.degrees)
|
||||
|
||||
def __str__(self):
|
||||
return f"Position(x={round(self.x, 5)}, y={round(self.y, 5)}, degrees={round(self.degrees, 5)})"
|
||||
|
||||
def __eq__(self, o: object) -> bool:
|
||||
if isinstance(o, Position):
|
||||
return self.x == o.x and self.y == o.y and self.degrees == o.degrees
|
||||
return False
|
||||
|
||||
def __ne__(self, o: object) -> bool:
|
||||
return not self.__eq__(o)
|
||||
|
||||
@staticmethod
|
||||
def position_from_json(json_str: Dict):
|
||||
return Position(json_str["x"], json_str["y"], json_str["degrees"])
|
||||
|
@ -59,7 +67,7 @@ class DoubleElim:
|
|||
"""
|
||||
|
||||
@staticmethod
|
||||
def get_position() -> Tuple[Position, int]:
|
||||
def get_pos() -> Tuple[Position, int]:
|
||||
"""Makes the /api/getPos call to the api.
|
||||
:return: A Position object with robot position
|
||||
:rtype: Tuple[Position, int]
|
||||
|
@ -68,7 +76,9 @@ class DoubleElim:
|
|||
if res.status_code == 408:
|
||||
logger.error(f"DoubleElim.get_position timeout. API={API_URL_GET_POS}")
|
||||
time.sleep(RETRY_TIMEOUT)
|
||||
return DoubleElim.get_position()
|
||||
return DoubleElim.get_pos()
|
||||
elif res.status_code == 503:
|
||||
return Position(0, 0, -1), 503
|
||||
|
||||
response = json.loads(res.content)
|
||||
logger.debug(f"DoubleElim.get_position = {response}, status code = {res.status_code}")
|
||||
|
@ -85,6 +95,8 @@ class DoubleElim:
|
|||
logger.error(f"DoubleElim.get_opponent timeout. API={API_URL_GET_OP}")
|
||||
time.sleep(RETRY_TIMEOUT)
|
||||
return DoubleElim.get_opponent()
|
||||
elif res.status_code == 503:
|
||||
return Position(0, 0, -1), 503
|
||||
|
||||
response = json.loads(res.content)
|
||||
logger.debug(f"DoubleElim.get_opponent = x:{response}, status code = {res.status_code}")
|
||||
|
@ -101,6 +113,8 @@ class DoubleElim:
|
|||
logger.error(f"DoubleElim.get_goal timeout. API={API_URL_GET_GOAL}")
|
||||
time.sleep(RETRY_TIMEOUT)
|
||||
return DoubleElim.get_goal()
|
||||
elif res.status_code == 503:
|
||||
return Position(0, 0, -1), 503
|
||||
|
||||
response = json.loads(res.content)
|
||||
logger.debug(f"DoubleElim.get_goal = {response}, status code = {res.status_code}")
|
||||
|
|
Reference in a new issue