Exemplo n.º 1
0
    def test_truediv(self):
        """Testing Vector2.__truediv__()"""

        self.assertTrue((x * 4 + y * 2) / 2 == x * 2 + y)

        X = x * 4
        X = X / 2
        self.assertTrue(x == Vector2(1, 0) and X == Vector2(2, 0))
Exemplo n.º 2
0
    def test_sub(self):
        """Testing Vector2.__sub__()"""

        self.assertTrue(x - y == Vector2(1, -1), 'Vector2 __sub__() failed')

        X = x
        X = X - x
        self.assertTrue(x == Vector2(1, 0) and X == Vector2(0, 0),
                        'Vector2 __isub__() failed')
Exemplo n.º 3
0
    def test_mul(self):
        """Testing Vector2.__mul__()"""

        self.assertTrue(x * 2 + y * 3 == Vector2(2, 3),
                        'Vector2 __mul__() failed')

        X = x
        X = X * 2
        self.assertTrue(x == Vector2(1, 0) and X == Vector2(2, 0),
                        'Vector2 __imul__() failed')
Exemplo n.º 4
0
    def test_add(self):
        """Testing Vector2.__add__()"""

        self.assertTrue(x + y == Vector2(1, 1), 'Vector2 __add__() failed')

        X = x
        X = X + x
        self.assertTrue(x == Vector2(1, 0) and X == Vector2(2, 0),
                        'Vector2 __iadd__() failed')

        self.assertFalse(x + y == Vector2(1 + 1e-6, 1),
                         'Vector2 __add__() failed')
Exemplo n.º 5
0
    def test_trig_utilties(self):
        """Testing Vector2 cos() and sin() utilities"""

        r2 = math.sqrt(2)
        r3 = math.sqrt(3)
        yr3 = y * r3

        self.assertTrue(Vector2.close((x + y).cos(y), 1 / r2))
        self.assertTrue(Vector2.close(x.cos(x + yr3), 0.5))

        self.assertTrue(Vector2.close((x + y).sin(y), 1 / r2))
        self.assertTrue(Vector2.close(x.sin(x + yr3), r3 / 2))
Exemplo n.º 6
0
    def test_angle(self):
        """Testing Vector2.angle()"""

        dr = math.radians

        for i in range(-179, +179):  # anticlockwise angle from x
            self.assertTrue(
                Vector2.close(
                    x.angle(x * math.cos(dr(i)) + y * math.sin(dr(i))), dr(i)))
Exemplo n.º 7
0
    def test_close_radius(self):
        """Testing Vector2.closeRadius()"""

        self.assertTrue(Vector2.closeRadius() < 1)
Exemplo n.º 8
0
    def test_nonzero(self):
        """Testing Vector2.nonZero()"""

        self.assertTrue(Vector2.nonZero(Vector2.closeRadius()))
Exemplo n.º 9
0
    def test_neg(self):
        """Testing Vector2.__neg__()"""

        self.assertTrue(-y == Vector2(0, -1), 'Vector2 __neg__() failed')
Exemplo n.º 10
0
    def test_close(self):
        """Testing Vector2.close()"""

        self.assertFalse(Vector2.close(1, 2), 'Vector2.close() failed')
        self.assertTrue(Vector2.close(1, 1 + 1e-100), 'Vector2.close() failed')
Exemplo n.º 11
0
    def test_smallestAngleToNormalPlane(self):
        """Testing Vector2.smallestAngleToNormalPlane()"""

        dr = math.radians

        # first vector is y, second vector is 0 degrees anti-clockwise from x axis
        self.assertTrue(Vector2.close(dr(0), y.smallestAngleToNormalPlane(x)))
        self.assertTrue(
            Vector2.close(dr(+45), y.smallestAngleToNormalPlane(x + y)))  # +45
        self.assertTrue(Vector2.close(dr(+90),
                                      y.smallestAngleToNormalPlane(y)))  # +90
        self.assertTrue(
            Vector2.close(dr(+45),
                          y.smallestAngleToNormalPlane(-x + -y)))  # +135
        self.assertTrue(Vector2.close(
            dr(0), y.smallestAngleToNormalPlane(-x)))  # +180
        self.assertTrue(
            Vector2.close(dr(+45),
                          y.smallestAngleToNormalPlane(-x + -y)))  # +225
        self.assertTrue(
            Vector2.close(dr(+90), y.smallestAngleToNormalPlane(-y)))  # +270
        self.assertTrue(
            Vector2.close(dr(+45),
                          y.smallestAngleToNormalPlane(-x + -y)))  # +315
        self.assertTrue(Vector2.close(dr(0),
                                      y.smallestAngleToNormalPlane(x)))  # +360

        p2 = math.pi / 2
        p4 = math.pi / 4

        # original tests
        self.assertTrue(Vector2.close(y.smallestAngleToNormalPlane(y), p2))
        self.assertTrue(Vector2.close(y.smallestAngleToNormalPlane(y * 2), p2))
        self.assertTrue(Vector2.close(y.smallestAngleToNormalPlane(x), 0))
        self.assertTrue(Vector2.close(y.smallestAngleToNormalPlane(-x), 0))
        self.assertTrue(
            Vector2.close((x + y).smallestAngleToNormalPlane(x), p4))
        self.assertTrue(
            Vector2.close((x - y).smallestAngleToNormalPlane(x), p4))
Exemplo n.º 12
0
    def test_close(self):
        """Testing Vector2.close()"""

        self.assertTrue(Vector2.close(0, Vector2.closeRadius() / 2))
Exemplo n.º 13
0
    def test_init(self):
        """Testing class initialisation"""

        self.assertTrue(x + y == Vector2(1, 1))
Exemplo n.º 14
0
import unittest
import math

from vita.modules.utils.Vector2 import Vector2

# create zero and unit vectors
zero, x, y = Vector2.zeroAndUnits()


class TestVector2(unittest.TestCase):
    def test_init(self):
        """Testing class initialisation"""

        self.assertTrue(x + y == Vector2(1, 1))

    def test_zeroAndUnits(self):
        """Testing initialisation through the zeroAndUnits() utility method"""

        self.assertTrue(zero != x and zero != y and x != y,
                        'Vector2 did not initialise correctly')

    def test_close(self):
        """Testing Vector2.close()"""

        self.assertFalse(Vector2.close(1, 2), 'Vector2.close() failed')
        self.assertTrue(Vector2.close(1, 1 + 1e-100), 'Vector2.close() failed')

    def test_repr(self):
        """Testing Vector2.__repr__()"""

        self.assertTrue(