예제 #1
0
    def test_instance(self):
        ship = spaceship.Thing()
        self.assertTrue(isinstance(ship, spaceship.Thing))
        self.assertFalse(ship.name)
        self.assertFalse(ship.location)

        ship = spaceship.Thing("USS Enterprise")
        self.assertTrue(isinstance(ship, spaceship.Thing))
        self.assertEqual("USS Enterprise", ship.name)
        self.assertFalse(ship.location)

        ship = spaceship.Thing("Millennium Falcon", 3, 4)
        self.assertTrue(isinstance(ship, spaceship.Thing))
        self.assertEqual("Millennium Falcon", ship.name)
        self.assertTrue(isinstance(ship.location, spaceship.Coordinate))

        coord = spaceship.Coordinate(5, 2)
        ship = spaceship.Thing("Death Star", coord)
        self.assertTrue(isinstance(ship, spaceship.Thing))
        self.assertEqual("Death Star", ship.name)
        self.assertEqual(ship.location, coord)

        ship = spaceship.Thing("Bird of Prey", 3, 2, coord)
        self.assertTrue(isinstance(ship, spaceship.Thing))
        self.assertEqual("Bird of Prey", ship.name)
        self.assertEqual(ship.location, coord)
예제 #2
0
 def test_str(self):
     space = spaceship.Space("Milky Way")
     self.assertEqual("Space: 'Milky Way'", space.__str__())
     sol = spaceship.Thing("Sol", x=3, y=3)
     space.append(sol)
     self.assertIn("contains", space.__str__())
     earth = spaceship.Thing("Earth", x=4, y=5)
     space.append(earth)
     self.assertEquals(3, space.__str__().count("\n"))
예제 #3
0
 def test_dotick(self):
     space = spaceship.Space("Earth's Orbit")
     moon = spaceship.Thing("Moon")
     space.append(moon)
     space.doTick(1)
     self.assertEqual(1, space.ticks)
     self.assertEqual(1, moon.ticks)
예제 #4
0
    def test_nonzero(self):
        planet = spaceship.Thing("Omicron Persei 8")
        self.assertFalse(planet.__nonzero__())

        planet.location = 33
        self.assertFalse(planet.__nonzero__())

        planet.location = spaceship.Coordinate(3, 2)
        self.assertTrue(planet.__nonzero__())
예제 #5
0
    def test_run(self):
        time = spaceship.Time(.01)
        space = spaceship.Space("Deep Space")
        ship = spaceship.Thing("USS Voyager")
        space.append(ship)
        time.append(space)

        time.run(5)
        self.assertEqual(5, time.tick)
        self.assertEqual(5, space.ticks)
        self.assertEqual(5, ship.ticks)
예제 #6
0
    def test_flight(self):
        time = spaceship.Time()
        universe = spaceship.Space("The Universe")
        ship = spaceship.Thing("Asteroid", 2, 2)
        ship.angle = 90
        ship.speed = 2
        universe.append(ship)
        self.assertTrue(isinstance(ship.location, spaceship.Coordinate))
        time.append(universe)

        time.run(10)
        desiredLocation = spaceship.Coordinate(2, 22)
        self.assertEqual(ship.location, desiredLocation)
예제 #7
0
    def test_domove(self):
        ship = spaceship.Thing("UFO", 2, 2)
        ship.speed = 2
        ship.angle = 90
        ship.doMove()
        desiredLocation = spaceship.Coordinate(2, 4)
        self.assertEqual(ship.location, desiredLocation)

        ship.angle = 0
        ship.doMove()
        desiredLocation = spaceship.Coordinate(4, 4)
        self.assertEqual(ship.location, desiredLocation)

        ship.angle = 45
        ship.doMove()
        desiredLocation = spaceship.Coordinate(5, 5)
        self.assertEqual(ship.location, desiredLocation)

        ship.angle = 270
        ship.doMove()
        desiredLocation = spaceship.Coordinate(5, 3)
        self.assertEqual(ship.location, desiredLocation)
예제 #8
0
 def test_dotick(self):
     ship = spaceship.Thing("X Wing")
     ship.doTick(1)
     self.assertEqual(1, ship.ticks)
예제 #9
0
 def test_str(self):
     mars = spaceship.Thing("Mars", 1, 1)
     self.assertEqual("Thing: 'Mars' at (1, 1)", mars.__str__())