Completed
Push — master ( 4d1361...6dc915 )
by Chris
03:58
created

namebot.tests.GetKeywordRelevancyMapTestCase   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 5
Duplicated Lines 0 %
Metric Value
dl 0
loc 5
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A namebot.tests.CategorizeWordType.setUp() 0 2 1
1
import unittest
2
from namebot import metrics
3
4
5
class GetNamedNumbersTestCase(unittest.TestCase):
6
7
    def test_basic(self):
8
        res = metrics.get_named_numbers_1_10(
9
            ['360 networks', 'Three Sixty networks'])
10
        self.assertEqual(res['data'], ['Three Sixty networks'])
11
        self.assertEqual(res['summary'], 'Of 2 words, 1 matched')
12
13
14
class NameLengthTestCase(unittest.TestCase):
15
16
    def test_basic(self):
17
        res = metrics.name_length(['short', 'medium', 'veryveryverylong'])
18
        self.assertEqual(res['data'], [5, 6, 16])
19
        self.assertEqual(
20
            res['summary'], 'Of 3 words, the average length of names is...9.0')
21
22
23
class NameVowelCountTestCase(unittest.TestCase):
24
25
    def test_basic(self):
26
        res = metrics.name_vowel_count(['neato'])
27
        self.assertEqual(res['data']['a'], 1)
28
        self.assertEqual(res['data']['e'], 1)
29
        self.assertEqual(res['data']['o'], 1)
30
        self.assertEqual(res['data']['i'], 0)
31
32
33
class NameStartsWithVowelTestCase(unittest.TestCase):
34
35
    def test_basic(self):
36
        res = metrics.name_starts_with_vowel(['aardvark', 'apple', 'banana'])
37
        self.assertEqual(res['data'], None)
38
        self.assertEqual(
39
            res['summary'],
40
            'Of 3 words, 2 or 67.0% are vowels as the first letter.')
41
42
    def test_diff_percentage(self):
43
        words = ['aardvark', 'apple', 'banana', 'fruit', 'orange', 'grape']
44
        res = metrics.name_starts_with_vowel(words)
45
        self.assertEqual(res['data'], None)
46
        self.assertEqual(
47
            res['summary'],
48
            'Of 6 words, 3 or 50.0% are vowels as the first letter.')
49
50
51
class GetSearchResultsTestCase(unittest.TestCase):
52
53
    def test_basic(self):
54
        pass
55
56
57
class GetDigitsFrequencyTestCase(unittest.TestCase):
58
59
    def test_basic(self):
60
        msg = ('Of 3 words, 3 have numbers in them, with a'
61
               ' total of 5 numbers found.')
62
        res = metrics.get_digits_frequency(['7-11', '24/7Networks', '360corp'])
63
        self.assertEqual(res['data'], ['7', '11', '24', '7', '360'])
64
        self.assertEqual(res['summary'], msg)
65
66
67
class GetFirstLetterFrequencyTestCase(unittest.TestCase):
68
69
    def test_basic(self):
70
        res = metrics.get_first_letter_frequency(['fjord', 'flower', 'apple'])
71
        self.assertEqual(res['data']['f'], 2)
72
        self.assertEqual(res['data']['a'], 1)
73
74
75
class GetSpecialCharsTestCase(unittest.TestCase):
76
77
    def test_basic(self):
78
        res = metrics.get_special_chars(['de.li.c.ious', 'flip-to', 'bit.ly'])
79
        self.assertEqual(res['data'], ['.', '.', '.', '-', '.'])
80
        self.assertEqual(
81
            res['summary'],
82
            '5 occurrences of special characters were found in 3 words.')
83
84
85
class GetWordTypesTestCase(unittest.TestCase):
86
87
    def test_basic(self):
88
        res = metrics.get_word_types(['apple', 'cat'])
89
        self.assertEqual(res['data'], [u'apple/NN', u'cat/NN'])
90
91
92
class GetNameSpacesTestCase(unittest.TestCase):
93
94
    def test_basic(self):
95
        res = metrics.get_name_spaces(
96
            ['Itsy bitsy spider co', 'Nifty widgets, Inc'])
97
        self.assertEqual(res['data'][0]['spaces'], 4)
98
        self.assertEqual(res['data'][1]['spaces'], 3)
99
100
101
class GetConsonantRepeatFrequencyTestCase(unittest.TestCase):
102
103
    def test_basic(self):
104
        words = ['cat']
105
        res = metrics.get_consonant_repeat_frequency(words)
106
        self.assertEqual(res, {
107
            'data': 1,
108
            'summary': None
109
        })
110
111
    def test_multiple(self):
112
        words = ['cat', 'foo', 'bar', 'quux']
113
        res = metrics.get_consonant_repeat_frequency(words)
114
        self.assertEqual(res, {
115
            'data': 4,
116
            'summary': None
117
        })
118
119
    def test_none(self):
120
        words = []
121
        res = metrics.get_consonant_repeat_frequency(words)
122
        self.assertEqual(res, {
123
            'data': 0,
124
            'summary': None
125
        })
126
127
128
class GetConsonantDuplicateRepeatFrequencyTestCase(unittest.TestCase):
129
130
    def test_basic(self):
131
        res = metrics.get_consonant_duplicate_repeat_frequency(
132
            ['cannon', 'fodder', 'grapple'])
133
        self.assertEqual(res['data'], 3)
134
135
136
class GetVowelRepeatFrequencyTestCase(unittest.TestCase):
137
138
    def test_basic(self):
139
        res = metrics.get_consonant_duplicate_repeat_frequency(
140
            ['food', 'beef', 'cheese'])
141
        self.assertEqual(res['data'], 3)
142
143
144
class GetAdjectiveVerbOrNounTestCase(unittest.TestCase):
145
146
    def test_only_nouns(self):
147
        res = metrics.get_adjective_verb_or_noun(['cat', 'dog'])
148
        self.assertEqual(res['data']['nouns'], 2)
149
        self.assertEqual(res['data']['verbs'], 0)
150
151
    def test_only_verbs(self):
152
        res = metrics.get_adjective_verb_or_noun(['jumping', 'flying'])
153
        self.assertEqual(res['data']['nouns'], 0)
154
        self.assertEqual(res['data']['verbs'], 2)
155
156
    def test_noun_verbs(self):
157
        res = metrics.get_adjective_verb_or_noun(['jumping', 'dog'])
158
        self.assertEqual(res['data']['nouns'], 1)
159
        self.assertEqual(res['data']['verbs'], 1)
160
161
162
class CategorizeWordType(unittest.TestCase):
163
164
    def setUp(self):
165
        self.words = ['rain', 'a lot of sunshine']
166
167
    def test_not_phrase(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
168
        res = metrics.categorize_word_type(self.words)
169
        self.assertEqual(res[1][1]['real'], 0)
170
        self.assertEqual(res[1][1]['phrase'], 50)
171
172
    def test_phrase(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
173
        res = metrics.categorize_word_type(self.words)
174
        self.assertEqual(res[0][1]['real'], 50)
175
        self.assertEqual(res[0][1]['phrase'], 0)
176