Ejemplo n.º 1
0
    def test_chaining_valid_operations(self):
        a = Vector(1, 2, 3)
        b = Vector(1, 2, 3)

        # chain addition and subtraction
        chain1 = a + b - a + b

        chain1_expected_result = Vector(2, 4, 6)
        self.assertEqual(chain1_expected_result, chain1)

        # chain scalar multiplication and dot product
        chain2 = a * b * 5 * a

        chain2_expected_result = Vector(70, 140, 210)
        self.assertEqual(chain2_expected_result, chain2)

        # chain dot product, scalar multiplication, reversal
        chain3 = (a * b * 5 * a).smul(0.5).reversed()

        chain3_expected_result = Vector(-35, -70, -105)
        self.assertEqual(chain3_expected_result, chain3)

        # chain cross product, vector addition,
        # vector subtraction, scalar multiplication
        a = Vector(3, -3, 1)
        b = Vector(4, 9, 2)

        chain4 = a.crossmul(b).smul(-1).subtract(b).add(a)

        chain4_expected_result = Vector(14, -10, -40)
        self.assertEqual(chain4_expected_result, chain4)
Ejemplo n.º 2
0
    def test_cross_product(self):
        a = Vector(3, -3, 1)
        b = Vector(4, 9, 2)
        expected_cross_product = Vector(-15, -2, 39)

        self.assertEqual(expected_cross_product, a.crossmul(b))