コード例 #1
0
def test_score_n4_iso(score, percent):
    # Add 10 points to a deviation of 5% increment or decrement in the
    # proportion ratio of dark module from the referential 50% (or 0 point)
    # level. For example, assign 0 points as a penalty if the ratio of dark
    # module is between 45% and 55%, or 10 points if the ratio of dark module
    # is between 40% and 60%

    def make_matrix():
        row = [0x0] * 10
        return tuple([bytearray(row) for i in range(10)])

    def fill_matrix(matrix, percent):
        cnt = 0
        finished = False
        for i in range(len(matrix)):
            for j in range(len(matrix)):
                matrix[i][j] = 0x1
                cnt += 1
                finished = cnt == percent
                if finished:
                    break
            if finished:
                break

    matrix = make_matrix()
    fill_matrix(matrix, percent)
    matrix_size = len(matrix)
    scores = encoder.mask_scores(matrix, matrix_size)
    score = scores[3]
    assert score == score
コード例 #2
0
def test_score_n2_iso():
    # Take a block consisting of 3 x 3 dark
    # modules for an example. Considering that up to four 2 x 2 dark modules can
    # be included in this block, the penalty applied to this block shall be
    # calculated as 4 (blocks) x 3 (points) = 12 points.
    matrix = (bytearray([1, 1, 1]), bytearray([1, 1, 1]), bytearray([1, 1, 1]))
    matrix_size = len(matrix)
    scores = encoder.mask_scores(matrix, matrix_size)
    score = scores[1]
    assert 12 == score

    matrix = (bytearray([0, 0, 0]), bytearray([0, 0, 0]), bytearray([0, 0, 0]))
    matrix_size = len(matrix)
    scores = encoder.mask_scores(matrix, matrix_size)
    score = scores[1]
    assert 12 == score
コード例 #3
0
def test_score_n1_iso():
    # For example, impose 5 penalty points on the block of “dark:dark:dark:dark:dark:dark:dark”
    # module pattern, where a series of seven consecutive modules is counted as one block
    matrix = tuple(bytearray([1] * 7) for i in range(7))
    matrix_size = len(matrix)
    scores = encoder.mask_scores(matrix, matrix_size)
    score = scores[0]
    assert 5 * 7 * 2 == score
コード例 #4
0
def test_thonky_pattern_2():
    # http://www.thonky.com/qr-code-tutorial/data-masking
    matrix = read_matrix('thonky_datamasking_mask-2')
    matrix_size = len(matrix)
    scores = encoder.mask_scores(matrix, matrix_size)
    assert 206 == scores[0]
    assert 141 == scores[1]
    # Thonky: 160
    assert 800 == scores[2]
    assert 0 == scores[3]
    assert 507 - 160 + 800 == encoder.evaluate_mask(matrix, matrix_size)
コード例 #5
0
def test_thonky_pattern_7():
    # http://www.thonky.com/qr-code-tutorial/data-masking
    matrix = read_matrix('thonky_datamasking_mask-7')
    matrix_size = len(matrix)
    scores = encoder.mask_scores(matrix, matrix_size)
    assert 197 == scores[0]
    assert 123 == scores[1]
    # Thonky: 200
    assert 720 == scores[2]
    assert 0 == scores[3]
    # See score 3
    assert 520 - 200 + 720 == encoder.evaluate_mask(matrix, matrix_size)
コード例 #6
0
def test_thonky_pattern_3():
    # http://www.thonky.com/qr-code-tutorial/data-masking
    matrix = read_matrix('thonky_datamasking_mask-3')
    matrix_size = len(matrix)
    scores = encoder.mask_scores(matrix, matrix_size)
    assert 180 == scores[0]
    assert 141 == scores[1]
    # Thonky: 120
    assert 760 == scores[2]
    # Thonky: 2, but that's impossible: Either 0 or a multiple of 10 (N4 = 10)
    assert 0 == scores[3]
    assert 443 - 2 - 120 + 760 == encoder.evaluate_mask(matrix, matrix_size)
コード例 #7
0
def test_thonky_pattern_1():
    # http://www.thonky.com/qr-code-tutorial/data-masking
    matrix = read_matrix('thonky_datamasking_mask-1')
    matrix_size = len(matrix)
    scores = encoder.mask_scores(matrix, matrix_size)
    assert 172 == scores[0]
    assert 129 == scores[1]
    # Thonky: 120
    assert 760 == scores[2]
    assert 0 == scores[3]
    # See score 3
    assert 421 - 120 + 760 == encoder.evaluate_mask(matrix, matrix_size)
コード例 #8
0
def test_thonky_pattern_6():
    # http://www.thonky.com/qr-code-tutorial/data-masking
    matrix = read_matrix('thonky_datamasking_mask-6')
    matrix_size = len(matrix)
    scores = encoder.mask_scores(matrix, matrix_size)
    assert 171 == scores[0]
    assert 102 == scores[1]
    # Thonky: 80
    assert 840 == scores[2]
    # Thonky: 4, but that's impossible: Either 0 or a multiple of 10 (N4 = 10)
    assert 0 == scores[3]
    # See score 3 and 4
    assert 357 - 4 - 80 + 840 == encoder.evaluate_mask(matrix, matrix_size)
コード例 #9
0
def test_thonky_pattern_5():
    # http://www.thonky.com/qr-code-tutorial/data-masking
    matrix = read_matrix('thonky_datamasking_mask-5')
    matrix_size = len(matrix)
    scores = encoder.mask_scores(matrix, matrix_size)
    assert 189 == scores[0]
    assert 156 == scores[1]
    # Thonky: 200
    assert 800 == scores[2]
    # Thonky: 2, but that's impossible: Either 0 or a multiple of 10 (N4 = 10)
    assert 0 == scores[3]
    # See score 3 and 4
    assert 547 - 2 - 200 + 800 == encoder.evaluate_mask(matrix, matrix_size)
コード例 #10
0
def test_score_n4():
    matrix = read_matrix('thonky_datamasking-2')
    matrix_size = len(matrix)
    scores = encoder.mask_scores(matrix, matrix_size)
    score = scores[3]
    assert 0 == score
コード例 #11
0
def test_score_n3():
    matrix, matrix_size = make_thonky_score_matrix()
    scores = encoder.mask_scores(matrix, matrix_size)
    score = scores[2]
    # Thonky: 80
    assert 760 == score
コード例 #12
0
def test_score_n2():
    matrix, matrix_size = make_thonky_score_matrix()
    scores = encoder.mask_scores(matrix, matrix_size)
    score = scores[1]
    assert 90 == score