def read(self): '''returns velocity vector object''' try: return Velocity(x=self._get_x(), y=self._get_y()) except TypeError as e: raise CorruptedSaveError(e) except FasterThanLightError as e: raise CorruptedSaveError(e)
def _velocity_input(): print(4 * ' ' + 'Type in values of the velocity vector: ') try: x = _number_input(8 * ' ' + 'x value: ') y = _number_input(8 * ' ' + 'y value: ') return Velocity(x, y) except (ValueError, TypeError, FasterThanLightError, InputError) as e: print(e) return _velocity_input()
def __init__(self, mass=Mass(earth_mass), radius=Radius(earth_radius), position=Position(0, 0)): super().__init__(position, Velocity(0, 0), mass, radius) if self.schwarzschild_radius() > self._radius: raise TooSmallRadiusError( f'Miniman radius can be {self.schwarzschild_radius()}')
def test_update_position(): p_obj_1 = PointObject(Position(0, 0), Velocity(0, 0)) p_obj_2 = PointObject(Position(0, 0), Velocity(10, 10)) p_obj_3 = PointObject(Position(0, 0), Velocity(-10, -10)) p_obj_1.update_position(0) assert p_obj_1._position == Position(0, 0) p_obj_1.update_position(5) assert p_obj_1._position == Position(0, 0) p_obj_2.update_position(1) assert p_obj_2._position == Position(10, 10) p_obj_2.update_position(5) assert p_obj_2._position == Position(60, 60) p_obj_3.update_position(2) assert p_obj_3._position == Position(-20, -20)
def __init__(self, position=Position(0, 0), velocity=Velocity(0, 0)): super().__init__(position, velocity, 0, 0) PointObject.num_pointobjects += 1
def test_velocity_reader(): velocity_0 = VelocityReader(json.loads(save), 0).read() velocity_1 = VelocityReader(json.loads(save), 1).read() assert velocity_0 == Velocity(7540, 0) assert velocity_1 == Velocity(-4540, 0)
def test_type_error(): with pytest.raises(TypeError): Velocity('a', 1) Position('b', 'da')
def test_faster_than_light_error(): with pytest.raises(FasterThanLightError): Velocity(3 * 10**8, 0)
from physic_vectors import Velocity, Position, FasterThanLightError import pytest v2 = Velocity(12, 16) v3 = Velocity(0, 0) v4 = Velocity(-3, -4) def test_type_error(): with pytest.raises(TypeError): Velocity('a', 1) Position('b', 'da') def test_faster_than_light_error(): with pytest.raises(FasterThanLightError): Velocity(3 * 10**8, 0)