|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
# Copyright 2018 by Christopher C. Little. |
|
4
|
|
|
# This file is part of Abydos. |
|
5
|
|
|
# |
|
6
|
|
|
# Abydos is free software: you can redistribute it and/or modify |
|
7
|
|
|
# it under the terms of the GNU General Public License as published by |
|
8
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
# (at your option) any later version. |
|
10
|
|
|
# |
|
11
|
|
|
# Abydos is distributed in the hope that it will be useful, |
|
12
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
# GNU General Public License for more details. |
|
15
|
|
|
# |
|
16
|
|
|
# You should have received a copy of the GNU General Public License |
|
17
|
|
|
# along with Abydos. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
|
|
19
|
|
|
"""abydos.tests.test_fingerprint_lightweight. |
|
20
|
|
|
|
|
21
|
|
|
This module contains unit tests for abydos.fingerprint.lightweight |
|
22
|
|
|
""" |
|
23
|
|
|
|
|
24
|
|
|
from __future__ import unicode_literals |
|
25
|
|
|
|
|
26
|
|
|
import unittest |
|
27
|
|
|
|
|
28
|
|
|
from abydos.fingerprint.lightweight import count_fingerprint, \ |
|
29
|
|
|
occurrence_fingerprint, occurrence_halved_fingerprint, position_fingerprint |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
class LightweightFingerprintsTestCases(unittest.TestCase): |
|
33
|
|
|
"""Test Cisłak & Grabowski lightweight fingerprint functions. |
|
34
|
|
|
|
|
35
|
|
|
abydos.fingerprint.lightweight.occurrence_fingerprint, |
|
36
|
|
|
.occurrence_halved_fingerprint, .count_fingerprint, & .position_fingerprint |
|
37
|
|
|
""" |
|
38
|
|
|
|
|
39
|
|
|
def test_occurrence_fingerprint(self): |
|
40
|
|
|
"""Test abydos.fingerprint.lightweight.occurrence_fingerprint.""" |
|
41
|
|
|
# Base case |
|
42
|
|
|
self.assertEqual(occurrence_fingerprint(''), 0) |
|
43
|
|
|
|
|
44
|
|
|
# https://arxiv.org/pdf/1711.08475.pdf |
|
45
|
|
|
self.assertEqual(occurrence_fingerprint('instance'), |
|
46
|
|
|
0b1110111000010000) |
|
47
|
|
|
|
|
48
|
|
|
self.assertEqual(occurrence_fingerprint('inst'), |
|
49
|
|
|
0b0100111000000000) |
|
50
|
|
|
self.assertEqual(occurrence_fingerprint('instance', 15), |
|
51
|
|
|
0b111011100001000) |
|
52
|
|
|
self.assertEqual(occurrence_fingerprint('instance', 32), |
|
53
|
|
|
0b11101110000100000000000000000000) |
|
54
|
|
|
self.assertEqual(occurrence_fingerprint('instance', 64), |
|
55
|
|
|
0b11101110000100000000000000000000 << 32) |
|
56
|
|
|
|
|
57
|
|
|
def test_occurrence_halved_fingerprint(self): |
|
58
|
|
|
"""Test abydos.fingerprint.lightweight.occurrence_halved_fingerprint.""" # noqa: E501 |
|
59
|
|
|
# Base case |
|
60
|
|
|
self.assertEqual(occurrence_halved_fingerprint(''), 0) |
|
61
|
|
|
|
|
62
|
|
|
# https://arxiv.org/pdf/1711.08475.pdf |
|
63
|
|
|
self.assertEqual(occurrence_halved_fingerprint('instance'), |
|
64
|
|
|
0b0110010010111000) |
|
65
|
|
|
|
|
66
|
|
|
self.assertEqual(occurrence_halved_fingerprint('inst'), |
|
67
|
|
|
0b0001000010100100) |
|
68
|
|
|
self.assertEqual(occurrence_halved_fingerprint('instance', 15), |
|
69
|
|
|
0b0110010010111000) |
|
70
|
|
|
self.assertEqual(occurrence_halved_fingerprint('instance', 32), |
|
71
|
|
|
0b01100100101110000000000100000000) |
|
72
|
|
|
self.assertEqual(occurrence_halved_fingerprint('instance', 64), |
|
73
|
|
|
0b01100100101110000000000100000000 << 32) |
|
74
|
|
|
|
|
75
|
|
|
def test_count_fingerprint(self): |
|
76
|
|
|
"""Test abydos.fingerprint.lightweight.count_fingerprint.""" |
|
77
|
|
|
# Base case |
|
78
|
|
|
self.assertEqual(count_fingerprint(''), 0) |
|
79
|
|
|
|
|
80
|
|
|
# https://arxiv.org/pdf/1711.08475.pdf |
|
81
|
|
|
self.assertEqual(count_fingerprint('instance'), |
|
82
|
|
|
0b0101010001100100) |
|
83
|
|
|
|
|
84
|
|
|
self.assertEqual(count_fingerprint('inst'), |
|
85
|
|
|
0b0001000001010100) |
|
86
|
|
|
self.assertEqual(count_fingerprint('instance', 15), |
|
87
|
|
|
0b0101010001100100) |
|
88
|
|
|
self.assertEqual(count_fingerprint('instance', 32), |
|
89
|
|
|
0b01010100011001000000000100000000) |
|
90
|
|
|
self.assertEqual(count_fingerprint('instance', 64), |
|
91
|
|
|
0b01010100011001000000000100000000 << 32) |
|
92
|
|
|
|
|
93
|
|
|
def test_position_fingerprint(self): |
|
94
|
|
|
"""Test abydos.fingerprint.lightweight.position_fingerprint.""" |
|
95
|
|
|
# Base case |
|
96
|
|
|
self.assertEqual(position_fingerprint(''), |
|
97
|
|
|
0b1111111111111111) |
|
98
|
|
|
|
|
99
|
|
|
# https://arxiv.org/pdf/1711.08475.pdf |
|
100
|
|
|
self.assertEqual(position_fingerprint('instance'), |
|
101
|
|
|
0b1110111001110001) |
|
102
|
|
|
|
|
103
|
|
|
self.assertEqual(position_fingerprint('instance'), |
|
104
|
|
|
0b1110111001110001) |
|
105
|
|
|
self.assertEqual(position_fingerprint('instance', 15), |
|
106
|
|
|
0b111011100111000) |
|
107
|
|
|
self.assertEqual(position_fingerprint('instance', 32), |
|
108
|
|
|
0b11101110011100000101011111111111) |
|
109
|
|
|
self.assertEqual(position_fingerprint('instance', 64), |
|
110
|
|
|
0xee7057ffefffffff) |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
if __name__ == '__main__': |
|
114
|
|
|
unittest.main() |
|
115
|
|
|
|