Skip to content

Commit 35c4044

Browse files
author
BNAndras
committed
Minor tweaks to generator
1 parent c736509 commit 35c4044

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

exercises/practice/gigasecond/.meta/spec_generator.lua

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@ local function components(moment)
22
return moment:match("(%d%d%d%d)%-(%d%d)%-(%d%d)T?(%d*):?(%d*):?(%d*)")
33
end
44

5-
local function to_num(str)
6-
if str ~= nil and str ~= '' then
7-
return tonumber(str)
5+
local function map_to_num(...)
6+
local t = {...}
7+
for i, str in ipairs(t) do
8+
if str ~= nil and str ~= '' then
9+
t[i] = tonumber(str)
10+
else
11+
t[i] = 0
12+
end
813
end
9-
return 0
14+
return table.unpack(t)
1015
end
1116

1217
return {
1318
module_name = 'gigasecond',
1419

1520
generate_test = function(case)
16-
local year, month, day, hour, min, sec = components(case.input.moment)
17-
year, month, day = to_num(year), to_num(month), to_num(day)
18-
hour, min, sec = to_num(hour), to_num(min), to_num(sec)
19-
20-
local e_year, e_month, e_day, e_hour, e_min, e_sec = components(case.expected)
21-
e_year, e_month, e_day = to_num(e_year), to_num(e_month), to_num(e_day)
22-
e_hour, e_min, e_sec = to_num(e_hour), to_num(e_min), to_num(e_sec)
21+
local year, month, day, hour, min, sec = map_to_num(components(case.input.moment))
22+
local e_year, e_month, e_day, e_hour, e_min, e_sec = map_to_num(components(case.expected))
2323

2424
local template = [[
2525
local momentA = os.time({ year = %d, month = %d, day = %d, hour = %d, min = %d, sec = %d })
2626
local momentB = os.time({ year = %d, month = %d, day = %d, hour = %d, min = %d, sec = %d })
27-
local result = gigasecond.anniversary(momentA)
27+
local actual = gigasecond.anniversary(momentA)
2828
local expected = os.date('!%%x', momentB)
29-
assert.are.equals(expected, result)]]
29+
assert.are.equals(expected, actual)]]
3030

3131
return template:format(
3232
year, month, day, hour, min, sec,

exercises/practice/gigasecond/gigasecond_spec.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,40 @@ describe('gigasecond', function()
44
it('date only specification of time', function()
55
local momentA = os.time({ year = 2011, month = 4, day = 25, hour = 0, min = 0, sec = 0 })
66
local momentB = os.time({ year = 2043, month = 1, day = 1, hour = 1, min = 46, sec = 40 })
7-
local result = gigasecond.anniversary(momentA)
7+
local actual = gigasecond.anniversary(momentA)
88
local expected = os.date('!%x', momentB)
9-
assert.are.equals(expected, result)
9+
assert.are.equals(expected, actual)
1010
end)
1111

1212
it('second test for date only specification of time', function()
1313
local momentA = os.time({ year = 1977, month = 6, day = 13, hour = 0, min = 0, sec = 0 })
1414
local momentB = os.time({ year = 2009, month = 2, day = 19, hour = 1, min = 46, sec = 40 })
15-
local result = gigasecond.anniversary(momentA)
15+
local actual = gigasecond.anniversary(momentA)
1616
local expected = os.date('!%x', momentB)
17-
assert.are.equals(expected, result)
17+
assert.are.equals(expected, actual)
1818
end)
1919

2020
it('third test for date only specification of time', function()
2121
local momentA = os.time({ year = 1959, month = 7, day = 19, hour = 0, min = 0, sec = 0 })
2222
local momentB = os.time({ year = 1991, month = 3, day = 27, hour = 1, min = 46, sec = 40 })
23-
local result = gigasecond.anniversary(momentA)
23+
local actual = gigasecond.anniversary(momentA)
2424
local expected = os.date('!%x', momentB)
25-
assert.are.equals(expected, result)
25+
assert.are.equals(expected, actual)
2626
end)
2727

2828
it('full time specified', function()
2929
local momentA = os.time({ year = 2015, month = 1, day = 24, hour = 22, min = 0, sec = 0 })
3030
local momentB = os.time({ year = 2046, month = 10, day = 2, hour = 23, min = 46, sec = 40 })
31-
local result = gigasecond.anniversary(momentA)
31+
local actual = gigasecond.anniversary(momentA)
3232
local expected = os.date('!%x', momentB)
33-
assert.are.equals(expected, result)
33+
assert.are.equals(expected, actual)
3434
end)
3535

3636
it('full time with day roll-over', function()
3737
local momentA = os.time({ year = 2015, month = 1, day = 24, hour = 23, min = 59, sec = 59 })
3838
local momentB = os.time({ year = 2046, month = 10, day = 3, hour = 1, min = 46, sec = 39 })
39-
local result = gigasecond.anniversary(momentA)
39+
local actual = gigasecond.anniversary(momentA)
4040
local expected = os.date('!%x', momentB)
41-
assert.are.equals(expected, result)
41+
assert.are.equals(expected, actual)
4242
end)
4343
end)

0 commit comments

Comments
 (0)