def test_shogi_input_is_initable(self): shogi = ShogiInput.init("channel_id", [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) self.assertEqual(shogi.channel_id, "channel_id") shogi = ShogiInput.init("channel_id", [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) self.assertIsNone(shogi) ShogiInput.clear("channel_id") shogi = ShogiInput.init("channel_id", [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) self.assertEqual(shogi.channel_id, "channel_id")
def test_shogi_input_is_initable(self): shogi = ShogiInput.init("channel_id", [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", } ]) self.assertEqual(shogi.channel_id, "channel_id") shogi = ShogiInput.init("channel_id", [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", } ]) self.assertIsNone(shogi) ShogiInput.clear("channel_id") shogi = ShogiInput.init("channel_id", [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", } ]) self.assertEqual(shogi.channel_id, "channel_id")
def start_shogi(channel, message, opponent_name): slacker = message._client.webapi user = User(slacker) opponent_id = user.username_to_id(opponent_name) if opponent_id is None: # In case of mention. In mention, slack transform username to userid # like @username to <@UOIFJ83F> opponent_id = opponent_name if not user.user_in_channel(opponent_id, channel.channel_id): message.reply("Error, sorry. Opponent is not found in this channel") return shogi = ShogiInput.init(channel_id=channel.channel_id, users=[{ "id": channel.own_id, "name": user.id_to_username(channel.own_id), }, { "id": opponent_id, "name": user.id_to_username(opponent_id), }]) if shogi is None: message.reply( "Shogi started already by a user. Sorry.\nIf you want to quit shogi which already exists, please say this command `resign`" ) else: message.reply("Shogi started: " + shogi.id) board = ShogiInput.get_shogi_board(channel.channel_id) board_str = ShogiOutput.make_board_emoji(board) message.send(board_str)
def test_shogi_output_reverse_format(self): # for syntax error and runtime error channel_id = "channel_id" shogi = ShogiInput.init(channel_id, [{"id": "user1", "name": "user1name"}, {"id": "user2", "name": "user2name"}]) board = ShogiInput.get_shogi_board(channel_id) board_str = ShogiOutput.make_board_emoji_reverse(board) self.assertIsNotNone(board_str)
def test_try_to_get_shogi_board(self): channel_id = "test_try_to_get_shogi_board" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) ShogiInput.get_shogi_board(channel_id)
def test_try_to_get_shogi_board(self): channel_id = "test_try_to_get_shogi_board" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) ShogiInput.get_shogi_board(channel_id)
def test_matta_for_KomaCannotMoveException(self): channel_id = "test_matta_for_KomaCannotMoveException" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) with self.assertRaises(KomaCannotMoveException): ShogiInput.matta(channel_id, shogi.first_user.id)
def test_matta_for_KomaCannotMoveException(self): channel_id = "test_matta_for_KomaCannotMoveException" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) with self.assertRaises(KomaCannotMoveException): ShogiInput.matta(channel_id, shogi.first_user.id)
def test_move_method_should_work(self): channel_id = "test_move_method_should_work" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) ShogiInput.move("76歩", channel_id, shogi.first_user.id) self.assertEqual(shogi.board[5][2], Koma.fu)
def test_move_method_should_work(self): channel_id = "test_move_method_should_work" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) ShogiInput.move("76歩", channel_id, shogi.first_user.id) self.assertEqual(shogi.board[5][2], Koma.fu)
def test_shogi_output_format(self): # for syntax error and runtime error channel_id = "channel_id" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name" }, { "id": "user2", "name": "user2name" }]) board = ShogiInput.get_shogi_board(channel_id) board_str = ShogiOutput.make_board_emoji(board) self.assertIsNotNone(board_str)
def test_set_any_user_validator(self): channel_id = "test_set_validotr" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) ShogiInput.move("76歩", channel_id, shogi.first_user.id) with self.assertRaises(UserDifferentException): ShogiInput.move("34歩", channel_id, shogi.first_user.id) ShogiInput.setAllMode(channel_id) ShogiInput.move("34歩", channel_id, shogi.first_user.id)
def test_move_method_should_raise_UserDifferentException(self): channel_id = "test_move_method_should_raise_UserDifferentException" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) with self.assertRaises(UserDifferentException): ShogiInput.move("76歩", channel_id, shogi.second_user.id) with self.assertRaises(UserDifferentException): ShogiInput.move("76歩", channel_id, shogi.second_user.id)
def test_set_any_user_validator(self): channel_id = "test_set_validotr" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) ShogiInput.move("76歩", channel_id, shogi.first_user.id) with self.assertRaises(UserDifferentException): ShogiInput.move("34歩", channel_id, shogi.first_user.id) ShogiInput.setAllMode(channel_id) ShogiInput.move("34歩", channel_id, shogi.first_user.id)
def test_move_method_should_raise_UserDifferentException(self): channel_id = "test_move_method_should_raise_UserDifferentException" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) with self.assertRaises(UserDifferentException): ShogiInput.move("76歩", channel_id, shogi.second_user.id) with self.assertRaises(UserDifferentException): ShogiInput.move("76歩", channel_id, shogi.second_user.id)
def test_matta(self): channel_id = "test_matta" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) ShogiInput.move("76歩", channel_id, shogi.first_user.id) self.assertEqual(shogi.board[5][2], Koma.fu) ShogiInput.matta(channel_id, shogi.second_user.id) self.assertEqual(shogi.board[5][2], Koma.empty) ShogiInput.move("76歩", channel_id, shogi.first_user.id) self.assertEqual(shogi.board[5][2], Koma.fu)
def test_matta(self): channel_id = "test_matta" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) ShogiInput.move("76歩", channel_id, shogi.first_user.id) self.assertEqual(shogi.board[5][2], Koma.fu) ShogiInput.matta(channel_id, shogi.second_user.id) self.assertEqual(shogi.board[5][2], Koma.empty) ShogiInput.move("76歩", channel_id, shogi.first_user.id) self.assertEqual(shogi.board[5][2], Koma.fu)
def test_matta_for_UserDifferentException(self): channel_id = "test_matta_for_UserDifferentException" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) ShogiInput.move("76歩", channel_id, shogi.first_user.id) self.assertEqual(shogi.board[5][2], Koma.fu) with self.assertRaises(UserDifferentException): ShogiInput.matta(channel_id, shogi.first_user.id) ShogiInput.move("34歩", channel_id, shogi.second_user.id) with self.assertRaises(UserDifferentException): ShogiInput.matta(channel_id, shogi.second_user.id)
def test_matta_for_UserDifferentException(self): channel_id = "test_matta_for_UserDifferentException" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) ShogiInput.move("76歩", channel_id, shogi.first_user.id) self.assertEqual(shogi.board[5][2], Koma.fu) with self.assertRaises(UserDifferentException): ShogiInput.matta(channel_id, shogi.first_user.id) ShogiInput.move("34歩", channel_id, shogi.second_user.id) with self.assertRaises(UserDifferentException): ShogiInput.matta(channel_id, shogi.second_user.id)
def test_move_method_should_raise_KomaCannotMoveException(self): channel_id = "test_move_method_should_raise_KomaCannotMoveException" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) with self.assertRaises(KomaCannotMoveException): ShogiInput.move("75歩", channel_id, shogi.first_user.id) with self.assertRaises(KomaCannotMoveException): ShogiInput.move("34歩", channel_id, shogi.first_user.id) with self.assertRaises(KomaCannotMoveException): ShogiInput.move("15151歩", channel_id, shogi.first_user.id) with self.assertRaises(KomaCannotMoveException): ShogiInput.move("Wow, it's great.", channel_id, shogi.first_user.id)
def test_move_method_should_raise_KomaCannotMoveException(self): channel_id = "test_move_method_should_raise_KomaCannotMoveException" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) with self.assertRaises(KomaCannotMoveException): ShogiInput.move("75歩", channel_id, shogi.first_user.id) with self.assertRaises(KomaCannotMoveException): ShogiInput.move("34歩", channel_id, shogi.first_user.id) with self.assertRaises(KomaCannotMoveException): ShogiInput.move("15151歩", channel_id, shogi.first_user.id) with self.assertRaises(KomaCannotMoveException): ShogiInput.move("Wow, it's great.", channel_id, shogi.first_user.id)
def test_matta_for_drop_komas(self): channel_id = "test_matta_for_da_komas" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) ShogiInput.move("76歩", channel_id, shogi.first_user.id) ShogiInput.move("34歩", channel_id, shogi.second_user.id) ShogiInput.move("22角", channel_id, shogi.first_user.id) ShogiInput.move("同銀", channel_id, shogi.second_user.id) ShogiInput.move("55角打", channel_id, shogi.first_user.id) ShogiInput.move("33角打", channel_id, shogi.second_user.id) ShogiInput.matta(channel_id, shogi.first_user.id) ShogiInput.matta(channel_id, shogi.second_user.id) ShogiInput.move("55角打", channel_id, shogi.first_user.id) ShogiInput.move("33角打", channel_id, shogi.second_user.id) self.assertEqual(shogi.board[4][4], Koma.kaku) self.assertEqual(shogi.board[2][6], Koma.opponent_kaku)
def test_matta_for_drop_komas(self): channel_id = "test_matta_for_da_komas" shogi = ShogiInput.init(channel_id, [{ "id": "user1", "name": "user1name", }, { "id": "user2", "name": "user2name", }]) ShogiInput.move("76歩", channel_id, shogi.first_user.id) ShogiInput.move("34歩", channel_id, shogi.second_user.id) ShogiInput.move("22角", channel_id, shogi.first_user.id) ShogiInput.move("同銀", channel_id, shogi.second_user.id) ShogiInput.move("55角打", channel_id, shogi.first_user.id) ShogiInput.move("33角打", channel_id, shogi.second_user.id) ShogiInput.matta(channel_id, shogi.first_user.id) ShogiInput.matta(channel_id, shogi.second_user.id) ShogiInput.move("55角打", channel_id, shogi.first_user.id) ShogiInput.move("33角打", channel_id, shogi.second_user.id) self.assertEqual(shogi.board[4][4], Koma.kaku) self.assertEqual(shogi.board[2][6], Koma.opponent_kaku)