summaryrefslogtreecommitdiff
path: root/internal/render/scale_test.go
blob: 9754bdce1605424237459c06ded4cce86d859999 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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)
		}
	}
}