Correction petit bugs

tests
Allan Point 3 years ago
parent fdc701b423
commit d907d9766d

@ -1,6 +1,6 @@
#coding:utf-8
import statistics
import custom_exception
from custom_exception.nothing_to_compare_error import *
class Boat:
def __init__(self, boat_id: str, name: str, sismer_id: str, url: str, avatar:str , temperatures: list, positions: list):
@ -13,15 +13,21 @@ class Boat:
self.positions = positions
def __str__(self):
return f"{self.name}"
def __eq__(self, other):
if other is None:
return False
if not isinstance(other, self.__class__):
return False
return self.boat_id == other.boat_id
def get_temp_mean(self):
return statistics.mean(self.temperatures)
def get_northiest_coords(self):
if len(self.positions) == 0:
raise custom_exception.NothingToComapreError(f"{self.name} must have coords to compare")
raise NothingToCompareError(f"{self.name} must have coords to compare")
best = self.positions[0]
for position in self.positions:
if position.is_northiest_than(best):
if position.is_norther_than(best):
best = position
return best

@ -25,8 +25,16 @@ class Fleet:
return best_boat, best_element_to_compare
def get_northiest(self):
return self.compare_boats(Boat.get_northiest_coords, Position.is_northiest_than)
try:
return self.compare_boats(Boat.get_northiest_coords, Position.is_norther_than)
except TypeError as e:
print(e)
return;
def get_highiest_heat_mean(self):
try:
return self.compare_boats(Boat.get_temp_mean, float.__ge__)
except TypeError as e:
print(e)
return;

@ -7,7 +7,14 @@ class Position:
def __str__(self):
return f"[{self.latitude}; {self.longitude}]"
def is_northiest_than(self, position):
def is_norther_than(self, position):
if position == None:
return True
return self.latitude >= position.latitude
def __eq__(self, other):
if other is None:
return False
if not isinstance(other, self.__class__):
return False
return self.longitude == other.longitude and self.latitude == other.latitude

Loading…
Cancel
Save