Exemplo n.º 1
0
 def test_divide_float(self):
     assert Vector(2.14, 8.23) / -0.1 == Vector(-21.4, -82.3)
Exemplo n.º 2
0
 def test_init_ints(self):
     Vector(-2, 4)
Exemplo n.º 3
0
 def test_divide_int(self):
     assert Vector(2, -4) / -2 == Vector(-1, 2)
Exemplo n.º 4
0
 def test_add(self):
     assert A + B == Particle(2, Vector(0, 5))
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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'
Exemplo n.º 7
0
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
Exemplo n.º 8
0
 def test_add_floats(self):
     assert Vector(2.245, -4.634) + Vector(23.420, -12.528) \
                                 == Vector(25.665, -17.162)
Exemplo n.º 9
0
 def test_sum(self):
     assert sum([Vector(2.245, -4.634), Vector(23.420, -12.528)]) \
                                     == Vector(25.665, -17.162)
Exemplo n.º 10
0
 def test_init_string(self):
     with pytest.raises(TypeError):
         Vector('hello', 'world')
Exemplo n.º 11
0
 def test_add_ints(self):
     assert Vector(-1, 4) + Vector(3, -6) == Vector(2, -2)
Exemplo n.º 12
0
 def test_init_complex(self):
     with pytest.raises(TypeError):
         Vector(2 + 1j, -4.6345 + 2.9521j)
Exemplo n.º 13
0
 def test_init_mixed(self):
     Vector(2, -4.6345)
Exemplo n.º 14
0
 def test_init_floats(self):
     Vector(2.245, -4.6345)
Exemplo n.º 15
0
 def test_divide_by_zero(self):
     assert Vector(2.14, 8.23) / 0 == Vector(0, 0)
Exemplo n.º 16
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)
Exemplo n.º 17
0
 def test_divide_wrong_order(self):
     with pytest.raises(TypeError):
         1.3 / Vector(2.21, 4.51)
Exemplo n.º 18
0
 def test_multiply_scalar(self):
     assert 2 * Vector(-2, 4) == Vector(-4, 8)
     assert Vector(2, -4) * -2 == Vector(-4, 8)
Exemplo n.º 19
0
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)
Exemplo n.º 20
0
 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)
Exemplo n.º 21
0
 def test_centre_of_mass(self):
     assert A.centre_of_mass(B) == Vector(0, 5)
Exemplo n.º 22
0
 def test_multiply_by_zero(self):
     assert 0 * Vector(2, 4) == Vector(0, 0)
     assert Vector(2.14, -8.23) * 0 == Vector(0, 0)
Exemplo n.º 23
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))
Exemplo n.º 24
0
 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)
Exemplo n.º 25
0
 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
Exemplo n.º 26
0
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):