Completed
Push — master ( 95b69a...08d3e4 )
by Chris
01:11
created

test_infix_nosingle_pairs()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
1
import unittest
2
from namebot import techniques
3
4
5
class DomainifyTestCase(unittest.TestCase):
6
7
    def test_threeletter(self):
8
        self.assertEqual(techniques.domainify(['intercom']), ['inter.com'])
9
10
    def test_twoletter(self):
11
        self.assertEqual(
12
            techniques.domainify(['actively'], tld='.ly'), ['active.ly'])
13
14
    def test_fourletter(self):
15
        self.assertEqual(
16
            techniques.domainify(['scamp'], tld='.camp'), ['s.camp'])
17
18
    def test_empty(self):
19
        self.assertEqual(
20
            techniques.domainify(['intercom'], tld=''), ['intercom'])
21
22
23
class PalindromeTestCase(unittest.TestCase):
24
25
    def test_simple(self):
26
        self.assertEqual(techniques.palindrome('Fool'), 'FoollooF')
27
28
    def test_complicated(self):
29
        self.assertEqual(techniques.palindrome(
30
            'Aardvarks'), 'AardvarksskravdraA')
31
32
    def test_spaced(self):
33
        self.assertEqual(techniques.palindrome(
34
            'Red Dragon'), 'Red DragonnogarD deR')
35
36
    def test_simple_array(self):
37
        self.assertEqual(techniques.palindromes(
38
            ['wtf', 'omg']), ['wtfftw', 'omggmo'])
39
40
    def test_simple_array_spaced(self):
41
        self.assertEqual(techniques.palindromes(
42
            ['wtf omg', 'omg wtf']), ['wtf omggmo ftw', 'omg wtfftw gmo'])
43
44
    def test_single_letter(self):
45
        self.assertEqual(techniques.palindrome('f'), 'ff')
46
47
48
class SpoonerismTestCase(unittest.TestCase):
49
50
    def test_simple(self):
51
        self.assertEqual(
52
            techniques.spoonerism(['flim', 'boom', 'dang', 'dune']),
53
            ['blim foom', 'doom bang', 'dang dune'])
54
55
    def test_single_word(self):
56
        with self.assertRaises(ValueError):
57
            self.assertEqual(techniques.spoonerism(['foo']))
58
59
60
class KniferismTestCase(unittest.TestCase):
61
62
    def test_simple(self):
63
        self.assertEqual(
64
            techniques.kniferism(['flim', 'boom', 'dang', 'dune']),
65
            ['flom boim', 'bonm daog', 'dang dune'])
66
67
    def test_single_word(self):
68
        with self.assertRaises(ValueError):
69
            self.assertEqual(techniques.kniferism(['foo']))
70
71
72
class ForkerismTestCase(unittest.TestCase):
73
74
    def test_simple(self):
75
        self.assertEqual(
76
            techniques.forkerism(['flim', 'boom', 'dang', 'dune']),
77
            ['flim boom', 'boog danm', 'dane dung'])
78
79
    def test_single_word(self):
80
        with self.assertRaises(ValueError):
81
            self.assertEqual(techniques.forkerism(['foo']))
82
83
84
class ReduplicationAblautTestCase(unittest.TestCase):
85
86
    def test_vowel_a(self):
87
        self.assertEqual(techniques.reduplication_ablaut(
88
            ['cat', 'dog'], random=False, vowel='a'), ['dog dag'])
89
90
    def test_vowel_e(self):
91
        self.assertEqual(techniques.reduplication_ablaut(
92
            ['cat', 'dog'], random=False, vowel='e'),
93
            ['cat cet', 'dog deg'])
94
95
    def test_vowel_i(self):
96
        self.assertEqual(techniques.reduplication_ablaut(
97
            ['cat', 'dog'], random=False, vowel='i'),
98
            ['cat cit', 'dog dig'])
99
100
    def test_vowel_o(self):
101
        self.assertEqual(techniques.reduplication_ablaut(
102
            ['cat', 'dog'], random=False, vowel='o'), ['cat cot'])
103
104
    def test_vowel_u(self):
105
        self.assertEqual(techniques.reduplication_ablaut(
106
            ['cat', 'dog'], random=False, vowel='u'),
107
            ['cat cut', 'dog dug'])
108
109
110
class AffixWordsTestCase(unittest.TestCase):
111
112
    def setUp(self):
113
        self.words = ['shop']
114
115
    def test_prefix(self):
116
        res = techniques.prefixify(self.words)
117
        self.assertEqual(res[:3], ['ennishop', 'epishop', 'equishop'])
118
119
    def test_suffix(self):
120
        res = techniques.suffixify(self.words)
121
        self.assertEqual(res[:3], ['shopage', 'shopable', 'shopible'])
122
123
    def test_duplifix(self):
124
        res = techniques.duplifixify(self.words)
125
        self.assertEqual(res[:3], ['shop ahop', 'shop bhop', 'shop chop'])
126
127
    def test_duplifix_duplicates(self):
128
        res = techniques.duplifixify(self.words)
129
        self.assertTrue('shop shop' not in res)
130
131
    def test_disfix(self):
132
        words = ['propagating', 'gigantic']
133
        res = techniques.disfixify(words)
134
        self.assertEqual(res, ['pagating', 'antic'])
135
136
    def test_disfix_nosingle_pairs(self):
137
        words = ['shop', 'prop']
138
        res = techniques.disfixify(words)
139
        self.assertEqual(res, ['shop', 'prop'])
140
141
    def test_disfix_novowels(self):
142
        words = ['shp', 'prp']
143
        res = techniques.disfixify(words)
144
        self.assertEqual(res, words)
145
146
    def test_disfix_noconsonants(self):
147
        words = ['oooaeoa']
148
        res = techniques.disfixify(words)
149
        self.assertEqual(res, words)
150
151
    def test_infix(self):
152
        words = ['sophisticated']
153
        res = techniques.infixify(words)
154
        expected = ['sophistiqacated', 'sophistiqecated',
155
                    'sophistiqicated', 'sophistiqocated']
156
        self.assertEqual(res[0:4], expected)
157
158
    def test_infix_novowels(self):
159
        words = ['shp', 'prp']
160
        res = techniques.infixify(words)
161
        self.assertEqual(res, words)
162
163
    def test_infix_noconsonants(self):
164
        words = ['oooaeoa']
165
        res = techniques.infixify(words)
166
        self.assertEqual(res, words)
167
168
    def test_infix_nosingle_pairs(self):
169
        words = ['shop', 'prop']
170
        res = techniques.infixify(words)
171
        self.assertEqual(res, words)
172
173
    def test_simulfix(self):
174
        res = techniques.simulfixify(self.words)
175
        self.assertIsInstance(res, list)
176
        self.assertGreater(len(res), len(self.words))
177
        # Confirm that the pairs were added to each word
178
        for word in res:
179
            self.assertEqual(len(self.words[0]) + 2, len(word))
180
181
    def test_simulfix_custom_pairs(self):
182
        res = techniques.simulfixify(self.words, pairs=['ab', 'ec', 'oz'])
183
        self.assertEqual(res, ['shabop', 'shecop', 'shozop'])
184
185
    def test_simulfix_empty_strings(self):
186
        res = techniques.simulfixify(['', ''], pairs=['ab', 'ec'])
187
        self.assertEqual(res, ['ab', 'ec', 'ab', 'ec'])
188
189
    def test_simulfix_short_words(self):
190
        res = techniques.simulfixify(['f', 'b', 'a'], pairs=['ab', 'ec'])
191
        expected = ['abf', 'ecf', 'abb', 'ecb', 'aba', 'eca']
192
        self.assertEqual(res, expected)
193
194
195
class MakeFounderProductNameTestCase(unittest.TestCase):
196
197
    def test_simple(self):
198
        self.assertEqual(
199
            techniques.make_founder_product_name(
200
                'Foo', 'Bar', 'Goods'), 'F & B Goods')
201
202
    def test_simple_lowercase(self):
203
        self.assertNotEqual(
204
            techniques.make_founder_product_name(
205
                'Foo', 'Bar', 'Goods'), 'foo bar & co goods')
206
207
208
class MakeNameAlliterationTestCase(unittest.TestCase):
209
210
    def test_simple(self):
211
        original = ['jamba', 'juice', 'dancing', 'tornado',
212
                    'disco', 'wicked', 'tomato']
213
        updated = ['dancing disco', 'disco dancing', 'jamba juice',
214
                   'juice jamba', 'tomato tornado', 'tornado tomato']
215
        self.assertEqual(
216
            techniques.make_name_alliteration(original), updated)
217
218
    def test_divider(self):
219
        original = ['content', 'applesauce', 'candor', 'character']
220
        updated = ['candor & character', 'candor & content',
221
                   'character & candor', 'character & content',
222
                   'content & candor', 'content & character']
223
        self.assertEqual(
224
            techniques.make_name_alliteration(
225
                original, divider=' & '), updated)
226
227
228
class MakeNameAbbreviationTestCase(unittest.TestCase):
229
230
    def test_simple(self):
231
        self.assertEqual(
232
            techniques.make_name_abbreviation(
233
                ['Badische', 'Anilin', 'Soda', 'Fabrik']), 'BASF')
234
235
236
class MakeVowelTestCase(unittest.TestCase):
237
238
    def test_a(self):
239
        self.assertEqual(techniques.make_vowel(
240
            ['brad', 'angelina'], r'a{1}', 'a'), ['brangelina'])
241
242
    def test_e(self):
243
        self.assertEqual(techniques.make_vowel(
244
            ['street', 'credence'], r'e{1}', 'e'), ['stredence'])
245
246
    def test_i(self):
247
        self.assertEqual(techniques.make_vowel(
248
            ['stripe', 'wild'], r'i{1}', 'i'), ['strild'])
249
250
    def test_o(self):
251
        self.assertEqual(techniques.make_vowel(
252
            ['strode', 'pork'], r'o{1}', 'o'), ['strork'])
253
254
    def test_u(self):
255
        self.assertEqual(techniques.make_vowel(
256
            ['true', 'crude'], r'u{1}', 'u'), ['trude'])
257
258
    def test_no_substring(self):
259
        """Check for values that aren't found in the regex list."""
260
        self.assertEqual(techniques.make_vowel(
261
            ['matching', 'not'], r'a{1}', 'a'), [])
262
263
264
class MakePortmanteauDefaultVowelTestCase(unittest.TestCase):
265
266
    def test_simple(self):
267
        self.assertEqual(
268
            techniques.make_portmanteau_default_vowel(
269
                ['sweet', 'potato', 'nifty', 'gadget', 'widgets']),
270
            ['potadget', 'gadgeet', 'widgeet'])
271
272
273
class MakemakePortmanteauSplitTestCase(unittest.TestCase):
274
275
    def test_2words(self):
276
        self.assertEqual(
277
            techniques.make_portmanteau_split(['dad', 'cool']),
278
            ['dadool', 'dadool', 'datool', 'dasool', 'dazool',
279
             'daxool', 'cocad', 'coad', 'colad', 'cotad',
280
             'cosad', 'cozad', 'coxad'])
281
282
    def test_results_count(self):
283
        self.assertEqual(
284
            len(techniques.make_portmanteau_split(
285
                ['dad', 'neat', 'cool'])), 40)
286
        self.assertEqual(
287
            len(techniques.make_portmanteau_split(
288
                ['dad', 'neat', 'cool', 'nifty'])), 58)
289
        self.assertEqual(
290
            len(techniques.make_portmanteau_split(
291
                ['dad', 'neat', 'cool', 'nifty', 'super', 'duper'])), 166)
292
293
294
class MakePunctuatorTestCase(unittest.TestCase):
295
296
    def test_simple(self):
297
        self.assertEqual(
298
            techniques.make_punctuator(['delicious'], 'i'),
299
            ['deli-ci-ous', 'deli.ci.ous'])
300
301
302
class MakeVowelifyTestCase(unittest.TestCase):
303
304
    def test_simple(self):
305
        self.assertEqual(
306
            techniques.make_vowelify(
307
                ['nautical', 'monster']), ['nautica', 'monste'])
308
309
310
class MakemisspellingTestCase(unittest.TestCase):
311
312
    def setUp(self):
313
        self.words = ['effects', 'phonics', 'glee', 'cron', 'chrono']
314
        self.expected = ['phonix', 'ephphects', 'gly', 'crawn', 'krono']
315
316
    def test_simple(self):
317
        res = techniques.make_misspelling(self.words)
318
        for word in self.expected:
319
            assert word in res
320
321
322
class PigLatinTestCase(unittest.TestCase):
323
324
    def test_simple(self):
325
        """Basic test."""
326
        self.assertEqual(
327
            techniques.pig_latinize(['rad']), ['adray'])
328
329
    def test_custom_postfix_value(self):
330
        """Basic test."""
331
        self.assertEqual(
332
            techniques.pig_latinize(['rad'], postfix='ey'), ['adrey'])
333
334
    def test_bad_postfix_value(self):
335
        """Basic test."""
336
        with self.assertRaises(TypeError):
337
            techniques.pig_latinize(['rad'], postfix=1223)
338
339
340
class AcronymLastnameTestCase(unittest.TestCase):
341
342
    def test_simple(self):
343
        desc = 'Amazingly cool product'
344
        self.assertEqual(
345
            'ACP McDonald', techniques.acronym_lastname(desc, 'McDonald'))
346
347
    def test_simple_nostopwords(self):
348
        desc = 'A cool product'
349
        self.assertEqual(
350
            'CP McDonald', techniques.acronym_lastname(desc, 'McDonald'))
351
352
353
class GetDescriptorsTestCase(unittest.TestCase):
354
355
    def test_complex(self):
356
        self.assertEqual(techniques.get_descriptors(
357
            ['Jumping', 'Fly', 'Monkey', 'Dog', 'Action']),
358
            {'VBG': ['Jumping'],
359
             'NNP': ['Fly', 'Monkey', 'Dog', 'Action']})
360
361
362
class MakeDescriptorsTestCase(unittest.TestCase):
363
364
    def test_simple(self):
365
        self.assertEqual(techniques.make_descriptors(
366
            {'VBG': ['Jumping'], 'RB': ['Fly'],
367
             'NNP': ['Monkey', 'Dog', 'Action']}),
368
            ['Monkey Fly', 'Fly Monkey', 'Action Fly', 'Dog Fly',
369
             'Fly Dog', 'Fly Action'])
370
371
372
class AllPrefixesToFirstVowelTestCase(unittest.TestCase):
373
374
    def test_simple(self):
375
        word = 'umbrellas'
376
        expected = [
377
            'Bumbrellas', 'Cumbrellas', 'Dumbrellas', 'Fumbrellas',
378
            'Gumbrellas', 'Humbrellas', 'Jumbrellas', 'Kumbrellas',
379
            'Lumbrellas', 'Mumbrellas', 'Numbrellas', 'Pumbrellas',
380
            'Qumbrellas', 'Rumbrellas', 'Sumbrellas', 'Tumbrellas',
381
            'Vumbrellas', 'Wumbrellas', 'Xumbrellas', 'Yumbrellas',
382
            'Zumbrellas']
383
        self.assertEqual(techniques.all_prefix_first_vowel(word), expected)
384
385
386
class RecycleTestCase(unittest.TestCase):
387
388
    def test_pig_latinize(self):
389
        words = techniques.pig_latinize(['purring', 'cats'])
390
        self.assertEqual(techniques.recycle(
391
            words, techniques.pig_latinize),
392
            ['urringpaywayway', 'atscaywayway'])
393
394
    def test_portmanteau(self):
395
        words = ['ratchet', 'broccoli', 'potato', 'gadget', 'celery', 'hammer']
396
        res = techniques.recycle(
397
            words, techniques.make_portmanteau_default_vowel)
398
        expected = ['potatchelery', 'potatchelery', 'potadgelery',
399
                    'potadgelery', 'potammelery', 'potammelery',
400
                    'ratchelery', 'ratchelery']
401
        self.assertEqual(res, expected)
402
403
404
class SuperScrubTestCase(unittest.TestCase):
405
406
    def test_uniq(self):
407
        data = {'words': {'technique': ['words', 'words']}}
408
        self.assertEqual(
409
            techniques.super_scrub(data)['words']['technique'], ['words'])
410
411
    def test_remove_odd(self):
412
        data = {'words': {'technique': ['asdsaasdokokk', 'words']}}
413
        self.assertEqual(
414
            techniques.super_scrub(data)['words']['technique'], ['words'])
415
416
    def test_cleansort(self):
417
        data = {'words': {'technique': ['!!@words', 'radio0']}}
418
        self.assertEqual(
419
            techniques.super_scrub(data)['words']['technique'],
420
            ['radio', 'words'])
421