Add baffling-birthdays#650
Conversation
| return s | ||
| end | ||
|
|
||
| package.loaded['utils'] = utils |
There was a problem hiding this comment.
This makes it so that they can be loaded via require 'utils' without creating a file to contain them
There was a problem hiding this comment.
Cool. I might steal that for moonscript.
9b164f2 to
8f6dc26
Compare
| local start = os.time { year = non_leap_year, month = 1, day = 1, hour = 12 } | ||
| for i = 1, count do | ||
| local offset = math.random(0, 364) | ||
| local t = start + offset * seconds_per_day | ||
| table.insert(birthdates, os.date('%Y-%m-%d', t)) |
There was a problem hiding this comment.
Fun fact: os.time normalizes the month and day:
os.date('%c', os.time({year = 2005, month = 1, day = 365}))
-- Sat Dec 31 12:00:00 2005There was a problem hiding this comment.
Thanks, that's a great trick! Unfortunately, os.time is slow enough that the tests take 3x as long if I use this trick.
| return s | ||
| end | ||
|
|
||
| package.loaded['utils'] = utils |
There was a problem hiding this comment.
Cool. I might steal that for moonscript.
| end | ||
|
|
||
| utils.stringify = function(x) | ||
| return ("'%s'"):format(x) |
There was a problem hiding this comment.
You might want to test if x contains single quotes.
There was a problem hiding this comment.
Good call. It turns out we already had a better stringify implementation in the word-count spec generator so I lifted that.
I also extracted some commonly used helpers so that they can be reused across spec generators.