-
Notifications
You must be signed in to change notification settings - Fork 2
/
performance_test.go
115 lines (87 loc) · 2.07 KB
/
performance_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package traindown
import (
"encoding/json"
"math/rand"
"testing"
)
func TestNewPerformance(t *testing.T) {
p := NewPerformance()
if p.Metadata == nil ||
p.Notes == nil ||
p.Reps != 1 ||
p.Sets != 1 ||
p.Unit != "unknown unit" {
t.Fatal("Failed to initialize Performance")
}
}
func TestStringifyPerformance(t *testing.T) {
p := NewPerformance()
expect, _ := json.Marshal(p)
if p.String() != string(expect) {
t.Fatal("Failed to stringify Performance")
}
}
func TestVolume(t *testing.T) {
fails := rand.Intn(100)
load := rand.Float32() * 1000
reps := rand.Intn(100)
sets := rand.Intn(100)
unit := "your mom"
p := Performance{
Fails: fails,
Load: load,
Reps: reps,
Sets: sets,
Unit: unit}
expected := (float32(reps) - float32(fails)) * float32(sets) * load
v, u := p.Volume()
if v != expected {
t.Errorf("Unexpected volume: %v", v)
}
if u != unit {
t.Errorf("Unexpected unit: %q", u)
}
}
func TestAssignSpecialToPerformance(t *testing.T) {
p := NewPerformance()
assigned := p.assignSpecial("your", "mom")
if assigned == true {
t.Errorf("Invalid assignment of special operator")
}
keys := []string{"u", "U", "unit", "Unit"}
for _, k := range keys {
assigned = p.assignSpecial(k, "your mom")
if assigned != true || p.Unit != "your mom" {
t.Errorf("Failed to assign special operator")
}
}
}
func TestMaybeInheritUnit(t *testing.T) {
du := "your mom"
m := &Movement{DefaultUnit: ""}
s := &Session{DefaultUnit: du}
p := NewPerformance()
p1 := Performance{}
p.maybeInheritUnit(s, m)
p1.maybeInheritUnit(s, m)
if p.Unit != du || p1.Unit != du {
t.Errorf("Failed to inherit from Session")
}
p = NewPerformance()
p1 = Performance{}
m.DefaultUnit = du
s.DefaultUnit = ""
p.maybeInheritUnit(s, m)
p1.maybeInheritUnit(s, m)
if p.Unit != du || p1.Unit != du {
t.Errorf("Failed to inherit from Movement")
}
p.Unit = "not your mom"
p1.Unit = "not your mom"
s.DefaultUnit = du
p.maybeInheritUnit(s, m)
p1.maybeInheritUnit(s, m)
if p.Unit == du || p1.Unit == du {
t.Errorf("Incorrectly overwrote a set unit")
}
}