Beispiel #1
0
    def test_eq_tuple(self):
        xyz = (1.0, 2.0, 3.0)
        self.assertEqual(eu.Vector3(*xyz), xyz)

        other = (1.0, 2.0, 3.0, 4.0)
        self.assertRaises(AssertionError, lambda a, b: a == b,
                          eu.Vector3(*xyz), other)

        other = 1.0
        self.assertRaises(AssertionError, lambda a, b: a == b,
                          eu.Vector3(*xyz), other)
Beispiel #2
0
    def test_swizzle_get(self):
        xyz = (1.0, 2.0, 3.0)
        v3 = eu.Vector3(*xyz)
        self.assertEqual(v3.x, xyz[0])
        self.assertEqual(v3.y, xyz[1])
        self.assertEqual(v3.z, xyz[2])

        self.assertEqual(v3.xy, (xyz[0], xyz[1]))
        self.assertEqual(v3.xz, (xyz[0], xyz[2]))
        self.assertEqual(v3.yz, (xyz[1], xyz[2]))

        self.assertEqual(v3.yx, (xyz[1], xyz[0]))
        self.assertEqual(v3.zx, (xyz[2], xyz[0]))
        self.assertEqual(v3.zy, (xyz[2], xyz[1]))

        self.assertEqual(v3.xyz, xyz)
        self.assertEqual(v3.xzy, (xyz[0], xyz[2], xyz[1]))
        self.assertEqual(v3.zyx, (xyz[2], xyz[1], xyz[0]))
        self.assertEqual(v3.zxy, (xyz[2], xyz[0], xyz[1]))
        self.assertEqual(v3.yxz, (xyz[1], xyz[0], xyz[2]))
        self.assertEqual(v3.yzx, (xyz[1], xyz[2], xyz[0]))

        exception = None
        try:
            v3.u == 11.0
        except Exception as a:
            exception = a
        assert isinstance(exception, AttributeError)
Beispiel #3
0
 def test_index_access__get(self):
     xyz = (1.0, 2.0, 3.0)
     v3 = eu.Vector3(*xyz)
     self.assertEqual(v3[0], xyz[0])
     self.assertEqual(v3[1], xyz[1])
     self.assertEqual(v3[2], xyz[2])
     self.assertRaises(IndexError, lambda a: v3[a], 3)
Beispiel #4
0
    def test_deepcopy(self):
        xyz = (1.0, 2.0, 3.0)
        v3 = eu.Vector3(*xyz)

        copied = copy.deepcopy(v3)
        self.assertEqual(repr(v3), repr(copied))
        self.assertFalse(copied is v3)
Beispiel #5
0
    def test_copy(self):
        xyz = (1.0, 2.0, 3.0)
        v3 = eu.Vector3(*xyz)

        copied = v3.__copy__()
        self.assertEqual(repr(v3), repr(copied))
        self.assertFalse(copied is v3)
Beispiel #6
0
    def test_pickle_protocol_2(self):
        xyz = (1.0, 2.0, 3.0)
        v3 = eu.Vector3(*xyz)

        s = pickle.dumps(v3, 2)
        copied = pickle.loads(s)
        self.assertEqual(repr(v3), repr(copied))
        self.assertFalse(copied is v3)
Beispiel #7
0
    def test_pickle_lower_protocols(self):
        xyz = (1.0, 2.0, 3.0)
        v3 = eu.Vector3(*xyz)

        s = pickle.dumps(v3, 0)
        copied = pickle.loads(s)
        self.assertEqual(repr(v3), repr(copied))
        self.assertFalse(copied is v3)
        self.assertFalse(hasattr(copied, '__dict__'))

        s = pickle.dumps(v3, 1)
        copied = pickle.loads(s)
        self.assertEqual(repr(v3), repr(copied))
        self.assertFalse(copied is v3)
        self.assertFalse(hasattr(copied, '__dict__'))
Beispiel #8
0
    def test_index_access__set(self):
        xyz = (1.0, 2.0, 3.0)
        v3 = eu.Vector3(*xyz)
        v3[0] = 7.0
        self.assertEqual(repr(v3),
                         "Vector3(%.2f, %.2f, %.2f)" % (7.0, 2.0, 3.0))
        v3[1] = 8.0
        self.assertEqual(repr(v3),
                         "Vector3(%.2f, %.2f, %.2f)" % (7.0, 8.0, 3.0))
        v3[2] = 9.0
        self.assertEqual(repr(v3),
                         "Vector3(%.2f, %.2f, %.2f)" % (7.0, 8.0, 9.0))

        def f():
            v3[3] = 9.0

        self.assertRaises(IndexError, f)
Beispiel #9
0
 def test_vector3_rsub(self):
     a = (3.0, 7.0, 9.0)
     b = (1.0, 2.0, 3.0)
     va = eu.Vector3(*a)
     vb = eu.Vector3(*b)
     self.assertEquals(a - vb, eu.Vector3(2.0, 5.0, 6.0))
Beispiel #10
0
 def test_sub__v3_t3(self):
     a = (3.0, 7.0, 9.0)
     b = (1.0, 2.0, 3.0)
     va = eu.Vector3(*a)
     vb = eu.Vector3(*b)
     self.assertEqual(va - b, eu.Vector3(2.0, 5.0, 6.0))
Beispiel #11
0
 def test_iter(self):
     xyz = [1.0, 2.0, 3.0]
     v3 = eu.Vector3(*xyz)
     sequence = [e for e in v3]
     self.assertEqual(sequence, xyz)
Beispiel #12
0
 def test_len(self):
     xyz = (1.0, 2.0, 3.0)
     self.assertEqual(len(eu.Vector3(*xyz)), 3)
Beispiel #13
0
    def test_eq_v3(self):
        xyz = (1.0, 2.0, 3.0)
        self.assertTrue(eu.Vector3(*xyz), eu.Vector3(*xyz))

        other = (1.0, 3.0, 7.0)
        self.assertTrue(eu.Vector3(*xyz) != eu.Vector3(*other))
Beispiel #14
0
 def test_instantiate_default(self):
     v3 = eu.Vector3()
     self.assertEqual(repr(v3), "Vector3(%.2f, %.2f, %.2f)" % (0, 0, 0))
Beispiel #15
0
 def test_instantiate(self):
     xyz = (1.0, 2.0, 3.0)
     v3 = eu.Vector3(*xyz)
     self.assertEqual(repr(v3), "Vector3(%.2f, %.2f, %.2f)" % xyz)