Exemplo n.º 1
0
 def test_cc(self):
     import luhns
     test_cases = [("38520000023237", True),
                   ("49927398716", True),
                   ("49927398717", False),
                   ("1234567812345678", False),
                   ("1234567812345670", True)]
     for ccnum, valid in test_cases:
         with self.subTest(i=ccnum):
             self.assertEqual(luhns.validate(ccnum), valid)
Exemplo n.º 2
0
def main():
    # This is a list of tuples, the first element is a card number
    # and the second is a boolean that's True if the card number is
    # valid and False if it is not.
    test_cases = [("38520000023237", True),
                  ("49927398716", True),
                  ("49927398717", False),
                  ("1234567812345678", False),
                  ("1234567812345670", True)]
    passed = 0
    for card_number, expected_result in test_cases:
        result = luhns.validate(card_number)
        if expected_result == result:
            passed += 1
        else:
            print('luhns.validate("{}") should return {}, but returned {}.'
                    .format(card_number, expected_result, result))
    print('The function luhns.validate correctly verified '
        + '{} out of {} card numbers.'.format(passed, len(test_cases)))
Exemplo n.º 3
0
 def test_validate(self):
     import luhns
     for ccnum, valid in TestLuhns.test_cases:
         with self.subTest(i=ccnum):
             self.assertEqual(luhns.validate(ccnum), valid)