예제 #1
0
 def test_simple_step(self):
     b = Body(1, Vector2(), Vector2(0, 0))
     b.add_force(Vector2(1, 1))
     self.system.add_body(Body(1, Vector2(), Vector2(1, 1)))
     self.system.add_body(b)
     self.system.step(1)
     self.assertEqual(self.system.bodies[0].velocity,
                      self.system.bodies[1].velocity)
예제 #2
0
 def test_angle_between(self):
     self.assertAlmostEqual(
         Vector2(1, math.sqrt(3)).angle_between(Vector2(0, 1000)),
         math.pi / 6
     )
     self.assertAlmostEqual(
         Vector2(1, math.sqrt(3)).angle_between(Vector2(0, -1000)),
         math.pi - math.pi / 6
     )
예제 #3
0
 def test_integrate(self):
     b = Body(2, Vector2(0, 0), Vector2(0, -1))
     b.add_force(Vector2(0, 2))
     b.integrate(0.1)
     self.assertAlmostEqual(b.position, Vector2(0, -0.09))
예제 #4
0
 def test_angle_fourth_quarter(self):
     self.assertAlmostEqual(Vector2(1, -math.sqrt(3)).angle, -math.pi / 3)
예제 #5
0
 def test_angle_second_quarter(self):
     self.assertAlmostEqual(
         Vector2(-1, math.sqrt(3)).angle,
         math.pi - (math.pi / 3)
         )
예제 #6
0
 def test_self_div(self):
     v = Vector2(4, 6)
     v /= 2
     self.assertEqual(v, Vector2(2, 3))
예제 #7
0
 def test_truediv(self):
     self.assertEqual(
         Vector2(4, 6) / 2, Vector2(2, 3)
     )
예제 #8
0
 def test_rmul(self):
     self.assertEqual(
         2 * Vector2(2, 3), Vector2(4, 6)
     )
예제 #9
0
 def test_substraction(self):
     self.assertEqual(
         Vector2(2, 3) - Vector2(2, 4),
         Vector2(0, -1)
     )
예제 #10
0
 def test_normalized(self):
     v = Vector2(2, 3)
     vn = Vector2(2, 3).normalized()
     self.assertEqual(vn.mag, 1)
     self.assertEqual(vn.angle, v.angle)
예제 #11
0
 def test_iter(self):
     values = []
     for x in Vector2(2, 3):
         values.append(x)
     self.assertListEqual(values, [2, 3])
예제 #12
0
 def test_abs(self):
     self.assertEqual(abs(Vector2(2, 3)), Vector2(2, 3).mag)
예제 #13
0
 def test_angle_null_vector(self):
     self.assertEqual(Vector2().angle, 0)
예제 #14
0
 def test_global_forces(self):
     self.system.add_external_force(Vector2(0, 1))
     self.system.add_body(Body())
     self.system.step(1)
     self.assertEqual(self.system.bodies[0].velocity, Vector2(0, 1))
예제 #15
0
 def test_construction(self):
     b = Body(1, Vector2(1, 2), Vector2(1, 1))
     self.assertEqual(b.mass, 1)
     self.assertEqual(b.position, Vector2(1, 2))
     self.assertEqual(b.velocity, Vector2(1, 1))
     self.assertEqual(b.acceleration, Vector2())
예제 #16
0
 def test_add(self):
     self.assertEqual(
         Vector2(2, 3) + Vector2(2, 4),
         Vector2(4, 7)
     )
예제 #17
0
 def test_self_add(self):
     v = Vector2(2, 3)
     v += Vector2(1, 1)
     self.assertEqual(v, Vector2(3, 4))
예제 #18
0
 def test_construction(self):
     v = Vector2(3, 5)
     self.assertEqual(v.x, 3)
     self.assertEqual(v.y, 5)
예제 #19
0
 def test_mul(self):
     self.assertEqual(
         Vector2(2, 3) * 2, Vector2(4, 6)
     )
예제 #20
0
 def test_dot(self):
     self.assertEqual(
         Vector2(2, 3).dot(Vector2(1, 2)),
         8
     )
예제 #21
0
 def test_self_mul(self):
     v = Vector2(2, 3)
     v *= 2
     self.assertEqual(v, Vector2(4, 6))
예제 #22
0
 def test_str(self):
     self.assertEqual(
         str(Vector2(3, 5)), "(3, 5)"
     )
예제 #23
0
 def test_default_construction(self):
     v = Vector2()
     self.assertEqual(v.x, 0)
     self.assertEqual(v.y, 0)
예제 #24
0
 def test_repr(self):
     self.assertEqual(
         repr(Vector2(3, 5)), "<Vector2 (3, 5)>"
     )
예제 #25
0
 def test_mag(self):
     self.assertAlmostEqual(Vector2(3, 4).mag, 5)
예제 #26
0
 def test_neg(self):
     self.assertEqual(-Vector2(2, 3), Vector2(-2, -3))
예제 #27
0
 def test_angle_third_quarter(self):
     self.assertAlmostEqual(
         Vector2(-1, -math.sqrt(3)).angle,
         math.pi / 3 - math.pi
         )
예제 #28
0
 def test_equal(self):
     self.assertEqual(
         Vector2(2, 3), Vector2(2, 3)
     )
예제 #29
0
 def test_angle_null_x(self):
     self.assertEqual(Vector2(0, 1).angle, math.pi)
     self.assertEqual(Vector2(0, -1).angle, -math.pi)
예제 #30
0
 def test_apply_force(self):
     b = Body(2)
     b.add_force(Vector2(3, 4))
     self.assertEqual(b.acceleration.mag, 5 / 2)