예제 #1
0
    def testHand(self):
        """
        This method allows us to test class Hand
        """

        print("Original test")
        h1 = Hand(3)
        print(h1)
        print(h1.bjValue())
        h1.hitMe()
        print(h1)
        print(h1.bjValue())
        h2 = Hand(2)
        print(h2)
        print(h1)  # to make sure that the creation of h2 didn't effect h1

        print("More robust test")
        for test in range(20):
            size = random.randrange(-2, 20)
            tester = Hand(size)
            print("---------A hand of size: " + str(size) + "---------")
            print(tester)
            print("This hand's blackjack value: " + str(tester.bjValue()))
            print()
import random


# Testing different initial values, their output, blackjack values of hand, and hitMe() method.
if __name__ == "__main__":

    someHand = Hand(3)
    print(someHand)

    someHand = Hand(2)
    print(someHand)

    someHand = Hand(5)
    print(someHand)

    print(someHand.bjValue())
    print(someHand)

    someHand.hitMe()
    print(someHand)

"""----------------------------------------Output-------------------------------
Cards in hand: Seven of Hearts, Jack of Hearts, Jack of Clubs 
Cards in hand: Jack of Hearts, Two of Hearts 
Cards in hand: Six of Hearts, Jack of Hearts, Six of Hearts, Four of Diamonds, Five of Diamonds 
31
Cards in hand: Six of Hearts, Jack of Hearts, Six of Hearts, Four of Diamonds, Five of Diamonds 
Cards in hand: Six of Hearts, Jack of Hearts, Six of Hearts, Four of Diamonds, Five of Diamonds, Ace of Clubs 
--------------------------------------------------------------------------------
"""
예제 #3
0
from Hand import Hand
"""
Tests all the methods in class Hand.
"""
hand1 = Hand(13)
print(hand1)

print("***print for hand2.bjvalue***")
hand2 = Hand(7)
print(hand2.bjValue())

print("***print for hand3.hitme***")
hand3 = Hand(2)
hand3.hitMe()
print(hand3)

print("print for hand2 __str__method")
print(hand2.__str__())
"""
four of diamonds
two of diamonds
four of spades
Ace of diamonds
King of diamonds
eight of spades
nine of clubs
nine of diamonds
eight of spades
eight of spades
four of clubs
four of clubs
예제 #4
0
"""
Test.py
Tests that the Hand class and all its methods are working properly
and stores one Hand object as a Pickle file and reads it back into
a new Hand object.
"""

from Hand import Hand
import pickle

if __name__ == "__main__":
    # Testing all methods in Hand Class
    hand1 = Hand(2)
    print("Original Set of Cards in Hand:%s" % hand1)
    print("Beginning Black Jack Value: %s" % hand1.bjValue())
    hand1.hitMe()
    print("\nSet of Cards After Calling Hit Me: %s" % hand1)
    print("Black Jack Value After 'Hit Me': \n%s" % hand1.bjValue())

    # Extra Credit
    with open('data.pickle', 'wb') as f:
        pickle.dump(hand1, f, pickle.HIGHEST_PROTOCOL)
        f.close()
    with open('data.pickle', 'rb') as g:
        hand2 = pickle.load(g)
        print("\nNew Hand Object from Pickle File: %s" % hand2)

# Output Is:
"""
Original Set of Cards in Hand:
Four of Clubs