def test_take_piece_output(self): merels = database.MerelsStorage(self.storage) game.beat("create", self.topic_name, self.storage) merels.update_game(self.topic_name, "X", 0, 0, "XXXNNNOOOXXXNNNOOOXXXOOO", "", 1) self.assertTrue("Taken a man" in game.beat("take 2,2", self.topic_name, self.storage))
def test_not_possible_take_piece_output(self): merels = database.MerelsStorage(self.storage) game.beat("create", self.topic_name, self.storage) merels.update_game(self.topic_name, "X", 6, 6, "XXXNNNOOOXXXNNNOOOXXXOOO", "", 0) self.assertTrue("Taking is not possible" in game.beat( "take 2,2", self.topic_name, self.storage))
def test_cannot_make_any_move_output(self): merels = database.MerelsStorage(self.storage) game.beat("create", self.topic_name, self.storage) merels.update_game(self.topic_name, "X", 3, 4, "OOXOXNOXNNOXNNNNNNXNNXNN", "", 0) self.assertTrue("Switching" in game.beat( "move 6,0 3,0", self.topic_name, self.storage))
def test_unknown_command(self): merels = database.MerelsStorage(self.storage) game.beat("create", self.topic_name, self.storage) merels.update_game(self.topic_name, "X", 6, 6, "XXXNNNOOONNNNNNNNNNNNNNN", "", 1) self.assertTrue("Unknown command", game.beat("magic 2,2", self.topic_name, self.storage))
def test_move_piece_output(self): merels = database.MerelsStorage(self.storage) game.beat("create", self.topic_name, self.storage) merels.update_game(self.topic_name, "X", 0, 0, "XXXNNNOOOXXXNNNOOOXXXOOO", "", 0) self.assertTrue("Moved a man" in game.beat( "move 0,3 1,3", self.topic_name, self.storage))
def test_not_possible_move_piece_output(self): merels = database.MerelsStorage(self.storage) game.beat("create", self.topic_name, self.storage) merels.update_game(self.topic_name, "X", 0, 0, "XXXNNNOOOXXXNNNOOOXXXOOO", "", 0) self.assertTrue("Failed" in game.beat("move 0,3 1,2", self.topic_name, self.storage))
def test_win_output(self): merels = database.MerelsStorage(self.storage) game.beat("create", self.topic_name, self.storage) merels.update_game(self.topic_name, "X", 6, 6, "XXXNNNOOONNNNNNNNNNNNNNN", "", 1) self.assertTrue("wins the game!", game.beat("take 2,2", self.topic_name, self.storage))
def test_take_before_put_output(self): merels = database.MerelsStorage(self.storage) game.beat("create", self.topic_name, self.storage) merels.update_game(self.topic_name, "X", 0, 0, "XXXNNNOOOXXXNNNOOOXXXNNN", "", 1) self.assertTrue("Take is required", game.beat("put 1,1", self.topic_name, self.storage))
def test_put_piece_output(self): merels = database.MerelsStorage(self.topic_name, self.storage) # All new games start with updating the game as follows merels.update_game(self.topic_name, "X", 0, 0, "NNNNNNNNNNNNNNNNNNNNNNNN", "", 0) resp, move = game.beat("put 0,0", self.topic_name, self.storage) self.assertTrue("Put a man" in resp)
def test_not_possible_put_piece_output(self): merels = database.MerelsStorage(self.topic_name, self.storage) merels.update_game(self.topic_name, "X", 0, 0, "NNNNNNNNNNNNNNNNNNNNNNNN", "", 0) with self.assertRaises(BadMoveException) as warning: game.beat("put 0,1", self.topic_name, self.storage) self.assertTrue("Failed" in str(warning))
def test_not_possible_take_piece_output(self): merels = database.MerelsStorage(self.topic_name, self.storage) merels.update_game(self.topic_name, "X", 0, 0, "NNNNNNNNNNNNNNNNNNNNNNNN", "", 0) merels.update_game(self.topic_name, "X", 6, 6, "XXXNNNOOOXXXNNNOOOXXXOOO", "", 0) with self.assertRaises(BadMoveException) as warning: game.beat("take 2,2", self.topic_name, self.storage) self.assertTrue("Taking is not possible" in str(warning))
def test_unknown_command(self): merels = database.MerelsStorage(self.topic_name, self.storage) merels.update_game(self.topic_name, "X", 0, 0, "NNNNNNNNNNNNNNNNNNNNNNNN", "", 0) merels.update_game(self.topic_name, "X", 6, 6, "XXXNNNOOONNNNNNNNNNNNNNN", "", 1) with self.assertRaises(BadMoveException) as warning: game.beat("magic 2,2", self.topic_name, self.storage) self.assertTrue("Unknown command" in str(warning))
def test_take_before_move_output(self): merels = database.MerelsStorage(self.topic_name, self.storage) merels.update_game(self.topic_name, "X", 0, 0, "NNNNNNNNNNNNNNNNNNNNNNNN", "", 0) merels.update_game(self.topic_name, "X", 6, 6, "XXXNNNOOONNNNNNNNNNNNNNN", "", 1) with self.assertRaises(BadMoveException) as warning: game.beat("move 0,1 1,3", self.topic_name, self.storage) self.assertTrue("Take is required" in str(warning))
def test_new_game_phase(self): storage = SimpleStorage() merels = database.MerelsStorage(storage) merels.create_new_game("test") res = game_data.GameData(merels.get_game_data("test")) self.assertEqual(res.get_phase(), 1) merels.update_game(res.topic_name, "O", 5, 4, "XXXXNNNOOOOONNNNNNNNNNNN", "03", 0) res = game_data.GameData(merels.get_game_data("test")) self.assertEqual(res.board, "XXXXNNNOOOOONNNNNNNNNNNN") self.assertEqual(res.get_phase(), 2) merels.update_game(res.topic_name, "X", 6, 4, "XXXNNNNOOOOONNNNNNNNNNNN", "03", 0) res = game_data.GameData(merels.get_game_data("test")) self.assertEqual(res.board, "XXXNNNNOOOOONNNNNNNNNNNN") self.assertEqual(res.get_phase(), 3)
def setUp(self): self.storage = SimpleStorage() self.merels = database.MerelsStorage(self.storage)