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
10 changes: 5 additions & 5 deletions exercises/practice/word-count/.meta/spec_generator.moon
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ kv_table = (tbl, level) ->
test_helpers: [[
-- ----------------------------------------------------------
same_kv = (state, arguments) ->
expected = arguments[1]
actual = arguments[2]
actual = arguments[1]
expected = arguments[2]
return false if #expected != #actual
for k, v in pairs expected
return false if actual[k] != v
true

say = require 'say'
say\set 'assertion.same_kv.positive', 'Expected\n%s\nto have the same keys and values as\n%s'
say\set 'assertion.same_kv.negative', 'Expected\n%s\nto not have the same keys and values as\n%s'
say\set 'assertion.same_kv.positive', 'Actual result\n%s\ndoes not have the same keys and values as expected\n%s'
say\set 'assertion.same_kv.negative', 'Actual result\n%s\nwas not supposed to be the same as expected\n%s'
assert\register 'assertion', 'same_kv', same_kv, 'assertion.same_kv.positive', 'assertion.same_kv.negative'
-- ----------------------------------------------------------
]]
Expand All @@ -33,7 +33,7 @@ kv_table = (tbl, level) ->
lines = {
"result = count_words #{json.encode case.input.sentence}",
"expected = #{kv_table case.expected, level}",
"assert.has.same_kv expected, result"
"assert.has.same_kv result, expected"
}
table.concat [indent line, level for line in *lines], '\n'
}
82 changes: 41 additions & 41 deletions exercises/practice/word-count/word_count_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import count_words from require 'word_count'
describe 'word-count', ->
-- ----------------------------------------------------------
same_kv = (state, arguments) ->
expected = arguments[1]
actual = arguments[2]
actual = arguments[1]
expected = arguments[2]
return false if #expected != #actual
for k, v in pairs expected
return false if actual[k] != v
true

say = require 'say'
say\set 'assertion.same_kv.positive', 'Expected\n%s\nto have the same keys and values as\n%s'
say\set 'assertion.same_kv.negative', 'Expected\n%s\nto not have the same keys and values as\n%s'
say\set 'assertion.same_kv.positive', 'Actual result\n%s\ndoes not have the same keys and values as expected\n%s'
say\set 'assertion.same_kv.negative', 'Actual result\n%s\nwas not supposed to be the same as the expected value.'
assert\register 'assertion', 'same_kv', same_kv, 'assertion.same_kv.positive', 'assertion.same_kv.negative'
-- ----------------------------------------------------------

Expand All @@ -21,135 +21,135 @@ describe 'word-count', ->
expected = {
word: 1,
}
assert.has.same_kv expected, result
assert.has.same_kv result, expected

pending 'count one of each word', ->
result = count_words "one of each"
expected = {
each: 1,
one: 1,
each: 1,
of: 1,
}
assert.has.same_kv expected, result
assert.has.same_kv result, expected

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

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

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

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

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

pending 'normalize case', ->
result = count_words "go Go GO Stop stop"
expected = {
go: 3,
stop: 2,
go: 3,
}
assert.has.same_kv expected, result
assert.has.same_kv result, expected

pending 'with apostrophes', ->
result = count_words "'First: don't laugh. Then: don't cry. You're getting it.'"
expected = {
then: 1,
laugh: 1,
cry: 1,
"you're": 1,
getting: 1,
"don't": 2,
it: 1,
first: 1,
getting: 1,
"you're": 1,
cry: 1,
laugh: 1,
it: 1,
}
assert.has.same_kv expected, result
assert.has.same_kv result, expected

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

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

pending 'multiple spaces not detected as a word', ->
result = count_words " multiple whitespaces"
expected = {
multiple: 1,
whitespaces: 1,
}
assert.has.same_kv expected, result
assert.has.same_kv result, expected

pending 'alternating word separators not detected as a word', ->
result = count_words ",\n,one,\n ,two \n 'three'"
expected = {
two: 1,
one: 1,
two: 1,
three: 1,
}
assert.has.same_kv expected, result
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,
}
assert.has.same_kv expected, result
assert.has.same_kv result, expected
2 changes: 1 addition & 1 deletion exercises/test_helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,5 @@ Useful for generating pretty tables mostly.

- dnd-character: `assert.between value, min, max`
- space-age: `assert.approx_equal #{case.expected}, result`
- word-count: `assert.has.same_kv table1, table2`:x
- word-count: `assert.has.same_kv result, expected`

Loading