Exemple #1
0
    def test_different_valued_vectors_are_not_equal(self):
        vectorA = Vector(7,6,2,3)
        vectorB = Vector(2,34,4,1000)
        self.assertNotEqual(vectorA, vectorB)

        vectorC = Vector(1,1,1,1,1,1,1)
        vectorD = Vector(1,1,1,1)
        self.assertNotEqual(vectorC, vectorD)
Exemple #2
0
    def test_vector_dimension(self):
        vectorA = Vector(5,2,3,5)
        self.assertEqual(4, vectorA.dimension)
        self.assertEqual(4, len(vectorA))

        vectorA = Vector()
        self.assertEqual(0, vectorA.dimension)
        self.assertEqual(0, len(vectorA))
Exemple #3
0
 def test_force_exertion(self):
     phys_obj = PhysicsObject([0, 0], 1)
     self.assertEqual(vector.get_inert_vector(2), phys_obj.applied_force)
     self.assertEqual(PhysicsObject.get_global_force(), phys_obj.net_force)
     phys_obj.apply_force([1, 4])
     self.assertEqual(Vector(1, 4), phys_obj.applied_force)
     self.assertEqual(
         Vector(1, 4) + PhysicsObject.get_global_force(),
         phys_obj.net_force)
Exemple #4
0
 def test_summation_creates_new_objects(self):
     vectorA = Vector(1,2,3)
     vectorB = Vector(10,10,-1)
     vectorC = vectorA + vectorB
     self.assertIsNot(vectorA, vectorC)
     self.assertIsNot(vectorB, vectorC)
     self.assertIsInstance(vectorA, Vector)
     self.assertIsInstance(vectorB, Vector)
     self.assertIsInstance(vectorC, Vector)
Exemple #5
0
    def test_equivalent_vectors_are_equal(self):
        vectorA = Vector(1,2,3)
        vectorB = Vector(1,2,3)
        self.assertEqual(vectorA,vectorB)

        randArr = [random.randint(-100,100) for x in range(10)]
        vectorC = Vector(*randArr)
        vectorD = Vector(*randArr)
        self.assertEqual(vectorA,vectorB)
Exemple #6
0
 def test_location(self):
     PhysicsObject.set_global_force([0, 0])
     phys_obj = PhysicsObject((4, 3), 4)
     self.assertEqual(Vector(4, 3), phys_obj.location)
     # self.assertFalse(phys_obj.in_motion)
     phys_obj.force_location(25, 432)
     self.assertEqual(Vector(25, 432))
     # self.assertFalse(phys_obj.in_motion)
     for i in range(30):
         location = [randint(-1000, 242), randint(1, 320)]
         phys_obj.force_location(*location)
         self.assertEqual(Vector(*location), phys_obj.location)
Exemple #7
0
    def test_equality_operator(self):
        vectorA = Vector(1,2,3)
        vectorB = Vector(1,2,3)
        vectorC = Vector(2,1,3)
        vectorD = Vector(32,12,4)
        vectorE = Vector(1,2)
        self.assertIsNot(vectorA, vectorB)
        self.assertEqual(vectorA, vectorB)
        self.assertEqual(list(vectorA), [1,2,3])
        self.assertNotEqual(vectorA, vectorC)
        self.assertNotEqual(vectorB, vectorC)
        self.assertNotEqual(vectorA, vectorE)

        self.assertNotEqual(vectorA, [1,2,3])
        self.assertNotEqual(vectorA*2, [2,4,6])
Exemple #8
0
    def test_motion_after_force(self):
        PhysicsObject.set_global_force([0, 0])
        phys_obj = PhysicsObject([1, 1], 23)
        self.assertFalse(phys_obj.in_motion)
        self.assertEqual(Vector(0, 0), phys_obj.velocity)
        phys_obj.exert_force([3, 2])
        self.assertTrue(phys_obj.in_motion)
        self.assertNotEqual(Vector(0, 0), phys_obj.velocity)

        phys_obj = PhysicsObject([1, 1], 23)
        self.assertFalse(phys_obj.in_motion)
        self.assertEqual(Vector(0, 0), phys_obj.velocity, (0, 0))
        phys_obj.exert_force([3, 2])
        self.assertFalse(phys_obj.in_motion)
        self.assertEqual(Vector(0, 0), phys_obj.velocity, (0, 0))
        self.assertNotEqual(Vector(0, 0), phys_obj.velocity)
Exemple #9
0
 def test_update_should_update(self):
     vectorA = Vector(1,2,3)
     vectorB = vectorA
     vectorB.update([3,4,5])
     self.assertIsInstance(vectorA, Vector)
     self.assertEqual(list(vectorB), [3,4,5])
     self.assertIs(vectorA, vectorB)
Exemple #10
0
 def test_get_item_at_index(self):
     vectorA = Vector(1,2,3,4)
     self.assertEqual(1, vectorA[0])
     self.assertEqual(2, vectorA[1])
     self.assertEqual(3, vectorA[2])
     self.assertEqual(4, vectorA[3])
     self.assertEqual(4, vectorA[-1])
     self.assertEqual(3, vectorA[2])
     for val in vectorA:
         self.assertIsInstance(val, float)
Exemple #11
0
 def test_set_vector_at_index(self):
     vectorA = Vector(1,2,3,4,5)
     vectorA[3] = -1
     self.assertEqual(-1, vectorA[3])
     self.assertEqual(list(vectorA), [1,2,3,-1,5])
     vectorA[-1]+=4
     self.assertEqual(9, vectorA[4])
     self.assertEqual(list(vectorA) , [1,2,3,-1,9])
     for val in vectorA:
         self.assertIsInstance(val, float)
Exemple #12
0
    def test_inert_property(self):
        vectorA = Vector(1,0,9,1)
        self.assertFalse(vectorA.inert)
        vectorA = Vector(0,0)
        self.assertTrue(vectorA.inert)
        vectorA = Vector(7,357,123,6,-32)
        self.assertFalse(vectorA.inert)
        vectorA[0]+=-7
        self.assertFalse(vectorA.inert)
        vectorA[1] = 0
        self.assertFalse(vectorA.inert)
        vectorA[2] = 0
        self.assertFalse(vectorA.inert)
        vectorA[3]-=6
        self.assertFalse(vectorA.inert)
        vectorA[4]+=32
        self.assertTrue(vectorA.inert)

        vectorA[2]+=1
        self.assertFalse(vectorA.inert)
Exemple #13
0
    def test_initial_velecoity(self):
        PhysicsObject.set_global_force([0, 0])
        phys_obj = PhysicsObject((4, 3), 4)
        self.assertFalse(phys_obj.in_motion)
        self.assertEqual(Vector(0, 0), phys_obj.velocity)

        phys_obj = PhysicsObject([43, -231], 214)
        self.assertFalse(phys_obj.in_motion)
        self.assertEqual(Vector(0, 0), phys_obj.velocity)

        phys_obj = PhysicsObject([1, 1], 23, [0, 0])
        self.assertFalse(phys_obj.in_motion)
        self.assertEqual(Vector(0, 0), phys_obj.velocity)

        phys_obj = PhysicsObject([1, 1], 23, [0, 1])
        self.assertTrue(phys_obj.in_motion)
        self.assertEqual(Vector(0, 1), phys_obj.velocity)

        phys_obj = PhysicsObject([1, 1], 23, [32, 0])
        self.assertTrue(phys_obj.in_motion)
        self.assertEqual(Vector(32, 0), phys_obj.velocity)
Exemple #14
0
    def test_vector_constant_mult(self):
        vectorA = Vector(1,2,3)
        vectorB = vectorA*2
        self.assertIsNot(vectorA , vectorB)
        self.assertEqual(list(vectorB) , [2,4,6])

        vectorC = 2*vectorA
        self.assertIsNot(vectorA, vectorC)
        self.assertIsNot(vectorB, vectorC)
        self.assertEqual(list(vectorC), [2,4,6])
        self.assertEqual(vectorC, vectorB)

        self.assertIsInstance(vectorA, Vector)
        self.assertIsInstance(vectorB, Vector)
        self.assertIsInstance(vectorC, Vector)
Exemple #15
0
    def test_set_global_force(self):
        PhysicsObject.set_global_force([2, 3])
        self.assertEqual(Vector(2, 3), PhysicsObject.get_global_force())
        PhysicsObject.set_global_force(Vector(54, 1.2))
        self.assertEqual(Vector(54, 1.2), PhysicsObject.get_global_force())
        PhysicsObject.set_global_force((0, 0))
        self.assertEqual(Vector(0, 0), PhysicsObject.get_global_force())

        PhysicsObject.set_global_force(Vector(54, 1.2))
        phys_obj = PhysicsObject(0, 0)
        self.assertEqual(Vector(54, 1.2), PhysicsObject.get_global_force())
        self.assertIsNot(PhysicsObject.get_global_force(),
                         PhysicsObject.get_global_force())
Exemple #16
0
 def test_summation_adds_well_like_addition(self):
     vectorC = Vector(1,2,3) + Vector(10,10,-1)
     self.assertEqual(list(vectorC) , [11,12,2])
     self.assertEqual(vectorC, Vector(11,12,2))
     self.assertIsInstance(vectorC, Vector)
Exemple #17
0
 def test_invalid_location_raises_ValueError(self):
     with self.assertRaises(ValueError):
         PhysicsObject(Vector(3, 2, 0), 0)
         PhysicsObject(Vector(0, 0, 0), -.002)
         PhysicsObject(Vector(-2), -12412412)
         PhysicsObject([randint(-100, 100) for x in range(1000)], 100)
Exemple #18
0
 def test_invalid_mass_zero_or_less_raises_ValueError(self):
     with self.assertRaises(ValueError):
         PhysicsObject(Vector(3, 2), 0)
         PhysicsObject(Vector(3, 2), -.002)
         PhysicsObject(Vector(3, 2), -12412412)
Exemple #19
0
 def test_vectors_can_be_empty(self):
     vectorA = Vector()