def test_points_to_segment_display_string_one_person_round(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.ACTION, Action.CONFIRM) ] * 3 game = GameX01(1, TestingPoller(evs), RENDERER) self.assertEqual(game._GameX01__points_to_string(), "501") game.loop() self.assertEqual(game._GameX01__points_to_string(), "498")
def test_score_display_triple(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 5), Event(EventType.ACTION, Action.TRIPLE) ] game = Cricket(1, TestingPoller(evs), RENDERER) game.loop() self.assertEqual("15t thr1", RENDERER.segment_text)
def test_game_over(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 5), Event(EventType.ACTION, Action.CONFIRM), ] game = Cricket(1, TestingPoller(evs * 6), RENDERER) self.assertFalse(game.over()) game.loop() self.assertFalse(game.over())
def test_segment_string_digits_on_the_same_place(self): evs = [ Event(EventType.NUMBER, 2), Event(EventType.NUMBER, 0), Event(EventType.ACTION, Action.CONFIRM), ] * 3 * 7 * 2 # 3 throws per round, seven rounds so that # score is below 100 and there are two players game = GameX01(2, TestingPoller(evs), RENDERER) game.loop() self.assertEqual(game._GameX01__points_to_string(), "81 " + "81")
def test_undo_segment_string(self): evs = [ Event(EventType.NUMBER, 2), Event(EventType.NUMBER, 0), Event(EventType.ACTION, Action.CONFIRM), Event(EventType.ACTION, Action.UNDO) ] game = GameX01(1, TestingPoller(evs), RENDERER) game.loop() self.assertEqual(game._GameX01__points_to_string(), "501")
def test_undo_game_logic(self): evs = [ Event(EventType.NUMBER, 2), Event(EventType.NUMBER, 0), Event(EventType.ACTION, Action.CONFIRM), Event(EventType.ACTION, Action.UNDO) ] game = GameX01(1, TestingPoller(evs), RENDERER) game.loop() self.assertEqual(game.players[0], 501)
def test_restart(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.ACTION, Action.CONFIRM), Event(EventType.ACTION, Action.RESTART) ] game = GameX01(1, TestingPoller(evs), RENDERER) self.assertFalse(game.over()) game.loop() self.assertTrue(game.over())
def test_two_rounds(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 0), Event(EventType.ACTION, Action.CONFIRM), ] game = GameX01(1, TestingPoller(evs * 6), RENDERER) self.assertEqual(game.players[0], 501) game.loop() self.assertEqual(game.players[0], 441)
def test_segment_string_digits_on_the_same_place_player_with_even_index( self): evs = [ Event(EventType.NUMBER, 2), Event(EventType.NUMBER, 0), Event(EventType.ACTION, Action.CONFIRM), ] * (3 * 7 * 2 - 1) game = GameX01(2, TestingPoller(evs), RENDERER) game.loop() self.assertEqual(game._GameX01__points_to_string(), "81 " + "101")
def test_do_not_display_already_thrown_right_edge(self): evs = [ Event(EventType.NUMBER, 2), Event(EventType.NUMBER, 5), Event(EventType.ACTION, Action.DOUBLE), Event(EventType.ACTION, Action.CONFIRM) ] * 2 game = Cricket(1, TestingPoller(evs), RENDERER) game.loop() self.assertEqual("151617 1819 20 ", RENDERER.lcd_first_line) self.assertEqual(" 0 0 0 0 0 0 ", RENDERER.lcd_second_line)
def test_do_not_display_already_thrown_middle_other_side(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 7), Event(EventType.ACTION, Action.TRIPLE), Event(EventType.ACTION, Action.CONFIRM) ] game = Cricket(1, TestingPoller(evs), RENDERER) game.loop() self.assertEqual("1516 1819 2025", RENDERER.lcd_first_line) self.assertEqual(" 0 0 0 0 0 0", RENDERER.lcd_second_line)
def test_single_score(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 0), Event(EventType.ACTION, Action.CONFIRM) ] game = GameX01(1, TestingPoller(evs), RENDERER) self.assertEqual(game.players[0], 501) game.loop() # Points are ONLY subtracted iff the round is over. self.assertEqual(game.players[0], 501)
def test_points_to_segment_display_string_four_people(self): evs = [] for i in range(1, 5): evs += [ Event(EventType.NUMBER, i), Event(EventType.ACTION, Action.CONFIRM) ] * 3 game = GameX01(4, TestingPoller(evs), RENDERER) self.assertEqual(game._GameX01__points_to_string(), "501 501") game.loop() self.assertEqual(game._GameX01__points_to_string(), "498 495") self.assertEqual(game.players, [498, 495, 492, 489])
def test_points_to_segment_display_string_three_people_two_rounds(self): evs = [] for i in range(1, 3): evs += [ Event(EventType.NUMBER, i), Event(EventType.ACTION, Action.CONFIRM) ] * 3 game = GameX01(3, TestingPoller(evs), RENDERER) self.assertEqual(game._GameX01__points_to_string(), "501 501") game.loop() self.assertEqual(game._GameX01__points_to_string(), "501") self.assertEqual(game.players, [498, 495, 501])
def test_overthrow_after_ninth(self): evs = [ Event(EventType.NUMBER, 2), Event(EventType.NUMBER, 0), Event(EventType.ACTION, Action.TRIPLE), Event(EventType.ACTION, Action.CONFIRM) ] * 9 game = GameX01(1, TestingPoller(evs), RENDERER) self.assertEqual(game.players[0], 501) game.loop() self.assertEqual(game.players[0], 501 - 3 * 20 * 6) self.assertFalse(game.over())
def test_score_overflow_second(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 5), Event(EventType.ACTION, Action.DOUBLE), Event(EventType.ACTION, Action.CONFIRM) ] * 3 game = Cricket(1, TestingPoller(evs), RENDERER) expected = cricket_score_init() game.loop() expected[15] = 3 self.assertEqual(game.players[0], expected)
def test_single_score(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 5), Event(EventType.ACTION, Action.CONFIRM) ] game = Cricket(1, TestingPoller(evs), RENDERER) expected = cricket_score_init() self.assertEqual(game.players[0], expected) game.loop() expected[15] = 1 self.assertEqual(game.players[0], expected)
def test_two_players_logic(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 7), Event(EventType.ACTION, Action.TRIPLE), Event(EventType.ACTION, Action.CONFIRM) ] game = Cricket(2, TestingPoller(evs), RENDERER) game.loop() expected = cricket_score_init() expected[17] = 3 self.assertEqual(game.players[0], expected) self.assertEqual(game.players[1], cricket_score_init())
def test_points_to_segment_display_string_two_people(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.ACTION, Action.CONFIRM) ] * 3 evs += [ Event(EventType.NUMBER, 2), Event(EventType.ACTION, Action.CONFIRM) ] * 3 game = GameX01(2, TestingPoller(evs), RENDERER) self.assertEqual(game._GameX01__points_to_string(), "501 501") game.loop() self.assertEqual(game._GameX01__points_to_string(), "498 495")
def test_overthrow_after_eleventh(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 8), Event(EventType.ACTION, Action.TRIPLE), Event(EventType.ACTION, Action.CONFIRM) ] evs = evs * 9 evs += [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 4), Event(EventType.ACTION, Action.CONFIRM) ] evs += [ Event(EventType.NUMBER, 2), Event(EventType.ACTION, Action.CONFIRM) ] game = GameX01(1, TestingPoller(evs), RENDERER) self.assertEqual(game.players[0], 501) game.loop() self.assertEqual(game.players[0], 501 - 3 * 18 * 9)
def test_score_display_segment(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 5), Event(EventType.ACTION, Action.DOUBLE), Event(EventType.ACTION, Action.CONFIRM) ] * 2 evs += [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 5) ] game = Cricket(1, TestingPoller(evs), RENDERER) game.loop() self.assertEqual("15 thr3", RENDERER.segment_text)
def test_two_players_display_one_whole_round(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 7), Event(EventType.ACTION, Action.CONFIRM) ] * 3 evs += [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 6), Event(EventType.ACTION, Action.CONFIRM) ] * 3 game = Cricket(2, TestingPoller(evs), RENDERER) game.loop() self.assertEqual("1516 1819 2025", RENDERER.lcd_first_line) self.assertEqual(" 0 0 0 0 0 0", RENDERER.lcd_second_line)
def test_two_players_display(self): evs = [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 7), Event(EventType.ACTION, Action.CONFIRM), ] * 3 evs += [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 6), Event(EventType.ACTION, Action.TRIPLE) ] game = Cricket(2, TestingPoller(evs), RENDERER) game.loop() self.assertEqual("151617 1819 2025", RENDERER.lcd_first_line) self.assertEqual(" 0 0 0 0 0 0 0", RENDERER.lcd_second_line) self.assertEqual("16t thr1", RENDERER.segment_text)
def test_triple_bulls_eye_second_corner_case(self): evs = [ Event(EventType.ACTION, Action.TRIPLE), Event(EventType.NUMBER, 2), Event(EventType.NUMBER, 5), Event(EventType.ACTION, Action.CONFIRM) ] evs += [ Event(EventType.ACTION, Action.CONFIRM), Event(EventType.ACTION, Action.CONFIRM) ] game = GameX01(1, TestingPoller(evs), RENDERER) self.assertEqual(game.players[0], 501) game.loop() # Note: the first throw will be "2" since the intermediate result is not erased # so, the sequence goes like this: "T" -> "2T" -> "2T" (with the error message of "25T" of not being valid) self.assertEqual(game.players[0], 495)
def test_score_seven_finisher(self): evs = [] for i in range(5,10): evs += [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, i), Event(EventType.ACTION, Action.TRIPLE), Event(EventType.ACTION, Action.CONFIRM) ] evs += [ Event(EventType.NUMBER, 2), Event(EventType.NUMBER, 0), Event(EventType.ACTION, Action.TRIPLE), Event(EventType.ACTION, Action.CONFIRM) ] evs += [ Event(EventType.NUMBER, 2), Event(EventType.NUMBER, 5), Event(EventType.ACTION, Action.CONFIRM) ] * 3 game = Cricket(1, TestingPoller(evs), RENDERER) game.loop() self.assertTrue(game.over())
def test_game_ten_finisher(self): evs = [ Event(EventType.NUMBER, 2), Event(EventType.NUMBER, 0), Event(EventType.ACTION, Action.TRIPLE), Event(EventType.ACTION, Action.CONFIRM) ] evs = evs * 6 evs += [ Event(EventType.NUMBER, 2), Event(EventType.NUMBER, 0), Event(EventType.ACTION, Action.TRIPLE), Event(EventType.ACTION, Action.CONFIRM) ] evs += [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 9), Event(EventType.ACTION, Action.TRIPLE), Event(EventType.ACTION, Action.CONFIRM) ] # Player misses the board evs += [Event(EventType.ACTION, Action.CONFIRM)] evs += [ Event(EventType.NUMBER, 1), Event(EventType.NUMBER, 2), Event(EventType.ACTION, Action.DOUBLE), Event(EventType.ACTION, Action.CONFIRM) ] game = GameX01(1, TestingPoller(evs), RENDERER) self.assertEqual(game.players[0], 501) game.loop() self.assertEqual(game.players[0], 0) self.assertTrue(game.over())