aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_weather.lua
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-17 08:57:27 +0200
committerDanilo M. <danix@danix.xyz>2026-09-17 08:57:27 +0200
commit2b499067d07328e775547059212bf3737cfcfdd4 (patch)
tree4971a888f526373d2014a34a835f140a3ab4da60 /test/test_weather.lua
parent17692349e6b6ce3f6083b5d565dda9f3ca7dba22 (diff)
downloadconky-theme-udt-2b499067d07328e775547059212bf3737cfcfdd4.tar.gz
conky-theme-udt-2b499067d07328e775547059212bf3737cfcfdd4.zip
feat: add sun position along the daylight arc
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'test/test_weather.lua')
-rw-r--r--test/test_weather.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/test_weather.lua b/test/test_weather.lua
index e18aa15..1d35748 100644
--- a/test/test_weather.lua
+++ b/test/test_weather.lua
@@ -127,4 +127,30 @@ assert(weather.arrow(0) == '\u{2193}', 'a north wind blows southward')
assert(weather.arrow(180) == '\u{2191}', 'a south wind blows northward')
assert(weather.arrow(nil) == '', 'no direction draws nothing')
+-- === Sun position =========================================================
+-- t is the fraction of daylight elapsed, and the widget uses it to place the
+-- dot along the arc. Sunrise 1000, sunset 2000, so midday is 1500.
+assert(weather.sun_t(1000, 1000, 2000) == 0, 'at sunrise t is 0')
+assert(weather.sun_t(1500, 1000, 2000) == 0.5, 'at midday t is half')
+assert(weather.sun_t(2000, 1000, 2000) == 1, 'at sunset t is 1')
+
+-- OWM reports today's sunrise and sunset, so between midnight and sunrise the
+-- numerator is negative. The clamp is the whole handling; without it the dot
+-- would be drawn off the left end of the arc.
+assert(weather.sun_t(500, 1000, 2000) == 0, 'before dawn clamps to 0')
+assert(weather.sun_t(9999, 1000, 2000) == 1, 'after dusk clamps to 1')
+
+-- Degenerate input must not divide by zero.
+assert(weather.sun_t(1500, 2000, 2000) == 0, 'zero-length day gives 0, not nan')
+assert(weather.sun_t(nil, 1000, 2000) == nil, 'missing now gives nil')
+assert(weather.sun_t(1500, nil, 2000) == nil, 'missing sunrise gives nil')
+
+-- is_day drives both the icon face and the dot's colour: a dot parked at the
+-- end of the arc must not read as a sun that is still up.
+assert(weather.is_day(1500, 1000, 2000) == true, 'midday is day')
+assert(weather.is_day(1000, 1000, 2000) == true, 'sunrise counts as day')
+assert(weather.is_day(2000, 1000, 2000) == true, 'sunset counts as day')
+assert(weather.is_day(500, 1000, 2000) == false, 'before dawn is night')
+assert(weather.is_day(2500, 1000, 2000) == false, 'after dusk is night')
+
print('test_weather: all assertions passed')