Created
November 28, 2012 17:32
-
-
Save pamelafox/4162735 to your computer and use it in GitHub Desktop.
Basic unit test of function in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
BUST_VAL = 22 | |
ACE_HIGH = 11 | |
ACE_LOW = 1 | |
def calculate_hand_val(low_hand_val, num_aces): | |
hand_val = low_hand_val | |
for x in range(1, num_aces + 1): | |
if (hand_val + (ACE_HIGH - ACE_LOW)) < BUST_VAL: | |
print 'adding high' | |
hand_val += (ACE_HIGH - ACE_LOW) | |
return hand_val | |
class TestHandFunctions(unittest.TestCase): | |
def test_hand_val(self): | |
self.assertEqual(calculate_hand_val(1, 2), 21) | |
self.assertEqual(calculate_hand_val(10, 1), 20) | |
self.assertEqual(calculate_hand_val(10, 2), 21) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment