def test_list_greater(): try: Commons.list_greater([1] * 3, [1] * 5) assert ( False ), "Function should throw an error if given 2 lists of unequal length." except ValueError: pass assert Commons.list_greater([5, 2, 1], [4, 2, 1]) assert not Commons.list_greater([4, 2, 1], [5, 2, 1]) assert Commons.list_greater([5, 2, 1], [4, 7, 9]) assert not Commons.list_greater([4, 7, 9], [5, 2, 1]) assert Commons.list_greater([1, 0, 0], [0, 9, 9]) assert not Commons.list_greater([0, 9, 9], [1, 0, 0]) assert Commons.list_greater([5, 3, 6], [5, 2, 6]) assert not Commons.list_greater([5, 2, 6], [5, 3, 6]) assert Commons.list_greater([5, 3, 6], [5, 3, 5]) assert not Commons.list_greater([5, 3, 5], [5, 3, 6]) assert Commons.list_greater([1, 2, 3, 4, 5, 6, 7, 8, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9]) assert not Commons.list_greater([1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 10]) assert Commons.list_greater([1], [1]) is None assert Commons.list_greater([5, 2, 1], [5, 2, 1]) is None assert (Commons.list_greater([1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9]) is None)
def poker_beats(self, other_hand): """ Compares hand with another hand, to see if this hand beats the other at poker. Returns true, false or none. """ # Check if either hand is a royal flush if self.is_royal_flush(): if other_hand.is_royal_flush(): return None return True if other_hand.is_royal_flush(): return False # Check if either hand is a straight flush straight_flush = self.is_straight_flush() other_straight_flush = other_hand.is_straight_flush() if straight_flush: if not other_straight_flush: return True if straight_flush == other_straight_flush: return None return straight_flush > other_straight_flush if other_straight_flush: return False # Check if either hand is four of a kind four_of_a_kind = self.is_four_of_a_kind() other_four_of_a_kind = other_hand.is_four_of_a_kind() if four_of_a_kind: if not other_four_of_a_kind: return True return Commons.list_greater(four_of_a_kind, other_four_of_a_kind) if other_four_of_a_kind: return False # Check if either hand is a full house full_house = self.is_full_house() other_full_house = other_hand.is_full_house() if full_house: if not other_full_house: return True return Commons.list_greater(full_house, other_full_house) if other_full_house: return False # Check if either hand is a flush flush = self.is_flush() other_flush = other_hand.is_flush() if flush: if not other_flush: return True return flush > other_flush if other_flush: return False # Check if either hand is a straight straight = self.is_straight() other_straight = other_hand.is_straight() if straight: if not other_straight: return True return straight > other_straight if other_straight: return False # Check if either hand is 3 of a kind three_of_a_kind = self.is_three_of_a_kind() other_three_of_a_kind = other_hand.is_three_of_a_kind() if three_of_a_kind: if not other_three_of_a_kind: return True return Commons.list_greater(three_of_a_kind, other_three_of_a_kind) if other_three_of_a_kind: return False # Check if either hand is 2 pairs two_pairs = self.is_two_pairs() other_two_pairs = other_hand.is_two_pairs() if two_pairs: if not other_two_pairs: return True return Commons.list_greater(two_pairs, other_two_pairs) if other_two_pairs: return False # Check if either hand is 1 paid one_pair = self.is_one_pair() other_one_pair = other_hand.is_one_pair() if one_pair: if not other_one_pair: return True return Commons.list_greater(one_pair, other_one_pair) if other_one_pair: return False # Compare by high card high_card = self.poker_high_card() other_high_card = other_hand.poker_high_card() return Commons.list_greater(high_card, other_high_card)