Ejemplo n.º 1
0
 def testWorldAssertions(self):
     try:
         world.assertRobotsAt(8, 8)
         fail("No Robots")
     except NoRobots:
         pass
     world.assertBeepersAt(0, 0, 0)
     try:
         world.assertBeepersAt(0, 0, 1)
         fail("Not enough beepers")
     except NoBeepers:
         pass
     world.assertRobotsAt(5, 5)
     world.placeBeepers(3, 3, 3)
     world.assertBeepersAt(3, 3, 0)
     world.assertBeepersAt(3, 3, 1)
     world.assertBeepersAt(3, 3, 3)
     try:
         world.assertBeepersAt(3, 3, 4)
         fail("Not enough beepers")
     except NoBeepers:
         pass
     try:
         world.assertBeepersAt(3, 3, infinity)
         fail("Not enough beepers")
     except NoBeepers:
         pass
     world.placeBeepers(3, 3, infinity)  #infinite
     world.assertBeepersAt(3, 3, infinity)
     world.assertBeepersAt(3, 3, 0)
     world.assertBeepersAt(3, 3, 3)
Ejemplo n.º 2
0
 def testInfiniteBeepersInWorld(self):
     "Infinite beepers in world"
     world.placeBeepers(5, 5, infinity)
     self.karel.pickBeeper()
     self.assertEqual( world._beepers[(5,5)], infinity, "World lacks infinite beepers")
     self.karel.putBeeper()
     self.assertEqual( world._beepers[(5,5)], infinity, "World lacks infinite beepers")
Ejemplo n.º 3
0
 def testPickBeeper(self):
     "Picking beepers and putting them again"
     world.placeBeepers(5, 5, 3)
     self.assertNoBeepersInBeeperBag(self.karel)
     self.karel.pickBeeper()
     self.assertBeepersInBeeperBag(self.karel)
     self.karel.pickBeeper()
     self.assertEqual( self.karel._UrRobot__beepers, 2, "Wrong number of beepers")
     self.karel.putBeeper()
     self.assertEqual( self.karel._UrRobot__beepers, 1, "Wrong number of beepers")
     self.karel.putBeeper()
     self.assertNoBeepersInBeeperBag(self.karel)
Ejemplo n.º 4
0
 def testRobotPredicates(self):
     "Validate all of the predicates in class Robot"
     self.karel = Robot(5, 5, North, 0)  # has to be a Robot here
     self.assertEqual(self.karel.anyBeepersInBeeperBag(), 0)
     self.assertEqual(self.karel.nextToABeeper(), 0)
     self.assertEqual(self.karel.facingNorth(), 1)
     self.assertEqual(self.karel.facingWest(), 0)
     self.assertEqual(self.karel.facingSouth(), 0)
     self.assertEqual(self.karel.facingEast(), 0)
     self.assertEqual(self.karel.frontIsClear(), 1)
     martha = UrRobot(5, 5, North, 0)
     self.assertEqual(self.karel.nextToARobot(), 1)
     world.placeWallNorthOf(5, 5)
     self.assertEqual(self.karel.frontIsClear(), 0)
     self.karel.turnLeft()
     self.assertEqual(self.karel.facingNorth(), 0)
     self.assertEqual(self.karel.facingWest(), 1)
     self.assertEqual(self.karel.frontIsClear(), 1)
     world.placeWallEastOf(5, 4)
     self.assertEqual(self.karel.frontIsClear(), 0)
     self.karel.turnLeft()
     self.assertEqual(self.karel.facingWest(), 0)
     self.assertEqual(self.karel.facingSouth(), 1)
     self.assertEqual(self.karel.frontIsClear(), 1)
     world.placeWallNorthOf(4, 5)
     self.assertEqual(self.karel.frontIsClear(), 0)
     self.karel.turnLeft()
     self.assertEqual(self.karel.facingSouth(), 0)
     self.assertEqual(self.karel.facingEast(), 1)
     self.assertEqual(self.karel.frontIsClear(), 1)
     world.placeWallEastOf(5, 5)
     self.assertEqual(self.karel.frontIsClear(), 0)
     charlie = Robot(12, 12, North, 1)
     rosie = UrRobot(12, 12, East, 0)
     self.assertEqual(charlie.anyBeepersInBeeperBag(), 1)
     charlie.putBeeper()
     self.assertEqual(charlie.anyBeepersInBeeperBag(), 0)
     charlie.pickBeeper()
     self.assertEqual(charlie.anyBeepersInBeeperBag(), 1)
     self.assertEqual(charlie.nextToARobot(), 1)
     charlie.move()
     charlie.move()
     self.assertEqual(charlie.nextToARobot(), 0)
     self.assertNoBeepersAt(9, 9)
     world.placeBeepers(9, 9, 1)
     self.assertBeepersAt(9, 9)