def test_instance(self): space = spaceship.Space() self.assertTrue(isinstance(space, spaceship.Space)) self.assertFalse(space.name) space = spaceship.Space("macrocosm") self.assertTrue(isinstance(space, spaceship.Space)) self.assertEqual("macrocosm", space.name) space.name = "cosmos" self.assertEqual("cosmos", space.name)
def test_dotick(self): time = spaceship.Time() space = spaceship.Space("Universe") time.append(space) time.doTick() self.assertEqual(1, time.tick) self.assertEqual(1, time[0].ticks)
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)
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"))
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)
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)