def test_is_rank_higher(self): world = WorldWatten() world.refresh() # weli played self.assertFalse(world.is_rank_higher(8, 0)) self.assertFalse(world.is_rank_higher(8, 1)) self.assertFalse(world.is_rank_higher(8, 2)) self.assertFalse(world.is_rank_higher(8, 3)) self.assertFalse(world.is_rank_higher(8, 4)) self.assertFalse(world.is_rank_higher(8, 5)) self.assertFalse(world.is_rank_higher(8, 6)) self.assertFalse(world.is_rank_higher(8, 7)) self.assertTrue(world.is_rank_higher(0, 8)) self.assertTrue(world.is_rank_higher(1, 8)) self.assertTrue(world.is_rank_higher(2, 8)) self.assertTrue(world.is_rank_higher(3, 8)) self.assertTrue(world.is_rank_higher(4, 8)) self.assertTrue(world.is_rank_higher(5, 8)) self.assertTrue(world.is_rank_higher(6, 8)) self.assertTrue(world.is_rank_higher(7, 8)) self.assertTrue(world.is_rank_higher(3, 8)) # not weli self.assertTrue(world.is_rank_higher(6, 5)) self.assertTrue(world.is_rank_higher(7, 1)) self.assertFalse(world.is_rank_higher(1, 4)) self.assertFalse(world.is_rank_higher(3, 6)) self.assertFalse(world.is_rank_higher(4, 6)) self.assertFalse(world.is_rank_higher(5, 6))
def test_get_valid_moves_declare_rank(self): world = WorldWatten() world.refresh() # opponent player declare the rank # valid moves: ALL RANKS + RAISE POINTS valid_moves = world.get_valid_moves() self.assertEqual([33, 34, 35, 36, 37, 38, 39, 40, 41, 46], valid_moves)
def test_is_won(self): world = WorldWatten() world.refresh() world.player_A_score = 15 result = world.is_won(-1) self.assertTrue(result) world.refresh() world.player_A_score = 15 world.player_B_score = 15 self.assertRaises(InconsistentStateError, world.is_won, 1) world.refresh() world.player_B_score = 15 result = world.is_won(-1) self.assertFalse(result) world.refresh() world.player_B_score = 15 result = world.is_won(1) self.assertTrue(result)
def test_get_valid_moves_declare_suit_rank_weli(self): world = WorldWatten() world.refresh() # when the chosen rank is weli, suit is automatically world.rank = 8 world.suit = 3 # opponent player declare the rank valid_moves = world.get_valid_moves() # if picked rank is weli, then it doesn't matter to declare a suit self.assertEqual(len(valid_moves), 6)
def test_compare_cards_first_is_trumpfe(self): world = WorldWatten() world.refresh() # only the first card is trümpfe world.rank = 4 world.suit = 2 card_id_one = watten.get_id(3, 2) card_id_two = watten.get_id(5, 1) self.assertTrue(world.compare_cards(card_id_one, card_id_two)) world.rank = 6 world.suit = 1 card_id_one = watten.get_id(4, 1) card_id_two = watten.get_id(7, 0) self.assertTrue(world.compare_cards(card_id_one, card_id_two)) # both cards are trümpfe world.rank = 4 world.suit = 2 card_id_one = watten.get_id(6, 2) card_id_two = watten.get_id(5, 2) self.assertTrue(world.compare_cards(card_id_one, card_id_two)) self.assertFalse(world.compare_cards(card_id_two, card_id_one)) world.rank = 7 world.suit = 1 card_id_one = watten.get_id(5, 1) card_id_two = watten.get_id(6, 1) self.assertFalse(world.compare_cards(card_id_one, card_id_two)) self.assertTrue(world.compare_cards(card_id_two, card_id_one)) world.rank = 8 world.suit = 3 card_id_one = watten.get_id(8, 3) card_id_two = watten.get_id(2, 1) self.assertTrue(world.compare_cards(card_id_one, card_id_two))
def test_compare_cards_no_trumpfe(self): world = WorldWatten() world.refresh() # different suit world.rank = 6 world.suit = 1 card_id_one = watten.get_id(5, 2) card_id_two = watten.get_id(3, 0) self.assertTrue(world.compare_cards(card_id_one, card_id_two)) self.assertTrue(world.compare_cards(card_id_two, card_id_one)) world.rank = 4 world.suit = 0 card_id_one = watten.get_id(6, 1) card_id_two = watten.get_id(7, 2) self.assertTrue(world.compare_cards(card_id_one, card_id_two)) self.assertTrue(world.compare_cards(card_id_two, card_id_one)) # same suit world.rank = 7 world.suit = 2 card_id_one = watten.get_id(5, 1) card_id_two = watten.get_id(3, 1) self.assertTrue(world.compare_cards(card_id_one, card_id_two)) self.assertFalse(world.compare_cards(card_id_two, card_id_one)) world.rank = 4 world.suit = 0 card_id_one = watten.get_id(1, 3) card_id_two = watten.get_id(5, 3) self.assertFalse(world.compare_cards(card_id_one, card_id_two)) self.assertTrue(world.compare_cards(card_id_two, card_id_one))
def test_compare_cards_blinde(self): world = WorldWatten() world.refresh() world.rank = 4 world.suit = 2 card_id_one = watten.get_id(8, 3) card_id_two = watten.get_id(4, 1) self.assertFalse(world.compare_cards(card_id_one, card_id_two)) self.assertTrue(world.compare_cards(card_id_two, card_id_one)) world.rank = 5 world.suit = 1 card_id_one = watten.get_id(5, 3) card_id_two = watten.get_id(5, 1) self.assertFalse(world.compare_cards(card_id_one, card_id_two)) self.assertTrue(world.compare_cards(card_id_two, card_id_one)) world.rank = 8 world.suit = 3 card_id_one = watten.get_id(8, 3) card_id_two = watten.get_id(5, 1) self.assertTrue(world.compare_cards(card_id_one, card_id_two)) self.assertFalse(world.compare_cards(card_id_two, card_id_one)) world.rank = 4 world.suit = 0 card_id_one = watten.get_id(3, 0) card_id_two = watten.get_id(4, 1) self.assertFalse(world.compare_cards(card_id_one, card_id_two)) self.assertTrue(world.compare_cards(card_id_two, card_id_one))
def test_compare_cards_second_is_trumpfe(self): world = WorldWatten() world.refresh() world.rank = 4 world.suit = 2 card_id_one = watten.get_id(3, 1) card_id_two = watten.get_id(5, 2) self.assertFalse(world.compare_cards(card_id_one, card_id_two)) world.rank = 7 world.suit = 1 card_id_one = watten.get_id(6, 3) card_id_two = watten.get_id(0, 1) self.assertFalse(world.compare_cards(card_id_one, card_id_two)) world.rank = 8 world.suit = 3 card_id_one = watten.get_id(2, 1) card_id_two = watten.get_id(8, 3) self.assertFalse(world.compare_cards(card_id_one, card_id_two)) world.rank = 2 world.suit = 3 card_id_one = watten.get_id(4, 3) card_id_two = watten.get_id(8, 3) self.assertTrue(world.compare_cards(card_id_one, card_id_two))
def test_is_game_end(self): world = WorldWatten() world.refresh() result = world.is_game_end() self.assertFalse(result) world.player_A_score = 15 result = world.is_game_end() self.assertTrue(result) world.refresh() world.player_B_score = 13 result = world.is_game_end() self.assertFalse(result) world.refresh() world.player_B_score = 18 result = world.is_game_end() self.assertTrue(result)