-
Notifications
You must be signed in to change notification settings - Fork 0
/
libwx_test.go
136 lines (123 loc) · 3.61 KB
/
libwx_test.go
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package libwx
import (
"testing"
"github.com/stretchr/testify/require"
)
// TODO(cdzombak): testing for calculations in libwx.go
func Test_WetBulb_C(t *testing.T) {
r := require.New(t)
eq := CurriedFloat64Equal(Tolerance0)
cases := []struct {
t TempC
rh RelHumidity
expected TempC
}{
{TempC(-19), RelHumidity(80), TempC(-20)},
{TempC(-14), RelHumidity(90), TempC(-15)},
{TempC(-1), RelHumidity(30), TempC(-5)},
{TempC(-1), RelHumidity(40), TempC(-5)},
{TempC(-3.5), RelHumidity(90), TempC(-5)},
{TempC(5), RelHumidity(30), TempC(0)},
{TempC(1), RelHumidity(90), TempC(0)},
{TempC(6.5), RelHumidity(90), TempC(5)},
{TempC(10), RelHumidity(50), TempC(5)},
{TempC(19), RelHumidity(5), TempC(5)},
{TempC(10), RelHumidity(99), TempC(10)},
{TempC(25), RelHumidity(10), TempC(10)},
{TempC(15), RelHumidity(50), TempC(10)},
{TempC(20), RelHumidity(60), TempC(15)},
{TempC(20), RelHumidity(99), TempC(20)},
{TempC(40), RelHumidity(70), TempC(35)},
{TempC(40), RelHumidity(99), TempC(40)},
{TempC(50), RelHumidity(11), TempC(25)},
{TempC(44), RelHumidity(50), TempC(35)},
{TempC(46), RelHumidity(90), TempC(45)},
}
for _, c := range cases {
result, err := WetBulbC(c.t, c.rh)
msgAndArgs := []interface{}{
"given t %v + rh %v: expected %v, got %v",
c.t,
c.rh,
c.expected,
result,
}
r.NoError(err, msgAndArgs...)
r.True(eq(result.Unwrap(), c.expected.Unwrap()), msgAndArgs...)
}
}
func Test_HeatIndex_All(t *testing.T) {
r := require.New(t)
eq := CurriedFloat64Equal(0.5)
cases := []struct {
t TempF
rh RelHumidity
expected TempF
}{
{TempF(80), RelHumidity(40), TempF(80)},
{TempF(80), RelHumidity(60), TempF(82)},
{TempF(80), RelHumidity(80), TempF(84)},
{TempF(80), RelHumidity(100), TempF(87)},
{TempF(86), RelHumidity(40), TempF(85)},
{TempF(86), RelHumidity(60), TempF(91)},
{TempF(86), RelHumidity(80), TempF(100)},
{TempF(86), RelHumidity(100), TempF(112)},
{TempF(90), RelHumidity(40), TempF(91)},
{TempF(90), RelHumidity(60), TempF(100)},
{TempF(90), RelHumidity(80), TempF(113)},
{TempF(90), RelHumidity(100), TempF(132)},
{TempF(104), RelHumidity(40), TempF(119)},
{TempF(104), RelHumidity(45), TempF(124)},
{TempF(104), RelHumidity(50), TempF(131)},
{TempF(104), RelHumidity(55), TempF(137)},
}
for _, c := range cases {
resultF := HeatIndexF(c.t, c.rh)
msgAndArgsF := []interface{}{
"given t %v degF + rh %v: expected %v, got %v",
c.t,
c.rh,
c.expected,
resultF,
}
r.True(eq(resultF.Unwrap(), c.expected.Unwrap()), msgAndArgsF...)
resultC := HeatIndexC(c.t.C(), c.rh)
msgAndArgsC := []interface{}{
"given t %v degC + rh %v: expected %v, got %v",
c.t.C(),
c.rh,
c.expected.C(),
resultC,
}
r.True(eq(resultC.Unwrap(), c.expected.C().Unwrap()), msgAndArgsC...)
}
}
func Test_HeatIndexWarning_F(t *testing.T) {
r := require.New(t)
cases := []struct {
t TempF
expected HeatIndexWarning
}{
{TempF(-19), HeatIndexWarningNone},
{TempF(79), HeatIndexWarningNone},
{TempF(80), HeatIndexWarningCaution},
{TempF(87), HeatIndexWarningCaution},
{TempF(90), HeatIndexWarningCaution},
{TempF(91), HeatIndexWarningExtremeCaution},
{TempF(103), HeatIndexWarningExtremeCaution},
{TempF(104), HeatIndexWarningDanger},
{TempF(124), HeatIndexWarningDanger},
{TempF(126), HeatIndexWarningExtremeDanger},
{TempF(135), HeatIndexWarningExtremeDanger},
}
for _, c := range cases {
result := HeatIndexWarningF(c.t)
msgAndArgs := []interface{}{
"given t %v degF: expected %v, got %v",
c.t,
c.expected,
result,
}
r.Equal(c.expected, result, msgAndArgs...)
}
}