forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hev_test.go
85 lines (83 loc) · 2.02 KB
/
hev_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
package nmea_test
import (
. "github.com/munnik/go-nmea"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
)
var _ = Describe("HEV", func() {
var (
sentence Sentence
parsed HEV
err error
raw string
)
Describe("Parsing", func() {
JustBeforeEach(func() {
sentence, err = Parse(raw)
if sentence != nil {
parsed = sentence.(HEV)
} else {
parsed = HEV{}
}
})
Context("a valid sentence", func() {
BeforeEach(func() {
raw = "$GPHEV,-0.07*54"
})
It("returns no errors", func() {
Expect(err).NotTo(HaveOccurred())
})
It("equals a valid HEV struct", func() {
Expect(parsed).To(MatchFields(IgnoreExtras, Fields{
"Heave": Equal(NewFloat64(-0.07)),
}))
})
})
Context("a sentence with an invalid heave", func() {
BeforeEach(func() {
raw = "$GPHEV,-B.07*26"
})
It("returns no errors", func() {
Expect(err).NotTo(HaveOccurred())
})
It("equals a valid HEV struct", func() {
Expect(parsed).To(MatchFields(IgnoreExtras, Fields{
"Heave": Equal(NewInvalidFloat64("strconv.ParseFloat: parsing \"-B.07\": invalid syntax")),
}))
})
})
Context("a sentence with a bad checksum", func() {
BeforeEach(func() {
raw = "$GPHEV,-0.07*00"
})
It("returns an error", func() {
Expect(err).To(MatchError("nmea: sentence checksum mismatch [54 != 00]"))
})
It("returns nil", func() {
Expect(sentence).To(BeNil())
})
})
})
Describe("Getting data from a HEV struct", func() {
BeforeEach(func() {
parsed = HEV{
Heave: NewFloat64(HeaveMeters),
}
})
Context("when having a complete struct", func() {
It("returns a valid heave", func() {
Expect(parsed.GetHeave()).To(BeNumerically("~", HeaveMeters, 0.00001))
})
})
Context("when having a struct with missing heave", func() {
JustBeforeEach(func() {
parsed.Heave = NewInvalidFloat64("")
})
It("returns an error", func() {
_, err := parsed.GetHeave()
Expect(err).To(HaveOccurred())
})
})
})
})