# cardtest.py # Lillian Lee (LJL2) and Steve Marschner (SRM2) # Feb 22, 2014 """Module for testing some functions in card""" import cornelltest import cardstuff def test_equals(): """Quick diagnostic for whether card equality seems to be working""" c = cardstuff.Card(3,4) d = cardstuff.Card(3,5) e = cardstuff.Card(3,4) cornelltest.assert_true(c==e) cornelltest.assert_true(d==d) cornelltest.assert_true(not c == d) print "finished test of card equality" def test_print_cards(): """Quick diagnostic test whether print_cards seems to be working""" clist = [cardstuff.Card(1,11), cardstuff.Card(3,1)] print 'about to print out a list of two cards using cardstuff.print_cards...\n' cardstuff.print_cards(clist) print '\nshould have seen...\nJack of Diamonds\nAce of Spades' print ("finished test of print_cards, BUT YOU HAVE TO CHECK IF THE OUTPUT" + " WAS RIGHT\n") def test_draw(): """Quick diagnostic test of whether draw seems to be working. May depend on equality being correct for cards""" clist = [cardstuff.Card(1,11)] hand = [cardstuff.Card(2,3)] hand.append(cardstuff.draw(clist)) cornelltest.assert_equals(0,len(clist)) cornelltest.assert_equals(2,len(hand)) cornelltest.assert_true(cardstuff.Card(2,3) in hand) cornelltest.assert_true(cardstuff.Card(1,11) in hand) clist = cardstuff.full_deck() hand.append(cardstuff.draw(clist)) cornelltest.assert_equals(51, len(clist)) cornelltest.assert_equals(3,len(hand)) print "finished test of test_draw()" def test_compare(): """Test cardstuff.poker_compare""" # we don't guarantee that this is a thorough set of test cases cornelltest.assert_equals(-1, cardstuff.poker_compare(cardstuff.Card(2,10),cardstuff.Card(2,11))) cornelltest.assert_equals(-1, cardstuff.poker_compare(cardstuff.Card(3,10),cardstuff.Card(2,11))) cornelltest.assert_equals(1, cardstuff.poker_compare(cardstuff.Card(2,13),cardstuff.Card(2,11))) cornelltest.assert_equals(1, cardstuff.poker_compare(cardstuff.Card(3,10),cardstuff.Card(2,1))) cornelltest.assert_equals(0, cardstuff.poker_compare(cardstuff.Card(3,10),cardstuff.Card(3,10))) cornelltest.assert_equals(-1, cardstuff.poker_compare(cardstuff.Card(3,2), cardstuff.Card(2,3))) print "finished test of cardstuff.poker_compare" def test_draw_poker_hand(): fd = cardstuff.full_deck() hand = cardstuff.draw_poker_hand(fd) print 'Drawing a poker hand. It is:\n', cardstuff.print_cards(hand) # check that we got five cards cornelltest.assert_equals(5, len(hand)) # check that 5 cards were removed from the deck cornelltest.assert_equals(52-5, len(fd)) # check that none of the cards in the hand are in the deck for c in hand: cornelltest.assert_true(not c in fd) # check that the cards in the hand are all different for cindex in range(5): for compareindex in range(cindex+1,5): cornelltest.assert_false(hand[cindex] == hand[compareindex]) print ("\nfinished test of draw_poker_hand") if __name__ == '__main__': test_equals() test_print_cards() test_draw() test_compare() test_draw_poker_hand() print 'All test cases for cardstuff passed'