Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion exercises/practice/word-count/.meta/example.moon
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ trim = (str) -> str\gsub("^'+", '')\gsub("'+$", '')
result = {}
for word in sentence\lower!\gmatch("[%w+']+")
w = trim word
result[w] = (result[w] or 0) + 1
if #w > 0
result[w] = (result[w] or 0) + 1
result
}
4 changes: 3 additions & 1 deletion exercises/practice/word-count/.meta/spec_generator.moon
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import json_string, kv_table from require 'test_helpers'
-- ----------------------------------------------------------
same_kv = (state, arguments) ->
actual = arguments[1]
return false if type(actual) != 'table'
expected = arguments[2]
return false if #expected != #actual
size = (t) -> #[k for k, _ in pairs t]
return false if size(expected) != size(actual)
for k, v in pairs expected
return false if actual[k] != v
true
Expand Down
52 changes: 27 additions & 25 deletions exercises/practice/word-count/word_count_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ describe 'word-count', ->
-- ----------------------------------------------------------
same_kv = (state, arguments) ->
actual = arguments[1]
return false if type(actual) != 'table'
expected = arguments[2]
return false if #expected != #actual
size = (t) -> #[k for k, _ in pairs t]
return false if size(expected) != size(actual)
for k, v in pairs expected
return false if actual[k] != v
true
Expand All @@ -26,58 +28,58 @@ describe 'word-count', ->
pending 'count one of each word', ->
result = count_words "one of each"
expected = {
each: 1,
of: 1,
each: 1,
one: 1,
}
assert.has.same_kv result, expected

pending 'multiple occurrences of a word', ->
result = count_words "one fish two fish red fish blue fish"
expected = {
two: 1,
blue: 1,
fish: 4,
one: 1,
red: 1,
blue: 1,
two: 1,
}
assert.has.same_kv result, expected

pending 'handles cramped lists', ->
result = count_words "one,two,three"
expected = {
two: 1,
three: 1,
one: 1,
three: 1,
}
assert.has.same_kv result, expected

pending 'handles expanded lists', ->
result = count_words "one,\ntwo,\nthree"
expected = {
two: 1,
three: 1,
one: 1,
three: 1,
}
assert.has.same_kv result, expected

pending 'ignore punctuation', ->
result = count_words "car: carpet as java: javascript!!&@$%^&"
expected = {
carpet: 1,
javascript: 1,
as: 1,
java: 1,
javascript: 1,
car: 1,
carpet: 1,
as: 1,
}
assert.has.same_kv result, expected

pending 'include numbers', ->
result = count_words "testing, 1, 2 testing"
expected = {
'1': 1,
testing: 2,
'2': 1,
testing: 2,
'1': 1,
}
assert.has.same_kv result, expected

Expand All @@ -92,40 +94,40 @@ describe 'word-count', ->
pending 'with apostrophes', ->
result = count_words "'First: don't laugh. Then: don't cry. You're getting it.'"
expected = {
first: 1,
it: 1,
laugh: 1,
"you're": 1,
cry: 1,
then: 1,
it: 1,
getting: 1,
"you're": 1,
"don't": 2,
first: 1,
cry: 1,
laugh: 1,
}
assert.has.same_kv result, expected

pending 'with quotations', ->
result = count_words "Joe can't tell between 'large' and large."
expected = {
tell: 1,
and: 1,
large: 2,
"can't": 1,
between: 1,
large: 2,
joe: 1,
and: 1,
between: 1,
}
assert.has.same_kv result, expected

pending 'substrings from the beginning', ->
result = count_words "Joe can't tell between app, apple and a."
expected = {
app: 1,
a: 1,
tell: 1,
apple: 1,
and: 1,
"can't": 1,
a: 1,
app: 1,
between: 1,
joe: 1,
and: 1,
apple: 1,
}
assert.has.same_kv result, expected

Expand All @@ -141,15 +143,15 @@ describe 'word-count', ->
result = count_words ",\n,one,\n ,two \n 'three'"
expected = {
two: 1,
three: 1,
one: 1,
three: 1,
}
assert.has.same_kv result, expected

pending 'quotation for word with apostrophe', ->
result = count_words "can, can't, 'can't'"
expected = {
"can't": 2,
can: 1,
"can't": 2,
}
assert.has.same_kv result, expected
Loading