diff --git a/exercises/practice/word-count/.meta/spec_generator.moon b/exercises/practice/word-count/.meta/spec_generator.moon index e17389d..89048d3 100644 --- a/exercises/practice/word-count/.meta/spec_generator.moon +++ b/exercises/practice/word-count/.meta/spec_generator.moon @@ -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' -- ---------------------------------------------------------- ]] @@ -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' } diff --git a/exercises/practice/word-count/word_count_spec.moon b/exercises/practice/word-count/word_count_spec.moon index a6877e3..3cdc0b4 100644 --- a/exercises/practice/word-count/word_count_spec.moon +++ b/exercises/practice/word-count/word_count_spec.moon @@ -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' -- ---------------------------------------------------------- @@ -21,113 +21,113 @@ 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" @@ -135,16 +135,16 @@ describe 'word-count', -> 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'" @@ -152,4 +152,4 @@ describe 'word-count', -> "can't": 2, can: 1, } - assert.has.same_kv expected, result + assert.has.same_kv result, expected diff --git a/exercises/test_helpers.md b/exercises/test_helpers.md index d739746..3a6c6cc 100644 --- a/exercises/test_helpers.md +++ b/exercises/test_helpers.md @@ -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`