示例#1
0
    def test_addition_inverse(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)

        assert -a == Quaternion(-1, -2, -3, -4)
        assert a + -b == a - b
        assert a + +b == a + b
示例#2
0
    def test_multiplication_commutativity(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)
        c = 5
        d = 5.0

        assert a * b == b * a
        assert a * c == c * a
        assert a * d == d * a
示例#3
0
    def test_addition_commutativity(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)
        c = 5
        d = 5.0

        assert a + b == b + a
        assert a + c == c + a
        assert a + d == d + a
示例#4
0
    def test_addition_associativity(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)
        c = Quaternion(3, 4, 5, 6)
        d = 5
        e = 6
        f = 5.0
        g = 6.0

        assert b + (a + c) == (b + a) + c
        assert d + (a + e) == (d + a) + e
        assert f + (a + g) == (f + a) + g
示例#5
0
    def test_multiplication_associativity(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)
        c = Quaternion(3, 4, 5, 6)
        d = 5
        e = 6
        f = 5.0
        g = 6.0

        assert b * (a * c) == (b * a) * c
        assert d * (a * e) == (d * a) * e
        assert f * (a * g) == (f * a) * g
示例#6
0
    def test_multiplication_inverse(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)

        assert all_close(
            Quaternion(1, 1, 1, 1) / a,
            Quaternion(1 / a.qi, 1 / a.qj, 1 / a.qk, 1 / a.qr))
        assert all_close(1 / a,
                         Quaternion(1 / a.qi, 1 / a.qj, 1 / a.qk, 1 / a.qr))
        assert all_close(1.0 / a,
                         Quaternion(1 / a.qi, 1 / a.qj, 1 / a.qk, 1 / a.qr))
        assert all_close(a * (Quaternion(1, 1, 1, 1) / b), a / b)
        assert all_close(a * (1 / b), a / b)
        assert all_close(a * (1.0 / b), a / b)
示例#7
0
    def test_quaternion_product_associativity(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)
        c = Quaternion(3, 4, 5, 6)

        assert b @ (a @ c) == (b @ a) @ c
示例#8
0
    def test_quaternion_product_inverse(self):
        a = Quaternion(2, 2, 2, 2)
        b = a.inverse()

        assert a @ b == Quaternion()
        assert b @ a == Quaternion()
示例#9
0
    def test_quaternion_product_neutral_element(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion()

        assert a @ b == a
        assert a @ b == b @ a
示例#10
0
    def test_distributivity(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)
        c = Quaternion(3, 4, 5, 6)

        assert a * (b + c) == a * b + a * c
示例#11
0
 def test_conjugate(self):
     assert Quaternion(1, 2, 3, 4).t == Quaternion(-1, -2, -3, 4)
示例#12
0
 def test_properties(self):
     a = Quaternion(1, 2, 3, 4)
     assert a.qi == 1
     assert a.qj == 2
     assert a.qk == 3
     assert a.qr == 4
示例#13
0
    def test_multiplication_neutral_element(self):
        a = Quaternion(1, 2, 3, 4)

        assert a * Quaternion(1, 1, 1, 1) == a
        assert a * 1 == a
        assert a * 1.0 == a
示例#14
0
 def test_matrix(self):
     assert Quaternion().matrix == Matrix.identity(4)
示例#15
0
    def test_quaternion_distributivity(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)
        c = Quaternion(3, 4, 5, 6)

        assert a @ (b + c) == a @ b + a @ c
示例#16
0
    def test_addition_neutral_element(self):
        a = Quaternion(1, 2, 3, 4)

        assert a + Quaternion(0, 0, 0, 0) == a
        assert a + 0 == a
        assert a + 0.0 == a
示例#17
0
    def test_slerp(self):
        a = Quaternion(1, 0, 0, 1)
        b = Quaternion(0, 1, 0, 1)

        assert Quaternion.slerp(a, b, 0.0) == a / a.norm()
        assert Quaternion.slerp(a, b, 1.0) == b / b.norm()
示例#18
0
    def test_transform(self):
        a = Quaternion(0, 0, 0, 1)
        b = Matrix((4, 1), (1, 2, 3, 4))

        assert a.transform(b) == b
示例#19
0
 def test_norm(self):
     assert Quaternion().norm() == 1
     assert Quaternion(1, 1, 1, 1).norm() == 2
示例#20
0
 def test_equality(self):
     assert Quaternion() == Quaternion()
     assert Quaternion(1, 2, 3, 4) == Quaternion(1, 2, 3, 4)
示例#21
0
    def test_quaternion_vectors(self):
        a = Quaternion(0, 0, 0, 1)
        b = Matrix((4, 1), (1, 2, 3, 4))

        assert a @ b @ a.inverse() == Quaternion(1, 2, 3, 4)
示例#22
0
 def test_instantiation(self):
     Quaternion()
     Quaternion(qi=0, qj=0, qk=0, qr=1, data_type="f")