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

tests.fingerprint.test_fingerprint_synoname.SynonameToolcodeTestCases.test_synoname_toolcode()   B

Complexity

Conditions 1

Size

Total Lines 131
Code Lines 125

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 125
nop 1
dl 0
loc 131
rs 7
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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_synoname.
20
21
This module contains unit tests for abydos.fingerprint.synoname
22
"""
23
24
from __future__ import unicode_literals
25
26
import unittest
27
28
from abydos.fingerprint.synoname import synoname_toolcode
29
30
31
class SynonameToolcodeTestCases(unittest.TestCase):
32
    """Test Synoname Toolcode function.
33
34
    abydos.fingerprint.synoname.synoname_toolcode
35
    """
36
37
    def test_synoname_toolcode(self):
38
        """Test abydos.fingerprint.synoname.synoname_toolcode."""
39
        # Base case
40
        self.assertEqual(synoname_toolcode(''), ('', '', '0000000000$$'))
41
42
        # from Synoname demo
43
        self.assertEqual(synoname_toolcode('angelico', 'fra'),
44
                         ('angelico', 'fra', '0000000308$044a$af'))
45
        self.assertEqual(synoname_toolcode('Aelst', 'Willem van', ''),
46
                         ('aelst', 'willem van', '0000001005$143a$awv'))
47
        self.assertEqual(synoname_toolcode('Afro'),
48
                         ('afro', '', '0000000004$$a'))
49
        self.assertEqual(synoname_toolcode('Afro', 'Basaldella'),
50
                         ('afro', 'basaldella', '0000001004$$ab'))
51
        self.assertEqual(synoname_toolcode('Albright', 'Ivan'),
52
                         ('albright', 'ivan', '0000000408$$ai'))
53
        self.assertEqual(synoname_toolcode('Antonello da Messina'),
54
                         ('antonello da messina', '', '0000000020$022b$adm'))
55
        self.assertEqual(synoname_toolcode('Albright', 'Ivan Le Lorraine'),
56
                         ('albright', 'ivan le lorraine',
57
                          '0000001608$067b$ail'))
58
        self.assertEqual(synoname_toolcode('Bazille', 'Frederic',
59
                                           'Attributed to'),
60
                         ('bazille', 'frederic', '1000000807$$bf'))
61
        self.assertEqual(synoname_toolcode('Bazille', 'Frederick',
62
                                           'Attributed to'),
63
                         ('bazille', 'frederick', '1000000907$$bf'))
64
        self.assertEqual(synoname_toolcode('Beerstraaten', 'Jan Abrahamsz.'),
65
                         ('beerstraaten', 'jan abrahamsz.', '0200001412$$bja'))
66
        self.assertEqual(synoname_toolcode('Bonifacio di Pitati'),
67
                         ('bonifacio di pitati', '', '0000000019$035b$bdp'))
68
        self.assertEqual(synoname_toolcode('Breughel the Younger', 'Jan'),
69
                         ('breughel the younger', 'jan',
70
                          '0020000320$134b$btyj'))
71
        self.assertEqual(synoname_toolcode('Brown', 'W. W.'),
72
                         ('brown', 'w. w.', '0200000505$$bw'))
73
        self.assertEqual(synoname_toolcode('Brueghel II (the Younger)', 'Jan'),
74
                         ('brueghel ii (the younger)', 'jan',
75
                          '0120490325$049b134b$bityj'))
76
        self.assertEqual(synoname_toolcode('Brueghel II (the Younger)',
77
                                           'Pieter', 'Workshop of'),
78
                         ('brueghel ii (the younger)', 'pieter',
79
                          '3120490625$049b134b$bityp'))
80
        self.assertEqual(synoname_toolcode('Bugiardini',
81
                                           'Guiliano di Piero di Simone'),
82
                         ('bugiardini', 'guiliano di piero di simone',
83
                          '0000002710$035b035b$bgdps'))
84
        self.assertEqual(synoname_toolcode('Caravaggio', '', 'Follower of'),
85
                         ('caravaggio', '', '3000000010$$c'))
86
        self.assertEqual(synoname_toolcode('Caravaggio',
87
                                           'Michelangelo Merisi da',
88
                                           'Follower of'),
89
                         ('caravaggio', 'michelangelo merisi da',
90
                          '3000002210$022a$cmd'))
91
        self.assertEqual(synoname_toolcode('Oost the Younger', 'Jacob van'),
92
                         ('oost the younger', 'jacob van',
93
                          '0020000916$134b143a$otyjv'))
94
95
        # additional tests for coverage
96
        self.assertEqual(synoname_toolcode('Cato the Elder', '', 'Copy of'),
97
                         ('cato the elder', '', '2010000014$133b$cte'))
98
        self.assertEqual(synoname_toolcode('Cato, the Elder', normalize=2),
99
                         ('cato the elder', '', '0110000014$133b$cte'))
100
        self.assertEqual(synoname_toolcode('Cato the Elder', normalize=2),
101
                         ('cato the elder', '', '0010000014$133b$cte'))
102
        self.assertEqual(synoname_toolcode('Lorem ipsum dolor sit amet, ' +
103
                                           'consectetur adipiscing elit, ' +
104
                                           'sed do eiusmod tempor ' +
105
                                           'incididunt ut labore et dolore ' +
106
                                           'magna aliqua. Nulla aliquet ' +
107
                                           'porttitor lacus luctus accumsan ' +
108
                                           'tortor posuere. Egestas purus ' +
109
                                           'viverra accumsan in. Ultrices ' +
110
                                           'mi tempus imperdiet nulla ' +
111
                                           'malesuada pellentesque elit ' +
112
                                           'eget gravida. Proin libero nunc ' +
113
                                           'consequat interdum varius sit ' +
114
                                           'amet mattis vulputate. Mauris ' +
115
                                           'ultrices eros in cursus turpis ' +
116
                                           'massa tincidunt dui. Faucibus ' +
117
                                           'in ornare quam viverra orci ' +
118
                                           'sagittis eu volutpat odio. Enim ' +
119
                                           'blandit volutpat maecenas ' +
120
                                           'volutpat blandit aliquam etiam. ' +
121
                                           'Vel quam elementum pulvinar ' +
122
                                           'etiam. Duis ut diam quam nulla ' +
123
                                           'porttitor massa id.',
124
                                           normalize=1)[2],
125
                         '02000060626$068d$lidsacetumnpvgflo')
126
        self.assertEqual(synoname_toolcode('Sainte-Vincent'),
127
                         ('sainte-vincent', '', '0100000014$110c$sv'))
128
        self.assertEqual(synoname_toolcode('Lorem', 'Sainte-Vincent'),
129
                         ('lorem', 'sainte-vincent',
130
                          '0100001405$068d110b$lsvlo'))
131
        self.assertEqual(synoname_toolcode('Louis II', 'Jean'),
132
                         ('louis ii', 'jean', '0000490408$049b068d$lijlo'))
133
        self.assertEqual(synoname_toolcode('Louis', 'Jean II', normalize=2),
134
                         ('louis ii', 'jean', '0000490705$049a068d$ljilo'))
135
        self.assertEqual(synoname_toolcode('Louis', 'Jean II ', normalize=2),
136
                         ('louis ii', 'jean', '0000490805$049b068d$ljilo'))
137
        self.assertEqual(synoname_toolcode('Louis', 'Jean II-', normalize=2),
138
                         ('louis', 'jean ii-', '0100490805$049b068d$ljilo'))
139
        self.assertEqual(synoname_toolcode('Louis V.', 'Jean', normalize=2),
140
                         ('louis v.', 'jean', '0200000408$068d$lvjlo'))
141
        self.assertEqual(synoname_toolcode('Louis V.', 'Ste.-Jean Ste.',
142
                                           normalize=2),
143
                         ('louis v.', 'ste.-jean ste.',
144
                          '0200001408$068d127b127X$lvsjlo ste'))
145
        self.assertEqual(synoname_toolcode('Louis IX', 'Jean III II',
146
                                           normalize=2),
147
                         ('louis ix iii ii', 'jean',
148
                          '0000481108$048b049a056b068d$lijlo'))
149
        self.assertEqual(synoname_toolcode('Louis IX', 'Jean II III',
150
                                           normalize=2),
151
                         ('louis ix iii ii', 'jean',
152
                          '0000481108$048a049a056b068d$lijlo'))
153
        self.assertEqual(synoname_toolcode('Louis IX', 'Jean II III',
154
                                           normalize=1),
155
                         ('louis ix', 'jean ii iii',
156
                          '0000481108$048a049a056b068d$lijlo'))
157
        self.assertEqual(synoname_toolcode('Lorem', 'Sainte-Sainte-Vincent'),
158
                         ('lorem', 'sainte-sainte-vincent',
159
                          '0100002105$068d110b$lsvlo'))
160
        self.assertEqual(synoname_toolcode('Brueghel II', 'I. Jan',
161
                                           normalize=2),
162
                         ('brueghel ii', 'i. jan', '0200000611$$bij'))
163
        self.assertEqual(synoname_toolcode('Brueghel', 'I. Jan II',
164
                                           normalize=2),
165
                         ('brueghel', 'i. jan ii', '0200000908$$bij'))
166
        self.assertEqual(synoname_toolcode('Lorem', 'Laurent Ormond'),
167
                         ('lorem', 'laurent ormond', '0000001405$068d$lo'))
168
169
170
if __name__ == '__main__':
171
    unittest.main()
172