예제 #1
0
def benchmark():
    particles = [
        Particle(uniform(-1.0, 1.0), uniform(-1.0, 1.0), uniform(-1.0, 1.0))
        for _ in range(1000)
    ]

    simulator = ParticleSimulator(particles)
    simulator.evolve(0.1)
예제 #2
0
def test():
    particles = [
        Particle(0.3, 0.5, +1),
        Particle(0.0, -0.5, -1),
        Particle(-0.1, -0.4, +3)
    ]

    simulator = ParticleSimulator(particles)
    simulator.evolve(0.1)

    p0, p1, p2 = particles

    def fequal(a, b):
        return abs(a - b) < 1e-5

    assert fequal(p0.x, 0.2102698450356825)
    assert fequal(p0.y, 0.5438635787296997)
    assert fequal(p1.x, -0.0993347660567358)
    assert fequal(p1.y, -0.4900342888538049)
    assert fequal(p2.x, 0.1913585038252641)
    assert fequal(p2.y, -0.3652272210744360)

    print('All tests passed !!!')
예제 #3
0
 def test_be_clicked(self):
     p = Particle(3, 4, 3, 4, 15)
     self.assertTrue(p.isBeClicked(6, 6))
예제 #4
0
 def test_Kinetic(self):
     p = Particle(3, 4, 3, 4, 15)
     self.assertEqual(25 / 2, p.calKinetic())
예제 #5
0
 def test_momentum(self):
     p = Particle(3, 4, 3, 4, 15)
     self.assertEqual(p.momentum, Vector(3, 4))