예제 #1
0
 def test_getMarsCarPos(self):
     mc = MarsCarDemo()
     self.assertEqual(mc.getMarsCarPos(), {
         "x": 0,
         "y": 0,
         "fc": None,
         "rip": None
     })
예제 #2
0
    def test_moveStep_rip(self):
        mc = MarsCarDemo()
        xy = {"xMax": 4, "yMax": 4}
        mc.setXyMax(xy)
        pos = {"x": 3, "y": 4, "fc": 'N', "rip": None}
        mc.setMarsCarPos(pos)

        # print(mc.getMarsCarPos())
        mc.moveStep(pos)
        # print(mc.getMarsCarPos())
        self.assertEqual(mc.getMarsCarPos()["rip"], 'RIP')
예제 #3
0
    def test_moveStep_alive(self):
        mc = MarsCarDemo()
        xy = {"xMax": 5, "yMax": 5}
        mc.setXyMax(xy)
        pos = {"x": 3, "y": 4, "fc": 'E', "rip": None}
        mc.setMarsCarPos(pos)

        tar_pos = copy.deepcopy(pos)
        tar_pos['x'] += 1
        # print(mc.getMarsCarPos())
        mc.moveStep(pos)
        # print(mc.getMarsCarPos())
        self.assertEqual(mc.getMarsCarPos(), tar_pos)
예제 #4
0
    def test_turnRight(self):
        mc = MarsCarDemo()
        pos = {"x": 3, "y": 4, "fc": 'N', "rip": None}
        mc.setMarsCarPos(pos)

        tar_pos = {"x": 3, "y": 4, "fc": 'E', "rip": None}
        mc.turnRight(pos)
        self.assertEqual(mc.getMarsCarPos(), tar_pos)
예제 #5
0
 def test_checkRipY_pass(self):
     mc = MarsCarDemo()
     xy = {"xMax": 5, "yMax": 5}
     mc.setXyMax(xy)
     y = 4
     print(mc.checkRipY(y))
     self.assertEqual(mc.checkRipY(y), False)
예제 #6
0
def test():

    # max x y and all mars car list
    max = {"xMax": 5, "yMax": 5}
    cars = []
    # ======================first mars car ======================
    pos1 = {"x": 1, "y": 2, "fc": "N", "rip": None}
    cmd1 = "L M L M L M L M M".split()
    print "================= first mars car position ====================="
    marsCar1 = MarsCarDemo()
    marsCar1.setXyMax(max)
    marsCar1.marsCarRunning(pos1, cmd1, cars)
    cars.append(marsCar1)
    print marsCar1.getMarsCarPos()

    print "================= second mars car position ===================="
    pos2 = {"x": 3, "y": 3, "fc": "E", "rip": None}
    cmd2 = "M M".split()
    marsCar2 = MarsCarDemo()
    marsCar2.setXyMax(max)
    marsCar2.marsCarRunning(pos2, cmd2, cars)
    cars.append(marsCar2)
    print marsCar2.getMarsCarPos()
예제 #7
0
 def test_checkRipY_smaller(self):
     mc = MarsCarDemo()
     xy = {"xMax": 5, "yMax": 5}
     mc.setXyMax(xy)
     y = -1
     self.assertEqual(mc.checkRipY(y), True)
예제 #8
0
 def test_setMarsCarPos(self):
     mc = MarsCarDemo()
     pos = {"x": 3, "y": 4, "fc": None, "rip": None}
     mc.setMarsCarPos(pos)
     self.assertEqual(mc.getMarsCarPos(), pos)
예제 #9
0
 def test_setXyMax(self):
     mc = MarsCarDemo()
     xy = {"xMax": 1, "yMax": 2}
     mc.setXyMax(xy)
     self.assertEqual(mc.xyMax, xy)
예제 #10
0
 def test_getXyMax(self):
     mc = MarsCarDemo()
     self.assertEqual(mc.getXyMax(), {"xMax": 0, "yMax": 0})