def test_divide_float(self): assert Vector(2.14, 8.23) / -0.1 == Vector(-21.4, -82.3)
def test_init_ints(self): Vector(-2, 4)
def test_divide_int(self): assert Vector(2, -4) / -2 == Vector(-1, 2)
def test_add(self): assert A + B == Particle(2, Vector(0, 5))
def test_two_body_force(self): g = 1 assert A.two_body_force(B, g) == Vector(0, g * 1 / 100) assert B.two_body_force(A, g) == Vector(0, g * -1 / 100)
def test_multiply_bad_type(self): with pytest.raises(TypeError): Vector(2, -3.1) / (3 - 2j) with pytest.raises(TypeError): Vector(2, -3.1) / 'lel'
from dust.vector import Vector from dust.particle import Particle A = Particle(1, Vector(0, 0)) B = Particle(1, Vector(0, 10)) C = Particle(3, Vector(5, 2)) D = Particle(1, Vector(0, 0)) class TestParticle: def test_centre_of_mass(self): assert A.centre_of_mass(B) == Vector(0, 5) def test_add(self): assert A + B == Particle(2, Vector(0, 5)) def test_sum(self): assert sum([A, B]) == A + B def test_sub(self): assert (A + B) - B == A def test_neg(self): assert (-A) == Particle(-1, Vector(0, 0)) assert (-B) == Particle(-1, Vector(0, 10)) assert - Particle(2.5, Vector(0.2, 93.5), Vector(34.1, -52.1)) \ == Particle(-2.5, Vector(0.2, 93.5), Vector(-34.1, 52.1)) def test_mod(self): assert A % A assert B % B
def test_add_floats(self): assert Vector(2.245, -4.634) + Vector(23.420, -12.528) \ == Vector(25.665, -17.162)
def test_sum(self): assert sum([Vector(2.245, -4.634), Vector(23.420, -12.528)]) \ == Vector(25.665, -17.162)
def test_init_string(self): with pytest.raises(TypeError): Vector('hello', 'world')
def test_add_ints(self): assert Vector(-1, 4) + Vector(3, -6) == Vector(2, -2)
def test_init_complex(self): with pytest.raises(TypeError): Vector(2 + 1j, -4.6345 + 2.9521j)
def test_init_mixed(self): Vector(2, -4.6345)
def test_init_floats(self): Vector(2.245, -4.6345)
def test_divide_by_zero(self): assert Vector(2.14, 8.23) / 0 == Vector(0, 0)
def test_iter_sum(self): s = Vector(0, 0) for v in [Vector(2.245, -4.634), Vector(23.420, -12.528)]: s += v assert s == Vector(25.665, -17.162)
def test_divide_wrong_order(self): with pytest.raises(TypeError): 1.3 / Vector(2.21, 4.51)
def test_multiply_scalar(self): assert 2 * Vector(-2, 4) == Vector(-4, 8) assert Vector(2, -4) * -2 == Vector(-4, 8)
def test_unit_vector(): assert A.unit_vector() == Vector(0, 0) assert B.unit_vector() == Vector(1, 0) assert C.unit_vector() == Vector(-1, 0) assert D.unit_vector() == Vector(3 / 5, 4 / 5)
def test_multiply_float(self): assert 0.1 * Vector(-2.14, -8.23) == Vector(-0.214, -0.823) assert Vector(2.14, 8.23) * -0.1 == Vector(-0.214, -0.823)
def test_centre_of_mass(self): assert A.centre_of_mass(B) == Vector(0, 5)
def test_multiply_by_zero(self): assert 0 * Vector(2, 4) == Vector(0, 0) assert Vector(2.14, -8.23) * 0 == Vector(0, 0)
def test_neg(self): assert (-A) == Particle(-1, Vector(0, 0)) assert (-B) == Particle(-1, Vector(0, 10)) assert - Particle(2.5, Vector(0.2, 93.5), Vector(34.1, -52.1)) \ == Particle(-2.5, Vector(0.2, 93.5), Vector(-34.1, 52.1))
def test_multiply_bad_type(self): with pytest.raises(TypeError): (3 - 2j) * Vector(2, -3.1) with pytest.raises(TypeError): 'test' * Vector(2, -3.1)
def test_two_body_amomentum(self): b = B b.momentum = Vector(5, 0) assert A.two_body_amomentum(b) == -50 assert b.two_body_amomentum(A) == -50
import pytest from dust.vector import Vector A = Vector(0, 0) B = Vector(5, 0) C = Vector(-3.14, 0) D = Vector(3, 4) class TestInit: def test_init_ints(self): Vector(-2, 4) def test_init_floats(self): Vector(2.245, -4.6345) def test_init_mixed(self): Vector(2, -4.6345) def test_init_complex(self): with pytest.raises(TypeError): Vector(2 + 1j, -4.6345 + 2.9521j) def test_init_string(self): with pytest.raises(TypeError): Vector('hello', 'world') class TestAdd: def test_add_ints(self):