Ejemplo n.º 1
0
    def test_operators_vector4(self):
        v1 = Vector4()
        v2 = Vector4([1., 2., 3., 4.])

        # add
        self.assertTrue(np.array_equal(v1 + v2, [1., 2., 3., 4.]))

        # subtract
        self.assertTrue(np.array_equal(v1 - v2, [-1., -2., -3., -4]))

        # multiply
        self.assertTrue(np.array_equal(v1 * v2, [0., 0., 0., 0.]))

        # divide
        self.assertTrue(np.array_equal(v1 / v2, [0., 0., 0., 0.]))

        # or
        self.assertTrue(
            np.array_equal(v1 | v2,
                           vector4.dot([0., 0., 0., 0.], [1., 2., 3., 4.])))

        # xor
        #self.assertTrue(np.array_equal(v1 ^ v2, vector4.cross([0.,0.,0.,0.], [1.,2.,3.,4.])))

        # ==
        self.assertTrue(Vector4() == Vector4())
        self.assertFalse(Vector4() == Vector4([1., 1., 1., 1.]))

        # !=
        self.assertTrue(Vector4() != Vector4([1., 1., 1., 1.]))
        self.assertFalse(Vector4() != Vector4())
Ejemplo n.º 2
0
    def test_operators_vector4(self):
        v1 = Vector4()
        v2 = Vector4([1.,2.,3.,4.])

        # add
        self.assertTrue(np.array_equal(v1 + v2, [1.,2.,3.,4.]))

        # subtract
        self.assertTrue(np.array_equal(v1 - v2, [-1.,-2.,-3.,-4]))

        # multiply
        self.assertTrue(np.array_equal(v1 * v2, [0.,0.,0.,0.]))

        # divide
        self.assertTrue(np.array_equal(v1 / v2, [0.,0.,0.,0.]))

        # or
        self.assertTrue(np.array_equal(v1 | v2, vector4.dot([0.,0.,0.,0.], [1.,2.,3.,4.])))

        # xor
        #self.assertTrue(np.array_equal(v1 ^ v2, vector4.cross([0.,0.,0.,0.], [1.,2.,3.,4.])))

        # ==
        self.assertTrue(Vector4() == Vector4())
        self.assertFalse(Vector4() == Vector4([1.,1.,1.,1.]))

        # !=
        self.assertTrue(Vector4() != Vector4([1.,1.,1.,1.]))
        self.assertFalse(Vector4() != Vector4())
Ejemplo n.º 3
0
 def test_dot_batch(self):
     result = vector4.dot([
         [1.,0.,0.,1.],
         [0.,1.,0.,1.],
         [.2,.2,0.,1.]
     ],[
         [0.,1.,0.,1.],
         [0.,1.,0.,1.],
         [2.,-.2,0.,1.]
     ])
     expected = [
         1.,
         2.,
         1.36
     ]
     np.testing.assert_almost_equal(result, expected, decimal=5)
Ejemplo n.º 4
0
 def test_dot_angle(self):
     result = vector4.dot([.2,.2,0.,1.], [2.,-.2,0.,1.])
     np.testing.assert_almost_equal(result, 1.359999, decimal=5)
Ejemplo n.º 5
0
 def test_dot_parallel(self):
     result = vector4.dot([0.,1.,0.,1.], [0.,1.,0.,1.])
     np.testing.assert_almost_equal(result, 2.0, decimal=5)
Ejemplo n.º 6
0
 def test_dot_adjacent(self):
     result = vector4.dot([1.,0.,0.,1.], [0.,1.,0.,1.])
     np.testing.assert_almost_equal(result, 1.0, decimal=5)
Ejemplo n.º 7
0
 def test_dot_batch(self):
     result = vector4.dot(
         [[1., 0., 0., 1.], [0., 1., 0., 1.], [.2, .2, 0., 1.]],
         [[0., 1., 0., 1.], [0., 1., 0., 1.], [2., -.2, 0., 1.]])
     expected = [1., 2., 1.36]
     np.testing.assert_almost_equal(result, expected, decimal=5)
Ejemplo n.º 8
0
 def test_dot_angle(self):
     result = vector4.dot([.2, .2, 0., 1.], [2., -.2, 0., 1.])
     np.testing.assert_almost_equal(result, 1.359999, decimal=5)
Ejemplo n.º 9
0
 def test_dot_parallel(self):
     result = vector4.dot([0., 1., 0., 1.], [0., 1., 0., 1.])
     np.testing.assert_almost_equal(result, 2.0, decimal=5)
Ejemplo n.º 10
0
 def test_dot_adjacent(self):
     result = vector4.dot([1., 0., 0., 1.], [0., 1., 0., 1.])
     np.testing.assert_almost_equal(result, 1.0, decimal=5)
Ejemplo n.º 11
0
    def test_bitwise(self):
        v1 = Vector4([1., 0., 0., 1.])
        v2 = Vector4([0., 1., 0., 1.])

        # or (dot)
        self.assertTrue(np.array_equal(v1 | v2, vector4.dot(v1, v2)))
Ejemplo n.º 12
0
    def test_bitwise(self):
        v1 = Vector4([1.,0.,0.,1.])
        v2 = Vector4([0.,1.,0.,1.])

        # or (dot)
        self.assertTrue(np.array_equal(v1 | v2, vector4.dot(v1, v2)))