Exemple #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)
    assert score == encoder.score_n4(matrix, len(matrix))
Exemple #2
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)
    assert score == encoder.score_n4(matrix, len(matrix))
Exemple #3
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)
    assert 206 == encoder.score_n1(matrix, matrix_size)
    assert 141 == encoder.score_n2(matrix, matrix_size)
    # Thonky: 160
    assert 800 == encoder.score_n3(matrix, matrix_size)
    assert 0 == encoder.score_n4(matrix, matrix_size)
    assert 507 - 160 + 800 == encoder.evaluate_mask(matrix, matrix_size)
Exemple #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)
    assert 206 == encoder.score_n1(matrix, matrix_size)
    assert 141 == encoder.score_n2(matrix, matrix_size)
    # Thonky: 160
    assert 800 == encoder.score_n3(matrix, matrix_size)
    assert 0 == encoder.score_n4(matrix, matrix_size)
    assert 507 - 160 + 800 == encoder.evaluate_mask(matrix, matrix_size)
Exemple #5
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)
    assert 180 == encoder.score_n1(matrix, matrix_size)
    assert 141 == encoder.score_n2(matrix, matrix_size)
    # Thonky: 120
    assert 760 == encoder.score_n3(matrix, matrix_size)
    # Thonky: 2, but that's impossible: Either 0 or a multiple of 10 (N4 = 10)
    assert 0 == encoder.score_n4(matrix, matrix_size)
    assert 443 - 2 - 120 + 760 == encoder.evaluate_mask(matrix, matrix_size)
Exemple #6
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)
    assert 172 == encoder.score_n1(matrix, matrix_size)
    assert 129 == encoder.score_n2(matrix, matrix_size)
    # Thonky: 120
    assert 760 == encoder.score_n3(matrix, matrix_size)
    assert 0 == encoder.score_n4(matrix, matrix_size)
    # See score 3
    assert 421 - 120 + 760 == encoder.evaluate_mask(matrix, matrix_size)
Exemple #7
0
def test_thonky_pattern_0():
    # http://www.thonky.com/qr-code-tutorial/data-masking
    matrix = read_matrix('thonky_datamasking_mask-0')
    matrix_size = len(matrix)
    assert 180 == encoder.score_n1(matrix, matrix_size)
    assert 90 == encoder.score_n2(matrix, matrix_size)
    # Thonky: 80
    assert 760 == encoder.score_n3(matrix, matrix_size)
    assert 0 == encoder.score_n4(matrix, matrix_size)
    # See score 3
    assert 350 - 80 + 760 == encoder.evaluate_mask(matrix, matrix_size)
Exemple #8
0
def test_thonky_pattern_0():
    # http://www.thonky.com/qr-code-tutorial/data-masking
    matrix = read_matrix('thonky_datamasking_mask-0')
    matrix_size = len(matrix)
    assert 180 == encoder.score_n1(matrix, matrix_size)
    assert 90 == encoder.score_n2(matrix, matrix_size)
    # Thonky: 80
    assert 760 == encoder.score_n3(matrix, matrix_size)
    assert 0 == encoder.score_n4(matrix, matrix_size)
    # See score 3
    assert 350 - 80 + 760 == encoder.evaluate_mask(matrix, matrix_size)
Exemple #9
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)
    assert 197 == encoder.score_n1(matrix, matrix_size)
    assert 123 == encoder.score_n2(matrix, matrix_size)
    # Thonky: 200
    assert 720 == encoder.score_n3(matrix, matrix_size)
    assert 0 == encoder.score_n4(matrix, matrix_size)
    # See score 3
    assert 520 - 200 + 720 == encoder.evaluate_mask(matrix, matrix_size)
Exemple #10
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)
    assert 180 == encoder.score_n1(matrix, matrix_size)
    assert 141 == encoder.score_n2(matrix, matrix_size)
    # Thonky: 120
    assert 760 == encoder.score_n3(matrix, matrix_size)
    # Thonky: 2, but that's impossible: Either 0 or a multiple of 10 (N4 = 10)
    assert 0 == encoder.score_n4(matrix, matrix_size)
    assert 443 - 2 - 120 + 760 == encoder.evaluate_mask(matrix, matrix_size)
Exemple #11
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)
    assert 172 == encoder.score_n1(matrix, matrix_size)
    assert 129 == encoder.score_n2(matrix, matrix_size)
    # Thonky: 120
    assert 760 == encoder.score_n3(matrix, matrix_size)
    assert 0 == encoder.score_n4(matrix, matrix_size)
    # See score 3
    assert 421 - 120 + 760 == encoder.evaluate_mask(matrix, matrix_size)
Exemple #12
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)
    assert 197 == encoder.score_n1(matrix, matrix_size)
    assert 123 == encoder.score_n2(matrix, matrix_size)
    # Thonky: 200
    assert 720 == encoder.score_n3(matrix, matrix_size)
    assert 0 == encoder.score_n4(matrix, matrix_size)
    # See score 3
    assert 520 - 200 + 720 == encoder.evaluate_mask(matrix, matrix_size)
Exemple #13
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)
    assert 171 == encoder.score_n1(matrix, matrix_size)
    assert 102 == encoder.score_n2(matrix, matrix_size)
    # Thonky: 80
    assert 840 == encoder.score_n3(matrix, matrix_size)
    # Thonky: 4, but that's impossible: Either 0 or a multiple of 10 (N4 = 10)
    assert 0 == encoder.score_n4(matrix, matrix_size)
    # See score 3 and 4
    assert 357 - 4 - 80 + 840 == encoder.evaluate_mask(matrix, matrix_size)
Exemple #14
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)
    assert 189 == encoder.score_n1(matrix, matrix_size)
    assert 156 == encoder.score_n2(matrix, matrix_size)
    # Thonky: 200
    assert 800 == encoder.score_n3(matrix, matrix_size)
    # Thonky: 2, but that's impossible: Either 0 or a multiple of 10 (N4 = 10)
    assert 0 == encoder.score_n4(matrix, matrix_size)
    # See score 3 and 4
    assert 547 - 2 - 200 + 800 == encoder.evaluate_mask(matrix, matrix_size)
Exemple #15
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)
    assert 171 == encoder.score_n1(matrix, matrix_size)
    assert 102 == encoder.score_n2(matrix, matrix_size)
    # Thonky: 80
    assert 840 == encoder.score_n3(matrix, matrix_size)
    # Thonky: 4, but that's impossible: Either 0 or a multiple of 10 (N4 = 10)
    assert 0 == encoder.score_n4(matrix, matrix_size)
    # See score 3 and 4
    assert 357 - 4 - 80 + 840 == encoder.evaluate_mask(matrix, matrix_size)
Exemple #16
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)
    assert 189 == encoder.score_n1(matrix, matrix_size)
    assert 156 == encoder.score_n2(matrix, matrix_size)
    # Thonky: 200
    assert 800 == encoder.score_n3(matrix, matrix_size)
    # Thonky: 2, but that's impossible: Either 0 or a multiple of 10 (N4 = 10)
    assert 0 == encoder.score_n4(matrix, matrix_size)
    # See score 3 and 4
    assert 547 - 2 - 200 + 800 == encoder.evaluate_mask(matrix, matrix_size)
Exemple #17
0
def test_score_n4():
    matrix = read_matrix('thonky_datamasking-2')
    score = encoder.score_n4(matrix, len(matrix))
    assert 0 == score
Exemple #18
0
def test_score_n4():
    matrix = read_matrix('thonky_datamasking-2')
    score = encoder.score_n4(matrix, len(matrix))
    assert 0 == score