def test_pair(self): d = self.d hand = Hand.get_pair([d.hk, d.ck, d.dq, d.dj, d.da]) assert(hand is not None and hand.category == Hand.PAIR) hand = Hand.get_pair([d.hk, d.ck, d.dk, d.dq, d.da]) assert(hand is not None and hand.category == Hand.PAIR) hand = Hand.get_pair([d.h5, d.hq, d.d3, d.d2, d.s6]) assert (hand is None)
def test_flush(self): d = self.d hand = Hand.get_flush([d.dk, d.d5, d.d9, d.dq, d.da]) assert(hand is not None and hand.category == Hand.FLUSH) hand = Hand.get_flush([d.dk, d.c8, d.s9, d.dq, d.d6]) assert(hand is None) hand = Hand.get_flush([d.d5, d.dk, d.da, d.dt, d.d9]) assert(hand is not None and hand.category == Hand.FLUSH)
def test_straightflush_compare(self): d = self.d # d7 d9 dt d5 d3 : d4 d6 : d8 dj straightflush1 = Hand.get_straightflush([d.d4, d.d6, d.d7, d.d5, d.d3]) straightflush2 = Hand.get_straightflush([d.d8, d.dj, d.d7, d.d9, d.dt]) assert(straightflush1 is not None) assert(straightflush1 < straightflush2) assert(straightflush2 > straightflush1)
def test_straight(self): d = self.d hand = Hand.get_straight([d.hk, d.sa, d.dj, d.dt, d.dq]) assert(hand is not None and hand.category == Hand.STRAIGHT) hand = Hand.get_straight([d.hk, d.sa, d.d9, d.dt, d.dq]) assert(hand is None) hand = Hand.get_straight([d.ha, d.d3, d.d2, d.d4, d.c5]) assert(hand is not None and hand.category == Hand.STRAIGHT)
def test_twopair(self): d = self.d hand = Hand.get_twopair([d.hk, d.ck, d.dq, d.sq, d.hj]) assert(hand is not None and hand.category == Hand.TWOPAIR) hand = Hand.get_twopair([d.ht, d.cq, d.dq, d.dj, d.dt]) assert(hand is not None and hand.category == Hand.TWOPAIR) hand = Hand.get_twopair([d.st, d.sq, d.ct, d.cj, d.ck]) assert(hand is None)
def test_pair_compare(self): d = self.d pair1 = Hand.get_pair([d.cj, d.h6, d.h8, d.sj, d.d7]) pair2 = Hand.get_pair([d.ck, d.d8, d.h8, d.sj, d.d7]) pair3 = Hand.get_pair([d.c9, d.c8, d.h8, d.sj, d.d7]) assert(pair1 is not None) assert(pair1 > pair2 and pair2 < pair1) assert(pair2 > pair3 and pair3 < pair2) assert(pair1 > pair3 and pair3 < pair1)
def test_highcard_compare(self): d = self.d highcard1 = Hand.get_highcard([d.h8, d.cj, d.ck, d.d9, d.d7]) highcard2 = Hand.get_highcard([d.c8, d.d5, d.ck, d.d9, d.d7]) highcard3 = Hand.get_highcard([d.ca, d.dj, d.ck, d.d9, d.d7]) assert(highcard1 is not None) assert(highcard1 > highcard2 and highcard2 < highcard1) assert(highcard2 < highcard3 and highcard3 > highcard2) assert(highcard3 > highcard1 and highcard1 < highcard3)
def test_fullhouse_compare(self): d = self.d # d7 c9 c7 s9 ca : da sa : s7 sj : d9 c2 fullhouse1 = Hand.get_fullhouse([d.da, d.sa, d.c9, d.s9, d.ca]) fullhouse2 = Hand.get_fullhouse([d.s7, d.d7, d.c9, d.c7, d.s9]) fullhouse3 = Hand.get_fullhouse([d.d9, d.d7, d.c9, d.c7, d.s9]) assert(fullhouse1 is not None) assert(fullhouse1 > fullhouse2 and fullhouse2 < fullhouse1) assert(fullhouse2 < fullhouse3 and fullhouse3 > fullhouse2) assert(fullhouse3 < fullhouse1 and fullhouse1 > fullhouse3)
def test_flush_compare(self): d = self.d # d3 c8 dk d4 sa : d2 d9 : d6 d5 : dj dt flush1 = Hand.get_flush([d.d2, d.d9, d.d3, d.dk, d.d4]) flush2 = Hand.get_flush([d.d6, d.d5, d.d3, d.dk, d.d4]) flush3 = Hand.get_flush([d.dj, d.dt, d.d3, d.dk, d.d4]) assert(flush1 is not None) assert(flush1 > flush2 and flush2 < flush1) assert(flush2 < flush3 and flush3 > flush2) assert(flush1 < flush3 and flush3 > flush1)
def test_threeofakind_compare(self): d = self.d # c5 d5 dj ca s3 - s5 s7 - sj cj - h5 ck trip1 = Hand.get_threeofakind([d.s5, d.c5, d.d5, d.dj, d.ca]) trip2 = Hand.get_threeofakind([d.sj, d.cj, d.c5, d.dj, d.ca]) trip3 = Hand.get_threeofakind([d.h5, d.ck, d.c5, d.d5, d.ca]) assert(trip1 is not None) assert(trip1 < trip2 and trip2 > trip1) assert(trip2 > trip3 and trip3 < trip2) assert(trip1 < trip3 and trip3 > trip1)
def test_twopair_compare(self): d = self.d # d2 cj ck d8 s4 - c2 c8 - sj s8 - h8 s2 twopair1 = Hand.get_twopair([d.c2, d.c8, d.d2, d.ck, d.d8]) twopair2 = Hand.get_twopair([d.sj, d.s8, d.cj, d.ck, d.d8]) twopair3 = Hand.get_twopair([d.h8, d.s2, d.d2, d.ck, d.d8]) assert(twopair1 is not None) assert(twopair1 < twopair2 and twopair2 > twopair1) assert(twopair2 > twopair3 and twopair3 < twopair2) assert(twopair1 == twopair3 and twopair3 == twopair1)
def test_threeofakind(self): d = self.d hand = Hand.get_threeofakind([d.ck, d.sk, d.dk, d.d2, d.c3]) assert(hand is not None and hand.category == Hand.THREEOFAKIND) hand = Hand.get_threeofakind([d.ck, d.sk, d.d2, d.s2, d.d3]) assert(hand is None) hand = Hand.get_threeofakind([d.ck, d.sk, d.dk, d.hk, d.h3]) assert(hand is not None and hand.category == Hand.THREEOFAKIND) hand = Hand.get_threeofakind([d.hk, d.sk, d.dk, d.d2, d.s2]) assert(hand is not None and hand.category == Hand.THREEOFAKIND)
def test_fourofakind(self): d = self.d hand = Hand.get_fourofakind([d.sj, d.hj, d.dj, d.cj, d.h9]) assert(hand is not None and hand.category == Hand.FOUROFAKIND) hand = Hand.get_fourofakind([d.cj, d.dj, d.d9, d.h9, d.s9]) assert(hand is None) hand = Hand.get_fourofakind([d.c9, d.d9, d.hj, d.h9, d.s9]) assert(hand is not None and hand.category == Hand.FOUROFAKIND) hand = Hand.get_fourofakind([d.cj, d.dj, d.hj, d.h9, d.sj]) assert(hand is not None and hand.category == Hand.FOUROFAKIND) hand = Hand.get_fourofakind([d.s9, d.hj, d.h8, d.h6, d.hq]) assert(hand is None)
def test_fullhouse(self): d = self.d hand = Hand.get_fullhouse([d.dk, d.ck, d.sk, d.sj, d.cj]) assert(hand is not None and hand.category == Hand.FULLHOUSE) hand = Hand.get_fullhouse([d.dk, d.ck, d.sj, d.cj, d.ht]) assert(hand is None) hand = Hand.get_fullhouse([d.hk, d.ck, d.sk, d.dk, d.dj]) assert(hand is None) hand = Hand.get_fullhouse([d.dk, d.dj, d.cj, d.ck, d.sj]) assert(hand is not None and hand.category == Hand.FULLHOUSE) hand = Hand.get_fullhouse([d.dj, d.dk, d.cq, d.sj, d.h9]) assert(hand is None)
def test_straight_compare(self): d = self.d # c7 hj d5 dt c3 : h6 d4 : c9 s8 straight1 = Hand.get_straight([d.h6, d.d4, d.c7, d.d5, d.c3]) straight2 = Hand.get_straight([d.c9, d.s8, d.c7, d.hj, d.dt]) assert(straight1 is not None) assert(straight1 < straight2 and straight2 > straight1) # d2 c8 d4 c5 s8 : h6 h7 : sa c3 : d6 s3 straight1 = Hand.get_straight([d.h6, d.h7, d.c8, d.d4, d.c5]) straight2 = Hand.get_straight([d.sa, d.c3, d.d2, d.d4, d.c5]) straight3 = Hand.get_straight([d.d6, d.s3, d.d2, d.d4, d.c5]) assert(straight1 is not None) assert(straight1 > straight2 and straight2 < straight1) assert(straight2 < straight3 and straight3 > straight2) assert(straight3 < straight1 and straight1 > straight3)
def test_fourofakind_compare(self): d = self.d # d8 d7 h7 sj c8 : s8 h8 : s7 c7 quad1 = Hand.get_fourofakind([d.s8, d.h8, d.d8, d.sj, d.c8]) quad2 = Hand.get_fourofakind([d.s7, d.c7, d.d7, d.h7, d.sj]) assert(quad1 is not None) assert(quad1 > quad2 and quad2 < quad1) # h5 s5 d3 d5 c5 : s2 s8 : sa ca : da d9 quad1 = Hand.get_fourofakind([d.s8, d.h5, d.s5, d.d5, d.c5]) quad2 = Hand.get_fourofakind([d.sa, d.h5, d.s5, d.d5, d.c5]) quad3 = Hand.get_fourofakind([d.da, d.h5, d.s5, d.d5, d.c5]) assert(quad1 is not None) assert(quad1 < quad2 and quad2 > quad1) assert(quad2 == quad3 and quad3 == quad2) assert(quad1 < quad3 and quad3 > quad1)
def test_different_categories_compare(self): d = self.d hands = [Hand.get_highcard([d.h6, d.c9, d.d2, d.ck, d.cj]), Hand.get_pair([d.cj, d.sq, d.d2, d.c2, d.s4]), Hand.get_twopair([d.sj, d.cq, d.da, d.dq, d.hj]), Hand.get_threeofakind([d.d3, d.h8, d.c4, d.d8, d.s8]), Hand.get_straight([d.d7, d.h4, d.c5, d.c3, d.d6]), Hand.get_flush([d.h4, d.h8, d.h5, d.hq, d.h2]), Hand.get_fullhouse([d.d8, d.c8, d.s6, d.s8, d.c6]), Hand.get_fourofakind([d.h9, d.c7, d.d9, d.c9, d.s9]), Hand.get_straightflush([d.c3, d.c5, d.c4, d.c2, d.c6])] for hand in hands: assert(hand is not None) for hand1, hand2 in combinations(hands, 2): assert(hand1 < hand2) hands.reverse() for hand1, hand2 in combinations(hands, 2): assert(hand1 > hand2)
def test_straightflush(self): d = self.d hand = Hand.get_straightflush([d.sj, d.sq, d.sk, d.s9, d.st]) assert(hand is not None and hand.category == Hand.STRAIGHTFLUSH) hand = Hand.get_straightflush([d.sj, d.sk, d.sq, d.st, d.sa]) assert(hand is not None and hand.category == Hand.STRAIGHTFLUSH) hand = Hand.get_straightflush([d.sj, d.cj, d.s9, d.h9, d.hj]) assert(hand is None) hand = Hand.get_straightflush([d.c8, d.hq, d.cj, d.h9, d.st]) assert(hand is None) hand = Hand.get_straightflush([d.ha, d.cj, d.s9, d.st, d.sk]) assert(hand is None) hand = Hand.get_straightflush([d.ha, d.hj, d.h9, d.ht, d.h5]) assert(hand is None)
def test_highcard(self): d = self.d hand = Hand.get_highcard([d.hk, d.da, d.hq, d.dk, d.cj]) assert(hand is not None and hand.category == Hand.HIGHCARD)