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
137
138
139
140
141
142
143
144
|
// Copyright © 2022 siddharth ravikumar <s@ricketyspace.net>
// SPDX-License-Identifier: ISC
package nws
import "testing"
func TestPoints(t *testing.T) {
// Test valid lat,lng.
np, err := Points(41.115, -83.177)
if err != nil {
t.Errorf("points: %v", err)
return
}
if np.Properties.Forecast != "https://api.weather.gov/gridpoints/CLE/33,42/forecast" {
t.Errorf("points: forcecast link: '%v'", np.Properties.Forecast)
}
if np.Properties.ForecastHourly != "https://api.weather.gov/gridpoints/CLE/33,42/forecast/hourly" {
t.Errorf("points: forcecast link: '%v'", np.Properties.ForecastHourly)
}
if np.Properties.GridId != "CLE" {
t.Errorf("points: gridid: %v", np.Properties.GridId)
}
if np.Properties.GridX != 33 {
t.Errorf("points: gridx: %v", np.Properties.GridX)
}
if np.Properties.GridY != 42 {
t.Errorf("points: gridy: %v", np.Properties.GridY)
}
if np.Properties.RelativeLocation.Properties.City != "Tiffin" {
t.Errorf("points: location: city: %v", np.Properties)
}
if np.Properties.RelativeLocation.Properties.State != "OH" {
t.Errorf("points: location: state: %v", np.Properties)
}
// Test invalid lat,lng
np, err = Points(115.0, -83.177)
if err == nil {
t.Errorf("points: %v", np)
}
}
func TestForecast(t *testing.T) {
// Get point.
np, err := Points(41.115, -83.177)
if err != nil {
t.Errorf("error: %v", err)
return
}
// Get forecast.
fc, err := Forecast(np)
if err != nil {
t.Errorf("error: %v", err)
return
}
// Verify periods.
for i, period := range fc.Properties.Periods {
if period.Number < 1 {
t.Errorf("period: %d: number invalid: %v", i, period.Number)
}
if len(period.Name) < 1 {
t.Errorf("period: %d: name invalid: %v", i, period.Name)
}
if len(period.StartTime) < 1 {
t.Errorf("period: %d: start time invalid: %v", i,
period.StartTime)
}
if len(period.EndTime) < 1 {
t.Errorf("period: %d: end time invalid: %v", i,
period.EndTime)
}
if len(period.TemperatureUnit) < 1 {
t.Errorf("period: %d: temperature unit invalid: %v",
i, period.TemperatureUnit)
}
if len(period.WindSpeed) < 1 {
t.Errorf("period: %d: wind speed invalid: %v",
i, period.WindSpeed)
}
if len(period.WindDirection) < 1 {
t.Errorf("period: %d: wind direction invalid: %v",
i, period.WindDirection)
}
if len(period.ShortForecast) < 1 {
t.Errorf("period: %d: short forecast invalid: %v",
i, period.ShortForecast)
}
if len(period.DetailedForecast) < 1 {
t.Errorf("period: %d: detailed forecast invalid: %v",
i, period.DetailedForecast)
}
}
}
func TestForecastHourly(t *testing.T) {
// Get point.
np, err := Points(41.115, -83.177)
if err != nil {
t.Errorf("error: %v", err)
return
}
// Get forecast hourly.
fc, err := ForecastHourly(np)
if err != nil {
t.Errorf("error: %v", err)
return
}
// Verify periods.
for i, period := range fc.Properties.Periods {
if period.Number < 1 {
t.Errorf("period: %d: number invalid: %v", i, period.Number)
}
if len(period.StartTime) < 1 {
t.Errorf("period: %d: start time invalid: %v", i,
period.StartTime)
}
if len(period.EndTime) < 1 {
t.Errorf("period: %d: end time invalid: %v", i,
period.EndTime)
}
if len(period.TemperatureUnit) < 1 {
t.Errorf("period: %d: temperature unit invalid: %v",
i, period.TemperatureUnit)
}
if len(period.WindSpeed) < 1 {
t.Errorf("period: %d: wind speed invalid: %v",
i, period.WindSpeed)
}
if len(period.WindDirection) < 1 {
t.Errorf("period: %d: wind direction invalid: %v",
i, period.WindDirection)
}
if len(period.ShortForecast) < 1 {
t.Errorf("period: %d: short forecast invalid: %v",
i, period.ShortForecast)
}
}
}
|