Completed
Branch master (87ccc1)
by Chris
10:18
created

tests.fingerprint.test_fingerprint_basic   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 46
dl 0
loc 100
rs 10
c 0
b 0
f 0
wmc 6
1
# -*- coding: utf-8 -*-
2
3
# Copyright 2014-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.basic.
20
21
This module contains unit tests for abydos.fingerprint.basic
22
"""
23
24
from __future__ import unicode_literals
25
26
import unittest
27
28
from abydos.fingerprint.basic import phonetic_fingerprint, qgram_fingerprint, \
29
    str_fingerprint
30
from abydos.phonetic.phonet import phonet
31
from abydos.phonetic.soundex import soundex
32
33
from six.moves import range
34
35
from .. import NIALL
36
37
38
class FingerprintTestCases(unittest.TestCase):
39
    """Test basic fingerprint functions.
40
41
    abydos.fingerprint.basic.str_fingerprint, .qgram_fingerprint, &
42
    .phonetic_fingerprint
43
    """
44
45
    _testset = ('À noite, vovô Kowalsky vê o ímã cair no pé do pingüim \
46
queixoso e vovó põe açúcar no chá de tâmaras do jabuti feliz.', )
47
    _anssetw = ('a acucar cair cha de do e feliz ima jabuti kowalsky no noite \
48
o pe pinguim poe queixoso tamaras ve vovo', )
49
    _anssetq2 = ('abacadaialamanarasbucachcudedoeaedeieleoetevfeguhaifiminirit\
50
ixizjakokylilsmamqngnoocoeoiojokoposovowpepipoqurarnsdsksotatetiucueuiutvevowa\
51
xoyv', )
52
    _anssetq1 = ('abcdefghijklmnopqrstuvwxyz', )
53
54
    def test_str_fingerprint(self):
55
        """Test abydos.fingerprint.basic.str_fingerprint."""
56
        # Base case
57
        self.assertEqual(str_fingerprint(''), '')
58
59
        for i in range(len(self._testset)):
60
            self.assertEqual(str_fingerprint(self._testset[i]),
61
                             self._anssetw[i])
62
63
    def test_qgram_fingerprint(self):
64
        """Test abydos.fingerprint.basic.qgram_fingerprint."""
65
        # Base case
66
        self.assertEqual(qgram_fingerprint(''), '')
67
68
        for i in range(len(self._testset)):
69
            self.assertEqual(qgram_fingerprint(self._testset[i], 1),
70
                             self._anssetq1[i])
71
            self.assertEqual(qgram_fingerprint(self._testset[i], 2),
72
                             self._anssetq2[i])
73
            self.assertEqual(qgram_fingerprint(self._testset[i]),
74
                             self._anssetq2[i])
75
76
        qgram_fp_niall = ('aliallni', 'aleane', 'eiilne', 'aljallnj',
77
                          'aljallnj', 'elgeigni', 'eeelne', 'ellene',
78
                          'elgeiglillni', 'elne', 'aleaknlene', 'eiilinllneui',
79
                          'eiilllneon', 'accneiilmane', 'accnellemane',
80
                          'acalchgiiaiglalllnninooi')
81
        for i in range(len(NIALL)):
82
            self.assertEqual(qgram_fingerprint(NIALL[i]), qgram_fp_niall[i])
83
84
    def test_phonetic_fingerprint(self):
85
        """Test abydos.fingerprint.basic.phonetic_fingerprint."""
86
        # Base case
87
        self.assertEqual(phonetic_fingerprint(''), '')
88
89
        self.assertEqual(phonetic_fingerprint(' '.join(NIALL)),
90
                         'a anl mknl njl nklk nl')
91
        self.assertEqual(phonetic_fingerprint(' '.join(NIALL), phonet),
92
                         'knile makneil maknele neil nel nele nial nigeli ' +
93
                         'nigl nil noigialach oneil ui')
94
        self.assertEqual(phonetic_fingerprint(' '.join(NIALL), soundex),
95
                         'k540 m254 n240 n242 n400 o540 u000')
96
97
98
if __name__ == '__main__':
99
    unittest.main()
100