Completed
Push — master ( 6dc915...5c7f60 )
by Chris
03:57
created

test_simple_array_spaced()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
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_infix(self):
132
        # TODO
133
        pass
134
135
    def test_disfix(self):
136
        # TODO
137
        pass
138
139
    def test_simulfix(self):
140
        res = techniques.simulfixify(self.words)
141
        self.assertIsInstance(res, list)
142
        self.assertGreater(len(res), len(self.words))
143
        # Confirm that the pairs were added to each word
144
        for word in res:
145
            self.assertEqual(len(self.words[0]) + 2, len(word))
146
147
    def test_simulfix_custom_pairs(self):
148
        res = techniques.simulfixify(self.words, pairs=['ab', 'ec', 'oz'])
149
        self.assertEqual(res, ['shabop', 'shecop', 'shozop'])
150
151
    def test_simulfix_empty_strings(self):
152
        res = techniques.simulfixify(['', ''], pairs=['ab', 'ec'])
153
        self.assertEqual(res, ['ab', 'ec', 'ab', 'ec'])
154
155
    def test_simulfix_short_words(self):
156
        res = techniques.simulfixify(['f', 'b', 'a'], pairs=['ab', 'ec'])
157
        expected = ['abf', 'ecf', 'abb', 'ecb', 'aba', 'eca']
158
        self.assertEqual(res, expected)
159
160
161
class MakeFounderProductNameTestCase(unittest.TestCase):
162
163
    def test_simple(self):
164
        self.assertEqual(
165
            techniques.make_founder_product_name(
166
                'Foo', 'Bar', 'Goods'), 'F & B Goods')
167
168
    def test_simple_lowercase(self):
169
        self.assertNotEqual(
170
            techniques.make_founder_product_name(
171
                'Foo', 'Bar', 'Goods'), 'foo bar & co goods')
172
173
174
class MakeNameAlliterationTestCase(unittest.TestCase):
175
176
    def test_simple(self):
177
        original = ['jamba', 'juice', 'dancing', 'tornado',
178
                    'disco', 'wicked', 'tomato']
179
        updated = ['dancing disco', 'disco dancing', 'jamba juice',
180
                   'juice jamba', 'tomato tornado', 'tornado tomato']
181
        self.assertEqual(
182
            techniques.make_name_alliteration(original), updated)
183
184
    def test_divider(self):
185
        original = ['content', 'applesauce', 'candor', 'character']
186
        updated = ['candor & character', 'candor & content',
187
                   'character & candor', 'character & content',
188
                   'content & candor', 'content & character']
189
        self.assertEqual(
190
            techniques.make_name_alliteration(
191
                original, divider=' & '), updated)
192
193
194
class MakeNameAbbreviationTestCase(unittest.TestCase):
195
196
    def test_simple(self):
197
        self.assertEqual(
198
            techniques.make_name_abbreviation(
199
                ['Badische', 'Anilin', 'Soda', 'Fabrik']), 'BASF')
200
201
202
class MakeVowelTestCase(unittest.TestCase):
203
204
    def test_a(self):
205
        self.assertEqual(techniques.make_vowel(
206
            ['brad', 'angelina'], r'a{1}', 'a'), ['brangelina'])
207
208
    def test_e(self):
209
        self.assertEqual(techniques.make_vowel(
210
            ['street', 'credence'], r'e{1}', 'e'), ['stredence'])
211
212
    def test_i(self):
213
        self.assertEqual(techniques.make_vowel(
214
            ['stripe', 'wild'], r'i{1}', 'i'), ['strild'])
215
216
    def test_o(self):
217
        self.assertEqual(techniques.make_vowel(
218
            ['strode', 'pork'], r'o{1}', 'o'), ['strork'])
219
220
    def test_u(self):
221
        self.assertEqual(techniques.make_vowel(
222
            ['true', 'crude'], r'u{1}', 'u'), ['trude'])
223
224
    def test_no_substring(self):
225
        """Check for values that aren't found in the regex list."""
226
        self.assertEqual(techniques.make_vowel(
227
            ['matching', 'not'], r'a{1}', 'a'), [])
228
229
230
class MakePortmanteauDefaultVowelTestCase(unittest.TestCase):
231
232
    def test_simple(self):
233
        self.assertEqual(
234
            techniques.make_portmanteau_default_vowel(
235
                ['sweet', 'potato', 'nifty', 'gadget', 'widgets']),
236
            ['potadget', 'gadgeet', 'widgeet'])
237
238
239
class MakemakePortmanteauSplitTestCase(unittest.TestCase):
240
241
    def test_2words(self):
242
        self.assertEqual(
243
            techniques.make_portmanteau_split(['dad', 'cool']),
244
            ['dadool', 'dadool', 'datool', 'dasool', 'dazool',
245
             'daxool', 'cocad', 'coad', 'colad', 'cotad',
246
             'cosad', 'cozad', 'coxad'])
247
248
    def test_results_count(self):
249
        self.assertEqual(
250
            len(techniques.make_portmanteau_split(
251
                ['dad', 'neat', 'cool'])), 40)
252
        self.assertEqual(
253
            len(techniques.make_portmanteau_split(
254
                ['dad', 'neat', 'cool', 'nifty'])), 58)
255
        self.assertEqual(
256
            len(techniques.make_portmanteau_split(
257
                ['dad', 'neat', 'cool', 'nifty', 'super', 'duper'])), 166)
258
259
260
class MakePunctuatorTestCase(unittest.TestCase):
261
262
    def test_simple(self):
263
        self.assertEqual(
264
            techniques.make_punctuator(['delicious'], 'i'),
265
            ['deli-ci-ous', 'deli.ci.ous'])
266
267
268
class MakeVowelifyTestCase(unittest.TestCase):
269
270
    def test_simple(self):
271
        self.assertEqual(
272
            techniques.make_vowelify(
273
                ['nautical', 'monster']), ['nautica', 'monste'])
274
275
276
class MakemisspellingTestCase(unittest.TestCase):
277
278
    def setUp(self):
279
        self.words = ['effects', 'phonics', 'glee', 'cron', 'chrono']
280
        self.expected = ['phonix', 'ephphects', 'gly', 'crawn', 'krono']
281
282
    def test_simple(self):
283
        res = techniques.make_misspelling(self.words)
284
        for word in self.expected:
285
            assert word in res
286
287
288
class PigLatinTestCase(unittest.TestCase):
289
290
    def test_simple(self):
291
        """Basic test."""
292
        self.assertEqual(
293
            techniques.pig_latinize(['rad']), ['adray'])
294
295
    def test_custom_postfix_value(self):
296
        """Basic test."""
297
        self.assertEqual(
298
            techniques.pig_latinize(['rad'], postfix='ey'), ['adrey'])
299
300
    def test_bad_postfix_value(self):
301
        """Basic test."""
302
        with self.assertRaises(TypeError):
303
            techniques.pig_latinize(['rad'], postfix=1223)
304
305
306
class AcronymLastnameTestCase(unittest.TestCase):
307
308
    def test_simple(self):
309
        desc = 'Amazingly cool product'
310
        self.assertEqual(
311
            'ACP McDonald', techniques.acronym_lastname(desc, 'McDonald'))
312
313
    def test_simple_nostopwords(self):
314
        desc = 'A cool product'
315
        self.assertEqual(
316
            'CP McDonald', techniques.acronym_lastname(desc, 'McDonald'))
317
318
319
class GetDescriptorsTestCase(unittest.TestCase):
320
321
    def test_complex(self):
322
        self.assertEqual(techniques.get_descriptors(
323
            ['Jumping', 'Fly', 'Monkey', 'Dog', 'Action']),
324
            {'VBG': ['Jumping'],
325
             'NNP': ['Fly', 'Monkey', 'Dog', 'Action']})
326
327
328
class MakeDescriptorsTestCase(unittest.TestCase):
329
330
    def test_simple(self):
331
        self.assertEqual(techniques.make_descriptors(
332
            {'VBG': ['Jumping'], 'RB': ['Fly'],
333
             'NNP': ['Monkey', 'Dog', 'Action']}),
334
            ['Monkey Fly', 'Fly Monkey', 'Action Fly', 'Dog Fly',
335
             'Fly Dog', 'Fly Action'])
336
337
338
class AllPrefixesToFirstVowelTestCase(unittest.TestCase):
339
340
    def test_simple(self):
341
        word = 'umbrellas'
342
        expected = [
343
            'Bumbrellas', 'Cumbrellas', 'Dumbrellas', 'Fumbrellas',
344
            'Gumbrellas', 'Humbrellas', 'Jumbrellas', 'Kumbrellas',
345
            'Lumbrellas', 'Mumbrellas', 'Numbrellas', 'Pumbrellas',
346
            'Qumbrellas', 'Rumbrellas', 'Sumbrellas', 'Tumbrellas',
347
            'Vumbrellas', 'Wumbrellas', 'Xumbrellas', 'Yumbrellas',
348
            'Zumbrellas']
349
        self.assertEqual(techniques.all_prefix_first_vowel(word), expected)
350
351
352
class RecycleTestCase(unittest.TestCase):
353
354
    def test_pig_latinize(self):
355
        words = techniques.pig_latinize(['purring', 'cats'])
356
        self.assertEqual(techniques.recycle(
357
            words, techniques.pig_latinize),
358
            ['urringpaywayway', 'atscaywayway'])
359
360
    def test_portmanteau(self):
361
        words = ['ratchet', 'broccoli', 'potato', 'gadget', 'celery', 'hammer']
362
        res = techniques.recycle(
363
            words, techniques.make_portmanteau_default_vowel)
364
        expected = ['potatchelery', 'potatchelery', 'potadgelery',
365
                    'potadgelery', 'potammelery', 'potammelery',
366
                    'ratchelery', 'ratchelery']
367
        self.assertEqual(res, expected)
368
369
370
class SuperScrubTestCase(unittest.TestCase):
371
372
    def test_uniq(self):
373
        data = {'words': {'technique': ['words', 'words']}}
374
        self.assertEqual(
375
            techniques.super_scrub(data)['words']['technique'], ['words'])
376
377
    def test_remove_odd(self):
378
        data = {'words': {'technique': ['asdsaasdokokk', 'words']}}
379
        self.assertEqual(
380
            techniques.super_scrub(data)['words']['technique'], ['words'])
381
382
    def test_cleansort(self):
383
        data = {'words': {'technique': ['!!@words', 'radio0']}}
384
        self.assertEqual(
385
            techniques.super_scrub(data)['words']['technique'],
386
            ['radio', 'words'])
387