diff options
Diffstat (limited to 'test/test_weather.lua')
| -rw-r--r-- | test/test_weather.lua | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/test_weather.lua b/test/test_weather.lua index 739161b..95908ce 100644 --- a/test/test_weather.lua +++ b/test/test_weather.lua @@ -208,4 +208,18 @@ local exp = weather.parse( '"sys":{"sunrise":100,"sunset":200}}') assert(exp and exp.temp == 18, 'exponent form, got ' .. tostring(exp and exp.temp)) +-- === Staleness ============================================================ +-- 45 minutes is three missed fetches at the 15-minute interval, so one +-- transient failure does not flag the card. +assert(weather.is_stale(1000, 1000) == false, 'a fresh reading is not stale') +assert(weather.is_stale(1000, 1000 + 45 * 60) == false, 'exactly 45 min is the boundary') +assert(weather.is_stale(1000, 1000 + 45 * 60 + 1) == true, 'past 45 min is stale') +assert(weather.is_stale(nil, 1000) == true, 'no observation time counts as stale') + +-- The age string is what the card prints beside the city, so it must be short. +assert(weather.age_str(1000, 1000 + 90) == '1m', 'ninety seconds reads as 1m') +assert(weather.age_str(1000, 1000 + 3600) == '1h', 'an hour reads as 1h') +assert(weather.age_str(1000, 1000 + 7200) == '2h', 'two hours') +assert(weather.age_str(1000, 1000 + 86400 * 2) == '2d', 'days, once it gets that bad') + print('test_weather: all assertions passed') |
