def test_update_car_coordinates_when_called_with_same_coords_speed_equals_0( self): car = Car(0, 0, 0, 1) car_coords = { 'timestamp': 1, 'carIndex': 1, 'location': { 'lat': 0, 'long': 0 } } car.update_car_coordinates(car_coords) assert car.curr_speed == 0
def test_update_car_coordinates_when_called_normally_returns_updated_ts( self): car = Car(0, 0, 0, 1) car_coords = { 'timestamp': 3600000, 'carIndex': 1, 'location': { 'lat': 0.01, 'long': 0 } } car.update_car_coordinates(car_coords) assert car.get_car_timestamp() == 3600000
def test_update_car_coordinates_when_called_with_same_ts_distance_equals_0( self): car = Car(0, 0, 0, 1) car_coords = { 'timestamp': 0, 'carIndex': 1, 'location': { 'lat': 1, 'long': 1 } } car.update_car_coordinates(car_coords) assert car.distance_travelled == 0
def test_update_car_coordinates_when_called_normally_returns_correct_distance_travelled( self): car = Car(0, 0, 0, 1) car_coords = { 'timestamp': 3600000, 'carIndex': 1, 'location': { 'lat': 0.01, 'long': 0 } } # Calculated value of this transtion = 0.6870766960504942 car.update_car_coordinates(car_coords) assert car.distance_travelled == 0.6870766960504942
def update_car_info(self, car_coordinates: dict): """Function that updates a car information and throws carStatus events if necessary If the car does not exist, it is build and added to the participants. Receives carCoordinates object """ if CarCoordinates.validate_car_coordinates(car_coordinates): if car_coordinates.get('carIndex') in self.__cars.keys(): car_to_update = self.__cars.get(car_coordinates.get('carIndex')) else: car_to_update = Car(float(car_coordinates.get('location').get('lat')), float(car_coordinates.get('location').get('long')), float(car_coordinates.get('timestamp')), int(car_coordinates.get('carIndex'))) self.__add_car_to_the_race(car_to_update) car_to_update.update_car_coordinates(car_coordinates) self.__assign_position(float(car_coordinates.get('timestamp'))) # Reporting if car_to_update.get_car_position() != 0: self.publish_car_status(car_to_update.generate_position_report()) self.publish_car_status(car_to_update.generate_speed_report()) else: pass
def test_update_car_coordinates_when_called_normally2times_returns_updated_speed( self): car = Car(0, 0, 0, 1) car_coords = { 'timestamp': 3600000, 'carIndex': 1, 'location': { 'lat': 0.01, 'long': 0 } } car.update_car_coordinates(car_coords) car_coords = { 'timestamp': 7200000, 'carIndex': 1, 'location': { 'lat': 0.02, 'long': 0 } } car.update_car_coordinates(car_coords) # Operating with floats, so we round to the 5 more significant digits assert round(car.distance_travelled, 5) == round(2 * 0.6870766960504942, 5)