-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_qrcodes.py
41 lines (26 loc) · 1.01 KB
/
test_qrcodes.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
import qrcodes
import numpy as np
from nose.tools import assert_equals
def test_qrCodeMatrix():
"""QR code matrices should have the specified size"""
data = "kg823nASp7"
matrix = qrcodes.qrCodeMatrix(data)
assert_equals((qrcodes.IMAGE_SIZE, qrcodes.IMAGE_SIZE), matrix.shape)
def test_dataToVector():
"""One-hot encoded vectors should have the proper shape"""
for ind, char in enumerate(qrcodes.CHARACTER_SET):
data = char + "random_suffix"
vec = qrcodes.dataToVector(data)
assert_equals(len(qrcodes.CHARACTER_SET), len(vec))
assert_equals(1.0, sum(vec))
assert_equals(1.0, vec[ind])
def test_getRandomBatch():
"""Batch tensors should have the correct shape"""
batchSize = 22
X, y = qrcodes.getRandomBatch(batchSize)
y = np.asarray(y)
assert_equals((batchSize, qrcodes.IMAGE_SIZE, qrcodes.IMAGE_SIZE, 1), X.shape)
assert_equals((batchSize, len(qrcodes.CHARACTER_SET)), y.shape)
if __name__ == "__main__":
import nose
nose.run()