-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.py
64 lines (49 loc) · 2.27 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import unittest
import matrix, qrcode
class MatrixTest(unittest.TestCase):
def setUp(self):
self.m1 = matrix.Matrix(10, 10)
self.m2 = matrix.Matrix(10, 5, initial=42)
self.m3 = matrix.Matrix(1, 10, initial=69)
self.m4 = matrix.Matrix(15, 1, initial=23)
def testCreate(self):
self.assertEqual(self.m1[0,0], None)
self.assertEqual(self.m2[9,4], 42)
def testSet(self):
self.assertEqual(self.m1[1,0], None)
self.assertEqual(self.m1[2,0], None)
self.assertEqual(self.m1[1,1], None)
self.m1[1,0] = 1
self.assertEqual(self.m1[1,0], 1)
self.assertEqual(self.m1[2,0], None)
self.assertEqual(self.m1[1,1], None)
def testGetRow(self):
self.assertEqual(self.m3.get_row(0), [69] * 10)
self.assertEqual(self.m1.get_row(8), [None] * 10)
def testGetCol(self):
self.assertEqual(self.m4.get_col(0), [23] * 15)
self.assertEqual(self.m1.get_col(8), [None] * 10)
class QRCodeTest(unittest.TestCase):
def testSymbolSize(self):
self.assertEqual(25, qrcode.QRCode().size)
self.assertEqual(21, qrcode.QRCode(version=1).size)
self.assertEqual(13, qrcode.QRCode(microcode=True).size)
self.assertEqual(15, qrcode.QRCode(microcode=True, version=3).size)
def testInvalidVersion(self):
self.assertRaises(qrcode.QRError, qrcode.QRCode, version=0)
self.assertRaises(qrcode.QRError, qrcode.QRCode, version=5, microcode=True)
self.assertRaises(qrcode.QRError, qrcode.QRCode, version=41)
def testBitlist(self):
self.assertEqual([0,0,0,1,0], qrcode.bitlist(2, 5))
def testBitToIntlist(self):
self.assertEqual([0,255],
qrcode.bit_to_intlist(
[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1]))
def testIntToBitlist(self):
self.assertEqual([1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
qrcode.int_to_bitlist([128,1]))
def testEncode(self):
#qrcode.QRCode(version=1).encode('HTTP://QR-CODE.CO.PA')
qrcode.QRCode().encode('HTTP://QR-CODE.CO.ZA/0123456789/0123456789/0123')
if __name__ == '__main__':
unittest.main()