コード例 #1
0
ファイル: main.py プロジェクト: flavioribeiro/tests_globocom
def main():
    if len(sys.argv) < 2:
        raise Exception("missing file")

    p = Parser(sys.argv[1])
    
    ground_size = p.get_ground_size()
    ground = Ground(ground_size[0], ground_size[1])
    
    robot_first_pos = p.get_robot_first_pos()
    robot = WalkerRobot(robot_first_pos[0], robot_first_pos[1], 
                    robot_first_pos[2], ground)

    commands = p.get_command()

    for command in commands:
        if command[0] == 'T':
            robot.teleport(command[1], command[2])
        elif command[0] == 'M':
            robot.move()
        elif command[0] == 'L' or command[0] == 'R':
            robot.turn(command[0])

    print 'final pos:', robot.x, robot.y, robot.curr_direction
コード例 #2
0
ファイル: tests.py プロジェクト: flavioribeiro/tests_globocom
def test_walker_bot_move_to_wrong_place():
    g = Ground(1,1)
    bot = WalkerRobot("E", 1,1,g)
    with pytest.raises(Exception):
        bot.move()
コード例 #3
0
ファイル: tests.py プロジェクト: flavioribeiro/tests_globocom
def test_walker_bot_teleport_to_wrong_place():
    g = Ground(10,10)
    bot = WalkerRobot("E", 1, 1,g)
    with pytest.raises(Exception):
        bot.teleport(1000,10000)
コード例 #4
0
ファイル: tests.py プロジェクト: flavioribeiro/tests_globocom
def test_walker_bot_teleport():
    g = Ground(10,10)
    bot = WalkerRobot("E",1,1,g)
    bot.teleport(4,4)
    assert bot.x == 4
    assert bot.y == 4
コード例 #5
0
ファイル: tests.py プロジェクト: flavioribeiro/tests_globocom
def test_walker_bot_move():
    g = Ground(10,10)
    bot = WalkerRobot("E",1,1,g)
    bot.move()
    assert bot.x == 2
    bot.move()
    assert bot.x == 3
    bot.turn("R")
    bot.move()
    assert bot.y == 2
    bot.move()
    assert bot.y == 3
コード例 #6
0
ファイル: tests.py プロジェクト: flavioribeiro/tests_globocom
def test_walker_bot_turn():
    g = Ground(10,10)
    bot = WalkerRobot("E", 1, 1, g)
    bot.turn("R")
    assert bot.curr_direction == "S"
    bot.turn("R")
    assert bot.curr_direction == "W"
    bot.turn("R")
    assert bot.curr_direction == "N"
    bot.turn("R")
    assert bot.curr_direction == "E"
    bot.turn("L")
    assert bot.curr_direction == "N"
    bot.turn("L")
    assert bot.curr_direction == "W"
    bot.turn("L")
    assert bot.curr_direction == "S"
    bot.turn("L")
    assert bot.curr_direction == "E"