Beispiel #1
0
    def test_get_moment(self):
        chunk = Chunk()
        self.assertEquals(chunk.get_moment(), 0.0, "bad initial moment")

        shard1 = Disc(gold, 2, (10, 20))
        shard2 = Block(gold, self.unitsquare, (100, 200))
        chunk.shards = [shard1, shard2]

        expected = shard1.get_moment() + shard2.get_moment()
        self.assertEquals(chunk.get_moment(), expected, "bad moment")
Beispiel #2
0
    def test_add_to_body(self):
        disc = Disc(gold, 5, (1, 2))
        body = Body(0, 0)
        space = Space()
        space.add(body)

        disc.add_to_body(space, body)

        self.assertNotNone(disc.shape, "didnt create shape")
        self.assertEquals(disc.shape.body, body, "didnt add shape to body")
        self.assertEquals(disc.shape.radius, 5.0, "bad radius")
        self.assertEquals(disc.shape.center, Vec2d(1.0, 2.0), "bad center")
        self.assertAlmostEquals(disc.shape.friction, gold.friction,
            msg="bad friction")
        self.assertAlmostEquals(disc.shape.elasticity, gold.elasticity,
            msg="bad elasticity")
        self.assertEquals(space.shapes, [disc.shape],
            "didn't add shape to space")
Beispiel #3
0
 def test_offset(self):
     disc = Disc(gold, 10, (11, 22))
     disc.offset((100, 200))
     self.assertEquals(disc.get_centroid(), (111, 222), "didnt apply offset")
Beispiel #4
0
 def test_get_centroid(self):
     disc = Disc(gold, 10, (111, 222))
     self.assertEquals(disc.get_centroid(), (111, 222), "bad offset")
Beispiel #5
0
 def test_get_moment(self):
     radius = 5
     offset = (1, 2)
     disc = Disc(gold, radius, offset)
     expected = moment_for_circle(disc.mass, 0, radius, offset)
     self.assertEquals(disc.get_moment(), expected, "bad moment")