summaryrefslogtreecommitdiff
path: root/internal/render/scale_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/render/scale_test.go')
-rw-r--r--internal/render/scale_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/internal/render/scale_test.go b/internal/render/scale_test.go
new file mode 100644
index 0000000..9754bdc
--- /dev/null
+++ b/internal/render/scale_test.go
@@ -0,0 +1,57 @@
+package render
+
+import (
+ "testing"
+
+ "github.com/lukaszkasprzak/prognosis/internal/config"
+)
+
+// IMGW's criteria are in Celsius. Switching the display to Fahrenheit must not
+// move the temperature at which the met office is said to warn.
+func TestThresholdsAreComparedInCelsiusWhateverTheDisplayUnits(t *testing.T) {
+ metric := ctx{cfg: config.Config{Units: "metric"}}
+ imperial := ctx{cfg: config.Config{Units: "imperial"}}
+
+ cases := []struct {
+ celsius float64
+ fahrenheit float64
+ want string
+ why string
+ }{
+ {29, 84.2, Yellow, "below the upal threshold"},
+ {30, 86, Red, "upal stopien 1 is Tmax >= 30C"},
+ {36, 96.8, BrightRed, "the higher heat level is Tmax > 35C"},
+ {-15, 5, BrightBlue, "silny mroz stopien 1 is Tmin <= -15C"},
+ {-14, 6.8, Blue, "just above the frost threshold"},
+ }
+ for _, c := range cases {
+ if got := TempStyle(metric.celsius(c.celsius)); got != c.want {
+ t.Errorf("%.0fC -> %s, want %s (%s)", c.celsius, got, c.want, c.why)
+ }
+ if got := TempStyle(imperial.celsius(c.fahrenheit)); got != c.want {
+ t.Errorf("%.1fF (=%.0fC) -> %s, want %s (%s)",
+ c.fahrenheit, c.celsius, got, c.want, c.why)
+ }
+ }
+}
+
+func TestPollenBandEdges(t *testing.T) {
+ cases := []struct {
+ species string
+ value float64
+ want string
+ }{
+ {"grass", 0.5, "none"}, {"grass", 19, "low"}, {"grass", 20, "medium"},
+ {"grass", 49, "medium"}, {"grass", 50, "high"}, {"grass", 64, "high"},
+ {"grass", 65, "very high"}, {"grass", 200, "very high"},
+ {"birch", 79, "low"}, {"birch", 80, "high"},
+ {"mugwort", 69, "low"}, {"mugwort", 70, "high"},
+ {"ragweed", 50, ""}, // no Polish threshold sourced: deliberately unbanded
+ {"alder", 500, ""},
+ }
+ for _, c := range cases {
+ if got := PollenBand(c.species, c.value); got != c.want {
+ t.Errorf("PollenBand(%q, %v) = %q, want %q", c.species, c.value, got, c.want)
+ }
+ }
+}