-
Notifications
You must be signed in to change notification settings - Fork 3
/
trend_test.go
101 lines (87 loc) · 3.62 KB
/
trend_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
package metar
import (
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
"github.com/urkk/metar/clouds"
"github.com/urkk/metar/phenomena"
)
func TestParseTrendData(t *testing.T) {
Convey("Trends parsing tests", t, func() {
var input []string
var expected *Trend
Convey(`test incorrect time, horizontal visibility and phenomena`, func() {
input = []string{"BECMG", "2526/2526", "0500", "FG"}
expected = &Trend{Type: BECMG,
Visibility: getVis([]string{"0500"}),
Phenomena: []phenomena.Phenomenon{phenomena.Phenomenon{Vicinity: false, Abbreviation: "FG", Intensity: ""}},
}
So(parseTrendData(input), ShouldResemble, expected)
})
Convey(`test misspelled time and cloud layer`, func() {
input = []string{"BECMG", "AT220O", "TL23O0", "BKN015//"}
expected = &Trend{Type: BECMG,
Clouds: []clouds.Cloud{getCloud("BKN015//")},
}
So(parseTrendData(input), ShouldResemble, expected)
})
Convey(`test for FM time and CAVOK condition`, func() {
input = []string{"FM241200", "18003MPS", "CAVOK"}
expected = &Trend{Type: FM,
FM: time.Date(curYear, curMonth, 24, 12, 0, 0, 0, time.UTC),
Wind: getWind("18003MPS"),
CAVOK: true,
}
So(parseTrendData(input), ShouldResemble, expected)
})
Convey(`test for vertical visibility and phenomena`, func() {
input = []string{"TEMPO", "2509/2515", "0500", "FG", "VV003"}
expected = &Trend{Type: TEMPO,
FM: time.Date(curYear, curMonth, 25, 9, 0, 0, 0, time.UTC),
TL: time.Date(curYear, curMonth, 25, 15, 0, 0, 0, time.UTC),
Visibility: getVis([]string{"0500"}),
Phenomena: []phenomena.Phenomenon{phenomena.Phenomenon{Vicinity: false, Abbreviation: "FG", Intensity: ""}},
VerticalVisibility: 300,
}
So(parseTrendData(input), ShouldResemble, expected)
})
Convey(`test for phenomena and multiple cloud layers`, func() {
input = []string{"TEMPO", "2506/2512", "3100", "-SHRA", "BR", "BKN005", "OVC020CB"}
expected = &Trend{Type: TEMPO,
FM: time.Date(curYear, curMonth, 25, 6, 0, 0, 0, time.UTC),
TL: time.Date(curYear, curMonth, 25, 12, 0, 0, 0, time.UTC),
Visibility: getVis([]string{"3100"}),
Phenomena: []phenomena.Phenomenon{phenomena.Phenomenon{Vicinity: false, Abbreviation: "SHRA", Intensity: "-"}, phenomena.Phenomenon{Vicinity: false, Abbreviation: "BR", Intensity: ""}},
Clouds: []clouds.Cloud{getCloud("BKN005"), getCloud("OVC020CB")},
}
So(parseTrendData(input), ShouldResemble, expected)
})
Convey(`test for wind and expected time of changes`, func() {
input = []string{"TEMPO", "FM1230", "TL1330", "18005MPS", "CAVOK"}
expected = &Trend{Type: TEMPO,
Wind: getWind("18005MPS"),
CAVOK: true,
FM: time.Date(curYear, curMonth, curDay, 12, 30, 0, 0, time.UTC),
TL: time.Date(curYear, curMonth, curDay, 13, 30, 0, 0, time.UTC),
}
So(parseTrendData(input), ShouldResemble, expected)
})
Convey(`test incorrect FM time and 24 hours at TL-time `, func() {
input = []string{"BECMG", "FM22o0", "TL2400", "BKN015//"}
expected = &Trend{Type: BECMG,
TL: time.Date(curYear, curMonth, curDay+1, 00, 0, 0, 0, time.UTC),
Clouds: []clouds.Cloud{getCloud("BKN015//")},
}
So(parseTrendData(input), ShouldResemble, expected)
})
Convey(`test AT-time`, func() {
input = []string{"TEMPO", "AT1230", "18005MPS", "BKN003"}
expected = &Trend{Type: TEMPO,
Wind: getWind("18005MPS"),
AT: time.Date(curYear, curMonth, curDay, 12, 30, 0, 0, time.UTC),
Clouds: []clouds.Cloud{getCloud("BKN003")},
}
So(parseTrendData(input), ShouldResemble, expected)
})
})
}