def test_mapobjects_replace(self): game = Game(Map(13,13)) pl = Player("darvin", game) self.assertEqual(pl.game, game) pl.cast("create_robot", Coords(0,0), Direction('e')) program = "+.+.+.+.+" for op, x in zip(program, range(len(program))): pl.place_operator(op, Coords(x,0)) pl.cast("run") for i in range(100): game.tick() program = "+++.+.+.+" for op, x in zip(program, range(len(program))): pl.place_operator(op, Coords(x,0)) pl.cast("create_robot", Coords(0,0), Direction('e')) pl.cast("run") for i in range(100): game.tick() self.assertEqual("CDE", pl.robots[1].output)
def test_cycled_programms(self): programms = ( #(["+++[>++<-]>."], "F"), #(["+++[>+++++<-]>."], "O"), #(["++[>+++[>+++<-]<-]>>."], "R"), #(["++[>++[>+++++<-]<-]>>+."], "U"), ([ r"++[( (>+++++( ", r" > [ < ", r" )++) - ", r" ] ", r" .+>>]-<( ", r" ", r" ", r" ", r" ", r" ", r" ", ], "U"), ) for program, rightresult in programms: game = Game(Map(60,60)) pl = Player("darvin",game) pl.cast("create_robot", Coords(0,0), Direction('e')) self.place_operators(pl, program, 0,0) pl.cast("run") for i in range(100): game.tick() self.assertEqual(rightresult, pl.robots[0].output)
def test_import(self): programms = ( (["++++++++.>+++++.<++++..++++-."], "HELLO"), (["++++++++.>+++++.<++++..++++-."], "HELLO"), (["++++++++.>+++++.<++++..++++-."], "HELLO"), (["++++++++.>+++++.<++++..++++-."], "HELLO"), ([\ "+++(",\ " +",\ " +",\ ".++(",\ "",\ ], "G"), ) for program, rightresult in programms: mapp = Map.from_list(program) game = Game(mapp) pl = Player("darvin", game) pl.cast("create_robot", Coords(0,0), Direction('e')) pl.cast("run") for i in range(100): game.tick() self.assertEqual(rightresult, pl.robots[0].output)
def test_many_programms(self): programms = ( #(["++++++++.>+++++.<++++..++++-."], "HELLO"), #(["++++++++.>+++++.<++++..++++-."], "HELLO"), #(["++++++++.>+++++.<++++..++++-."], "HELLO"), #(["++++++++.>+++++.<++++..++++-."], "HELLO"), ([\ " +++(",\ " +",\ " +",\ " .++(",\ "",\ ], "G"), ) for program, rightresult in programms: game = Game(Map(60,60)) pl = Player("darvin",game) pl.cast("create_robot", Coords(0,0), Direction('e')) self.place_operators(pl, program, 0,0) pl.cast("run") for i in range(100): game.tick() self.assertEqual(rightresult, pl.robots[0].output)