Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created November 28, 2012 17:32
Show Gist options
  • Save pamelafox/4162735 to your computer and use it in GitHub Desktop.
Save pamelafox/4162735 to your computer and use it in GitHub Desktop.
Basic unit test of function in Python
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