-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote_test.go
More file actions
108 lines (102 loc) · 4.05 KB
/
note_test.go
File metadata and controls
108 lines (102 loc) · 4.05 KB
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
package catTrackslib
import (
"encoding/json"
"testing"
"time"
)
func TestNotesField_AsNoteStructured(t *testing.T) {
type field struct {
Note string
}
wantTime, _ := time.Parse(time.RFC3339, "2023-12-16T15:25:40.335Z")
pointOfF := func(f float64) *float64 {
return &f
}
pointOfI := func(f int) *int {
return &f
}
tests := []struct {
name string
fields field
want *NoteStructured
}{
{
name: "test 1",
fields: field{
Note: "{\"floorsAscended\":56,\"customNote\":\"\",\"heartRateS\":\"\",\"currentTripStart\":\"2023-12-16T15:25:40.335Z\",\"floorsDescended\":40,\"averageActivePace\":0.53959662255944008,\"networkInfo\":\"{}\",\"numberOfSteps\":65066,\"visit\":\"{\\\"validVisit\\\":false}\",\"relativeAltitude\":-16.205322265625,\"currentCadence\":1.851201057434082,\"heartRateRawS\":\"\",\"batteryStatus\":\"{\\\"level\\\":0.94999998807907104,\\\"status\\\":\\\"unplugged\\\"}\",\"activity\":\"Stationary\",\"currentPace\":0.69526106119155884,\"imgb64\":\"\",\"pressure\":97.975234985351562,\"distance\":69266.793879101984,\"user_accelerometer_x\":0.14,\"activity_confidence\":100}",
},
want: &NoteStructured{
Activity: "Stationary",
ActivityConfidence: pointOfI(100),
FloorsAscended: 56,
FloorsDescended: 40,
NumberOfSteps: 65066,
CurrentCadence: 1.851201057434082,
CurrentPace: 0.69526106119155884,
AverageActivePace: 0.53959662255944008,
Pressure: 97.975234985351562,
Distance: 69266.793879101984,
CurrentTripStart: wantTime,
NetworkInfo: "{}",
HeartRateS: "",
HeartRateRawS: "",
BatteryStatus: `{\"level\":0.94999998807907104,\"status\":\"unplugged\"}`,
Visit: `{\"validVisit\":false}`,
CustomNote: "",
UserAccelerometer: UserAccelerometer{X: pointOfF(0.14)},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
bf := []byte(tt.fields.Note)
nv := NotesField(bf)
n := &nv
if got, err := n.AsNoteStructured(); err == nil {
if got.FloorsAscended != tt.want.FloorsAscended {
t.Errorf("AsNoteStructured() = %v, want %v", got.FloorsAscended, tt.want.FloorsAscended)
}
if got.FloorsDescended != tt.want.FloorsDescended {
t.Errorf("AsNoteStructured() = %v, want %v", got.FloorsDescended, tt.want.FloorsDescended)
}
if got.NumberOfSteps != tt.want.NumberOfSteps {
t.Errorf("AsNoteStructured() = %v, want %v", got.NumberOfSteps, tt.want.NumberOfSteps)
}
if got.CurrentCadence != tt.want.CurrentCadence {
t.Errorf("AsNoteStructured() = %v, want %v", got.CurrentCadence, tt.want.CurrentCadence)
}
if got.CurrentPace != tt.want.CurrentPace {
t.Errorf("AsNoteStructured() = %v, want %v", got.CurrentPace, tt.want.CurrentPace)
}
if got.AverageActivePace != tt.want.AverageActivePace {
t.Errorf("AsNoteStructured() = %v, want %v", got.AverageActivePace, tt.want.AverageActivePace)
}
if got.Pressure != tt.want.Pressure {
t.Errorf("AsNoteStructured() = %v, want %v", got.Pressure, tt.want.Pressure)
}
if got.Distance != tt.want.Distance {
t.Errorf("AsNoteStructured() = %v, want %v", got.Distance, tt.want.Distance)
}
if got.CurrentTripStart != tt.want.CurrentTripStart {
t.Errorf("AsNoteStructured() = %v, want %v", got.CurrentTripStart, tt.want.CurrentTripStart)
}
if got.Activity != tt.want.Activity {
t.Errorf("AsNoteStructured() = %v, want %v", got.Activity, tt.want.Activity)
}
if *got.ActivityConfidence != *tt.want.ActivityConfidence {
t.Errorf("AsNoteStructured() = %v, want %v", got.ActivityConfidence, tt.want.ActivityConfidence)
}
if *got.UserAccelerometer.X != *tt.want.UserAccelerometer.X {
t.Errorf("AsNoteStructured() = %v, want %v", got.UserAccelerometer.X, tt.want.UserAccelerometer.X)
}
show, err := json.MarshalIndent(got, "", " ")
if err != nil {
t.Errorf("AsNoteStructured() = %v, want %v", err, nil)
}
t.Logf("AsNoteStructured() = %v", string(show))
} else {
t.Fatal(err)
}
})
}
}