diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/test_weather.lua | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/test/test_weather.lua b/test/test_weather.lua index cea4645..e7d7614 100644 --- a/test/test_weather.lua +++ b/test/test_weather.lua @@ -64,9 +64,20 @@ assert(weather.describe(nil) == 'Unknown', 'nil code words') assert(weather.deg(13.2) == '13\u{00B0}', 'rounds down') assert(weather.deg(13.5) == '14\u{00B0}', 'rounds half up') assert(weather.deg(-0.4) == '0\u{00B0}', 'just below zero reads 0') -assert(weather.deg(-2.6) == '-3\u{00B0}', 'negative rounds away from zero') +assert(weather.deg(-2.6) == '-3\u{00B0}', 'negative rounds to nearest') assert(weather.deg(nil) == '--', 'missing temperature is --, never 0') +-- Non-finite input must not raise (1e999 parses to inf from a cache line). +local NAN, INF = 0/0, math.huge +for _, bad in ipairs({ NAN, INF, -INF, 1e300, math.maxinteger }) do + assert(weather.deg(bad) == '--', 'deg non-finite ' .. tostring(bad)) + assert(weather.num(bad) == '--', 'num non-finite ' .. tostring(bad)) + assert(weather.duration(bad) == '--', 'duration non-finite ' .. tostring(bad)) + assert(weather.moon_icon(bad) == weather.ICON.unknown, 'moon_icon non-finite ' .. tostring(bad)) +end +assert(weather.sun_t(NAN, 1000, 2000) == 0, 'NaN now parks at 0') +assert(weather.age_str(NAN, 0) == '?', 'NaN age is ?') + assert(weather.num(77) == '77', 'plain number') assert(weather.num(39.6, '%') == '40%', 'rounded with suffix') assert(weather.num(0, '%') == '0%', 'zero is a real reading') |
