| | 119 | class TestUtilsChecksums(TestCase): |
|---|
| | 120 | |
|---|
| | 121 | def check_output(self, function, value, output=None): |
|---|
| | 122 | """ |
|---|
| | 123 | Check that function(value) equals output. If output is None, |
|---|
| | 124 | check that function(value) equals value. |
|---|
| | 125 | """ |
|---|
| | 126 | if output is None: |
|---|
| | 127 | output = value |
|---|
| | 128 | self.assertEqual(function(value), output) |
|---|
| | 129 | |
|---|
| | 130 | def test_luhn(self): |
|---|
| | 131 | f = checksums.luhn |
|---|
| | 132 | items = ( |
|---|
| | 133 | (4111111111111111, True), ('4111111111111111', True), |
|---|
| | 134 | (4222222222222, True), (378734493671000, True), |
|---|
| | 135 | (5424000000000015, True), (5555555555554444, True), |
|---|
| | 136 | (1008, True), ('0000001008', True), ('000000001008', True), |
|---|
| | 137 | (4012888888881881, True), (1234567890123456789012345678909, True), |
|---|
| | 138 | (4111111111211111, False), (42222222222224, False), |
|---|
| | 139 | (100, False), ('100', False), ('0000100', False), |
|---|
| | 140 | ('abc', False), (None, False), (object(), False), |
|---|
| | 141 | ) |
|---|
| | 142 | for value, output in items: |
|---|
| | 143 | self.check_output(f, value, output) |
|---|
| | 144 | |
|---|