Skip to content

Commit 37206db

Browse files
neiljptimabbott
authored andcommitted
TicTacToe tests: Improve test coverage.
1 parent b3fc7ed commit 37206db

File tree

1 file changed

+57
-9
lines changed

1 file changed

+57
-9
lines changed

zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,65 @@ def test_bot(self):
2828
'subject': '[email protected]', # FIXME Requiring this in bot is a bug?
2929
}
3030

31-
help_txt = "*Help for Tic-Tac-Toe bot* \nThe bot responds to messages starting with @mention-bot.\n**@mention-bot new** will start a new game (but not if you're already in the middle of a game). You must type this first to start playing!\n**@mention-bot help** will return this help function.\n**@mention-bot quit** will quit from the current game.\n**@mention-bot <coordinate>** will make a move at the given coordinate.\nCoordinates are entered in a (row, column) format. Numbering is from top to bottom and left to right. \nHere are the coordinates of each position. (Parentheses and spaces are optional). \n(1, 1) (1, 2) (1, 3) \n(2, 1) (2, 2) (2, 3) \n(3, 1) (3, 2) (3, 3) \n"
32-
didnt_understand_txt = "Hmm, I didn't understand your input. Type **@tictactoe help** or **@ttt help** to see valid inputs."
33-
new_game_txt = "Welcome to tic-tac-toe! You'll be x's and I'll be o's. Your move first!\nCoordinates are entered in a (row, column) format. Numbering is from top to bottom and left to right.\nHere are the coordinates of each position. (Parentheses and spaces are optional.) \n(1, 1) (1, 2) (1, 3) \n(2, 1) (2, 2) (2, 3) \n(3, 1) (3, 2) (3, 3) \n Your move would be one of these. To make a move, type @mention-bot followed by a space and the coordinate."
31+
msg = dict(
32+
help = "*Help for Tic-Tac-Toe bot* \nThe bot responds to messages starting with @mention-bot.\n**@mention-bot new** will start a new game (but not if you're already in the middle of a game). You must type this first to start playing!\n**@mention-bot help** will return this help function.\n**@mention-bot quit** will quit from the current game.\n**@mention-bot <coordinate>** will make a move at the given coordinate.\nCoordinates are entered in a (row, column) format. Numbering is from top to bottom and left to right. \nHere are the coordinates of each position. (Parentheses and spaces are optional). \n(1, 1) (1, 2) (1, 3) \n(2, 1) (2, 2) (2, 3) \n(3, 1) (3, 2) (3, 3) \n",
33+
didnt_understand = "Hmm, I didn't understand your input. Type **@tictactoe help** or **@ttt help** to see valid inputs.",
34+
new_game = "Welcome to tic-tac-toe! You'll be x's and I'll be o's. Your move first!\nCoordinates are entered in a (row, column) format. Numbering is from top to bottom and left to right.\nHere are the coordinates of each position. (Parentheses and spaces are optional.) \n(1, 1) (1, 2) (1, 3) \n(2, 1) (2, 2) (2, 3) \n(3, 1) (3, 2) (3, 3) \n Your move would be one of these. To make a move, type @mention-bot followed by a space and the coordinate.",
35+
already_playing = "You're already playing a game! Type **@tictactoe help** or **@ttt help** to see valid inputs.",
36+
already_played_there = 'That space is already filled, sorry!',
37+
successful_quit = "You've successfully quit the game.",
38+
after_1_1 = ("[ x _ _ ]\n[ _ _ _ ]\n[ _ _ _ ]\n"
39+
"My turn:\n[ x _ _ ]\n[ _ o _ ]\n[ _ _ _ ]\n"
40+
"Your turn! Enter a coordinate or type help."),
41+
after_2_1 = ("[ x _ _ ]\n[ x o _ ]\n[ _ _ _ ]\n"
42+
"My turn:\n[ x _ _ ]\n[ x o _ ]\n[ o _ _ ]\n"
43+
"Your turn! Enter a coordinate or type help."),
44+
after_1_3 = ("[ x _ x ]\n[ x o _ ]\n[ o _ _ ]\n"
45+
"My turn:\n[ x o x ]\n[ x o _ ]\n[ o _ _ ]\n"
46+
"Your turn! Enter a coordinate or type help."),
47+
after_3_2 = ("[ x o x ]\n[ x o _ ]\n[ o x _ ]\n"
48+
"My turn:\n[ x o x ]\n[ x o o ]\n[ o x _ ]\n"
49+
"Your turn! Enter a coordinate or type help."),
50+
)
3451

3552
expected_send_message = [
36-
("", didnt_understand_txt),
37-
("help", help_txt),
38-
("quit", didnt_understand_txt), # Quit not understood when no game
39-
("new", new_game_txt),
40-
("quit", "You've successfully quit the game."), # If have state
41-
("quit", didnt_understand_txt), # Quit not understood when no game
53+
# Empty message
54+
("", msg['didnt_understand']),
55+
# Non-command
56+
("adboh", msg['didnt_understand']),
57+
# Help command
58+
("help", msg['help']),
59+
# Command: quit not understood with no game
60+
("quit", msg['didnt_understand']),
61+
# Can quit if new game and have state
62+
("new", msg['new_game']),
63+
("quit", msg['successful_quit']),
64+
# Quit not understood when no game FIXME improve response?
65+
("quit", msg['didnt_understand']),
66+
# New right after new just restarts
67+
("new", msg['new_game']),
68+
("new", msg['new_game']),
69+
# Make a corner play
70+
("(1,1)", msg['after_1_1']),
71+
# New while playing doesn't just restart
72+
("new", msg['already_playing']),
73+
# User played in this location already
74+
("(1,1)", msg['already_played_there']),
75+
# ... and bot played here
76+
("(2,2)", msg['already_played_there']),
77+
("quit", msg['successful_quit']),
78+
# Can't play without game FIXME improve response?
79+
("(1,1)", msg['didnt_understand']),
80+
("new", msg['new_game']),
81+
# Value out of range FIXME improve response?
82+
("(1,5)", msg['didnt_understand']),
83+
# Value out of range FIXME improve response?
84+
("0,1", msg['didnt_understand']),
85+
# Sequence of moves to show valid input formats:
86+
("1,1", msg['after_1_1']),
87+
("2, 1", msg['after_2_1']),
88+
("(1,3)", msg['after_1_3']),
89+
# Can't test 'after_3_2' as it's random!
4290
]
4391
for m in messages:
4492
state = StateHandler()

0 commit comments

Comments
 (0)