1 import unittest
2
3 f = lambda n: n%10==0 and 10 or n%10
4 def compute_check_mod1110(str):
5 t = 10
6 for c in str:
7 t = (2 * f(t + ord(c) - 48)) % 11
8 return (11 - t) % 10
9
10 class CheckTest(unittest.TestCase):
11 def testMod112(self):
12 self.assertEquals(5, compute_check_mod1110('0794'))
13 self.assertEquals(5, compute_check_mod1110('00200667308'))
14 self.assertEquals(3, compute_check_mod1110('00200667309'))
15 self.assertEquals(8, compute_check_mod1110('00200667310'))
16 self.assertEquals(6, compute_check_mod1110('00200667311'))
17 self.assertEquals(4, compute_check_mod1110('00200667312'))
18
19 if __name__=='__main__':
20 unittest.main()
Iso7064Mod1110.py (last edited 2011-08-03 11:00:49 by localhost)