Last active
January 4, 2018 19:02
-
-
Save marcuszierke/658dcc8dd7b9ad0347bbbaf7481b4cac to your computer and use it in GitHub Desktop.
This file contains 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 | |
def bn(draws=None, balls=None): | |
#error message for missing input | |
if draws == None or balls == None: return "Missing Input" | |
#error message for negative input | |
if draws < 0 or balls < 0: return "Input has to be a number >= 0" | |
#error message if draws > balls | |
if balls<draws: return "Input number for draws has to be <= input number for balls" | |
#defining the factorial function | |
def fact(num): | |
return 1 if num == 0 else num*fact(num-1) | |
#calculating the bn with fact | |
return fact(balls) / (fact(draws)*fact(balls-draws)) | |
#unittests | |
class TestingFunctionBio(unittest.TestCase): | |
def test_negativity(self): | |
self.assertEqual(bn(-1,0), 'Input has to be a number >= 0') | |
self.assertEqual(bn(12,-1), 'Input has to be a number >= 0') | |
def test_drawsSmallerThanBalls(self): | |
self.assertEqual(bn(4,1), 'Input number for draws has to be <= input number for balls') | |
def test_missingInput(self): | |
self.assertEqual(bn(), 'Missing Input') | |
self.assertEqual(bn(12), 'Missing Input') | |
def test_lotto(self): | |
self.assertEqual(bn(6,49), 13983816) | |
if __name__ == '__main__': | |
unittest.main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment