-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctionx_test.go
97 lines (95 loc) · 1.74 KB
/
functionx_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
package lynx
import "testing"
func TestFunction_FormatValue(t *testing.T) {
type fields struct {
ID int64
Type string
InstallationID int64
Meta Meta
ProtectedMeta Meta
Created int64
Updated int64
}
type args struct {
value float64
topicKey string
}
tests := []struct {
name string
fields fields
args args
want string
}{
{
name: "FormatMeta",
fields: fields{
Meta: map[string]string{
"format": "%.1f°C",
},
},
args: args{
value: 21.22222,
topicKey: "",
},
want: "21.2°C",
},
{
name: "UnitMeta",
fields: fields{
Meta: map[string]string{
"unit": "°C",
},
},
args: args{
value: 21.222,
topicKey: "",
},
want: "21.222000°C",
},
{
name: "StateOn",
fields: fields{
Meta: map[string]string{
"state_on": "1",
"state_off": "0",
},
},
args: args{
value: 1,
topicKey: "",
},
want: "on",
},
{
name: "StateOff",
fields: fields{
Meta: map[string]string{
"state_on": "1",
"state_off": "0",
"text_off": "turned off",
},
},
args: args{
value: 0,
topicKey: "",
},
want: "turned off",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := &Function{
ID: tt.fields.ID,
Type: tt.fields.Type,
InstallationID: tt.fields.InstallationID,
Meta: tt.fields.Meta,
ProtectedMeta: tt.fields.ProtectedMeta,
Created: tt.fields.Created,
Updated: tt.fields.Updated,
}
if got := f.FormatValue(tt.args.value, tt.args.topicKey); got != tt.want {
t.Errorf("FormatValue() = %v, want %v", got, tt.want)
}
})
}
}