|
1 |
| --- problem specification version 1.4.0 |
2 |
| -local word_count = require('word-count').word_count |
| 1 | +local word_count = require('word-count') |
3 | 2 |
|
4 | 3 | describe('word-count', function()
|
5 |
| - it('counts one word', function() |
6 |
| - local result = word_count('word') |
7 |
| - local expected = { word = 1 } |
| 4 | + it('count one word', function() |
| 5 | + local result = word_count.count_words('word') |
| 6 | + local expected = { ['word'] = 1 } |
8 | 7 | assert.are.same(expected, result)
|
9 | 8 | end)
|
10 | 9 |
|
11 |
| - it('counts one of each', function() |
12 |
| - local result = word_count('one of each') |
13 |
| - local expected = { one = 1, of = 1, each = 1 } |
| 10 | + it('count one of each word', function() |
| 11 | + local result = word_count.count_words('one of each') |
| 12 | + local expected = { ['each'] = 1, ['of'] = 1, ['one'] = 1 } |
14 | 13 | assert.are.same(expected, result)
|
15 | 14 | end)
|
16 | 15 |
|
17 |
| - it('counts multiple occurrences', function() |
18 |
| - local result = word_count('one fish two fish red fish blue fish') |
19 |
| - local expected = { one = 1, fish = 4, two = 1, red = 1, blue = 1 } |
| 16 | + it('multiple occurrences of a word', function() |
| 17 | + local result = word_count.count_words('one fish two fish red fish blue fish') |
| 18 | + local expected = { ['blue'] = 1, ['fish'] = 4, ['one'] = 1, ['red'] = 1, ['two'] = 1 } |
20 | 19 | assert.are.same(expected, result)
|
21 | 20 | end)
|
22 | 21 |
|
23 | 22 | it('handles cramped lists', function()
|
24 |
| - local result = word_count('one,two,three') |
25 |
| - local expected = { one = 1, two = 1, three = 1 } |
| 23 | + local result = word_count.count_words('one,two,three') |
| 24 | + local expected = { ['one'] = 1, ['three'] = 1, ['two'] = 1 } |
26 | 25 | assert.are.same(expected, result)
|
27 | 26 | end)
|
28 | 27 |
|
29 | 28 | it('handles expanded lists', function()
|
30 |
| - local result = word_count('one,\ntwo,\nthree') |
31 |
| - local expected = { one = 1, two = 1, three = 1 } |
| 29 | + local result = word_count.count_words('one,\ntwo,\nthree') |
| 30 | + local expected = { ['one'] = 1, ['three'] = 1, ['two'] = 1 } |
32 | 31 | assert.are.same(expected, result)
|
33 | 32 | end)
|
34 | 33 |
|
35 |
| - it('ignores punctuation', function() |
36 |
| - local result = word_count('car : carpet as java : javascript!!&@$%^&') |
37 |
| - local expected = { car = 1, carpet = 1, as = 1, java = 1, javascript = 1 } |
| 34 | + it('ignore punctuation', function() |
| 35 | + local result = word_count.count_words('car: carpet as java: javascript!!&@$%^&') |
| 36 | + local expected = { ['as'] = 1, ['car'] = 1, ['carpet'] = 1, ['java'] = 1, ['javascript'] = 1 } |
38 | 37 | assert.are.same(expected, result)
|
39 | 38 | end)
|
40 | 39 |
|
41 |
| - it('includes numbers', function() |
42 |
| - local result = word_count('testing, 1, 2 testing') |
43 |
| - local expected = { testing = 2, ['1'] = 1, ['2'] = 1 } |
| 40 | + it('include numbers', function() |
| 41 | + local result = word_count.count_words('testing, 1, 2 testing') |
| 42 | + local expected = { ['1'] = 1, ['2'] = 1, ['testing'] = 2 } |
44 | 43 | assert.are.same(expected, result)
|
45 | 44 | end)
|
46 | 45 |
|
47 |
| - it('normalizes case', function() |
48 |
| - local result = word_count('go Go GO Stop stop') |
49 |
| - local expected = { go = 3, stop = 2 } |
| 46 | + it('normalize case', function() |
| 47 | + local result = word_count.count_words('go Go GO Stop stop') |
| 48 | + local expected = { ['go'] = 3, ['stop'] = 2 } |
50 | 49 | assert.are.same(expected, result)
|
51 | 50 | end)
|
52 | 51 |
|
53 |
| - it('counts with apostrophes', function() |
54 |
| - local result = word_count("First: don't laugh. Then: don't cry.") |
55 |
| - local expected = { first = 1, ["don't"] = 2, laugh = 1, ['then'] = 1, cry = 1 } |
| 52 | + it('with apostrophes', function() |
| 53 | + local result = word_count.count_words("'First: don't laugh. Then: don't cry. You're getting it.'") |
| 54 | + local expected = { |
| 55 | + ["don't"] = 2, |
| 56 | + ["you're"] = 1, |
| 57 | + ['cry'] = 1, |
| 58 | + ['first'] = 1, |
| 59 | + ['getting'] = 1, |
| 60 | + ['it'] = 1, |
| 61 | + ['laugh'] = 1, |
| 62 | + ['then'] = 1 |
| 63 | + } |
56 | 64 | assert.are.same(expected, result)
|
57 | 65 | end)
|
58 | 66 |
|
59 |
| - it('counts with quotation', function() |
60 |
| - local result = word_count("Joe can't tell between 'large' and large.") |
61 |
| - local expected = { joe = 1, ["can't"] = 1, tell = 1, between = 1, large = 2, ["and"] = 1 } |
| 67 | + it('with quotations', function() |
| 68 | + local result = word_count.count_words("Joe can't tell between 'large' and large.") |
| 69 | + local expected = { ["can't"] = 1, ['and'] = 1, ['between'] = 1, ['joe'] = 1, ['large'] = 2, ['tell'] = 1 } |
62 | 70 | assert.are.same(expected, result)
|
63 | 71 | end)
|
64 | 72 |
|
65 |
| - it('counts with substrings from the beginning', function() |
66 |
| - local result = word_count("Joe can't tell between app, apple and a.") |
67 |
| - local expected = { joe = 1, ["can't"] = 1, tell = 1, between = 1, app = 1, apple = 1, ["and"] = 1, a = 1 } |
| 73 | + it('substrings from the beginning', function() |
| 74 | + local result = word_count.count_words("Joe can't tell between app, apple and a.") |
| 75 | + local expected = { |
| 76 | + ["can't"] = 1, |
| 77 | + ['a'] = 1, |
| 78 | + ['and'] = 1, |
| 79 | + ['app'] = 1, |
| 80 | + ['apple'] = 1, |
| 81 | + ['between'] = 1, |
| 82 | + ['joe'] = 1, |
| 83 | + ['tell'] = 1 |
| 84 | + } |
68 | 85 | assert.are.same(expected, result)
|
69 | 86 | end)
|
70 | 87 |
|
71 |
| - it('does not count multiple spaces as a word', function() |
72 |
| - local result = word_count(' multiple whitespaces') |
73 |
| - local expected = { multiple = 1, whitespaces = 1 } |
| 88 | + it('multiple spaces not detected as a word', function() |
| 89 | + local result = word_count.count_words(' multiple whitespaces') |
| 90 | + local expected = { ['multiple'] = 1, ['whitespaces'] = 1 } |
74 | 91 | assert.are.same(expected, result)
|
75 | 92 | end)
|
76 | 93 |
|
77 | 94 | it('alternating word separators not detected as a word', function()
|
78 |
| - local result = word_count(",\n,one,\n ,two \n 'three'") |
79 |
| - local expected = { one = 1, two = 1, three = 1 } |
| 95 | + local result = word_count.count_words(",\n,one,\n ,two \n 'three'") |
| 96 | + local expected = { ['one'] = 1, ['three'] = 1, ['two'] = 1 } |
| 97 | + assert.are.same(expected, result) |
| 98 | + end) |
| 99 | + |
| 100 | + it('quotation for word with apostrophe', function() |
| 101 | + local result = word_count.count_words("can, can't, 'can't'") |
| 102 | + local expected = { ["can't"] = 2, ['can'] = 1 } |
80 | 103 | assert.are.same(expected, result)
|
81 | 104 | end)
|
82 | 105 | end)
|
0 commit comments