-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathspec_generator.moon
More file actions
34 lines (30 loc) · 1.14 KB
/
spec_generator.moon
File metadata and controls
34 lines (30 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{
module_name: 'SpaceAge',
test_helpers: [[
-- ----------------------------------------
-- Why do we need to test "approximately equal"?
-- See https://0.30000000000000004.com
epsilon = 1e-2
is_close_to = (state, arguments) ->
{a, b} = arguments
math.abs(a - b) <= epsilon
say = require 'say'
say\set 'assertion.approx_equal.positive', "Expected %s and %s to be within #{epsilon}"
say\set 'assertion.approx_equal.negative', "Expected %s and %s not to be within #{epsilon}"
assert\register 'assertion', 'approx_equal', is_close_to, 'assertion.approx_equal.positive', 'assertion.approx_equal.negative'
-- ----------------------------------------
]]
generate_test: (case, level) ->
local lines
if type(case.expected) == "table"
lines = {
"f = -> SpaceAge.age #{quote case.input.planet}, #{case.input.seconds}",
"assert.has.errors f, #{quote case.expected.error}"
}
else
lines = {
"result = SpaceAge.age #{quote case.input.planet}, #{case.input.seconds}",
"assert.approx_equal #{case.expected}, result"
}
table.concat [indent line, level for line in *lines], '\n'
}