-
Notifications
You must be signed in to change notification settings - Fork 1
/
tilt_test.go
72 lines (65 loc) · 1.64 KB
/
tilt_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
package tilt_test
import (
"errors"
"testing"
"github.com/alexhowarth/go-tilt"
)
func TestNewTilt(t *testing.T) {
tt := []struct {
name string
ibeacon *tilt.IBeacon
colour tilt.Colour
celsius float64
fahrenheit uint16
gravity float64
err error
}{
{
name: "Red iBeacon",
ibeacon: &tilt.IBeacon{UUID: "a495bb10c5b14b44b5121370f02d74de", Major: 70, Minor: 1035},
colour: tilt.Colour("Red"),
fahrenheit: 70,
celsius: 21.11,
gravity: 1.035,
err: nil,
},
{
name: "Black iBeacon",
ibeacon: &tilt.IBeacon{UUID: "a495bb30c5b14b44b5121370f02d74de", Major: 69, Minor: 1065},
colour: tilt.Colour("Black"),
fahrenheit: 69,
celsius: 20.56,
gravity: 1.065,
err: nil,
},
{
name: "Not an iBeacon",
ibeacon: &tilt.IBeacon{UUID: "a495bb99c5b14b44b5121370f02d74de", Major: 1, Minor: 2},
err: tilt.ErrNotTilt,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
got, err := tilt.NewTilt(tc.ibeacon)
if tc.err != nil {
// expecting an error
if !errors.Is(err, tc.err) {
t.Fatalf("Expected '%v' error, got '%v' error", tc.err, err)
}
return
}
if got.Colour() != tc.colour {
t.Errorf("Expected %v, got %v", tc.colour, got.Colour())
}
if got.Celsius() != tc.celsius {
t.Errorf("Expected %v, got %v", tc.celsius, got.Celsius())
}
if got.Fahrenheit() != tc.fahrenheit {
t.Errorf("Expected %v, got %v", tc.fahrenheit, got.Fahrenheit())
}
if got.Gravity() != tc.gravity {
t.Errorf("Expected %v, got %v", tc.gravity, got.Gravity())
}
})
}
}