1
+
Added:
(** Unit tests for {!Stimulus}. *)
2
+
Added:
3
+
Added:
let ok = function Ok v -> v | Error _ -> Alcotest.fail "expected Ok"
4
+
Added:
5
+
Added:
let get id =
6
+
Added:
match Exercise.find id with
7
+
Added:
| Some e -> e
8
+
Added:
| None -> Alcotest.failf "catalog is missing %S" id
9
+
Added:
10
+
Added:
let kg n = ok (Units.Weight.of_kg n)
11
+
Added:
let reps n = ok (Units.Reps.of_int n)
12
+
Added:
13
+
Added:
let move ?(outcome = Stimulus.Positive_failure) id load r =
14
+
Added:
Stimulus.Movement.make ~exercise:(get id) ~load:(kg load) ~reps:(reps r)
15
+
Added:
~outcome
16
+
Added:
17
+
Added:
let outcome_tests =
18
+
Added:
[
19
+
Added:
( "positive failure used no extension",
20
+
Added:
`Quick,
21
+
Added:
fun () ->
22
+
Added:
Alcotest.(check (list string))
23
+
Added:
"none" []
24
+
Added:
(List.map
25
+
Added:
(Format.asprintf "%a" Stimulus.pp_extension)
26
+
Added:
(Stimulus.extensions_of_outcome Stimulus.Positive_failure)) );
27
+
Added:
( "extensions stack in the order applied",
28
+
Added:
`Quick,
29
+
Added:
fun () ->
30
+
Added:
let o =
31
+
Added:
Stimulus.Beyond_failure (Stimulus.Forced_reps, [ Stimulus.Negatives ])
32
+
Added:
in
33
+
Added:
Alcotest.(check (list string))
34
+
Added:
"forced reps then negatives"
35
+
Added:
[ "forced reps"; "negatives" ]
36
+
Added:
(List.map
37
+
Added:
(Format.asprintf "%a" Stimulus.pp_extension)
38
+
Added:
(Stimulus.extensions_of_outcome o)) );
39
+
Added:
]
40
+
Added:
41
+
Added:
let delivery_tests =
42
+
Added:
[
43
+
Added:
( "a single movement is one stimulus",
44
+
Added:
`Quick,
45
+
Added:
fun () ->
46
+
Added:
let s = ok (Stimulus.make (Stimulus.Single (move "curls" 40. 8))) in
47
+
Added:
Alcotest.(check int)
48
+
Added:
"one movement" 1
49
+
Added:
(List.length (Stimulus.movements s));
50
+
Added:
Alcotest.(check bool) "not extended" false (Stimulus.is_extended s) );
51
+
Added:
( "a pre-exhaust pair is one stimulus, isolation first",
52
+
Added:
`Quick,
53
+
Added:
fun () ->
54
+
Added:
let s =
55
+
Added:
ok
56
+
Added:
(Stimulus.make
57
+
Added:
(Stimulus.Pre_exhaust
58
+
Added:
{
59
+
Added:
isolation = move "dumbbell-flyes" 20. 9;
60
+
Added:
compound = move "incline-press" 60. 7;
61
+
Added:
}))
62
+
Added:
in
63
+
Added:
Alcotest.(check int)
64
+
Added:
"two movements" 2
65
+
Added:
(List.length (Stimulus.movements s));
66
+
Added:
Alcotest.(check (list string))
67
+
Added:
"isolation leads"
68
+
Added:
[ "Dumbbell Flyes"; "Incline Presses" ]
69
+
Added:
(List.map Exercise.name (Stimulus.exercises s)) );
70
+
Added:
( "a mislabelled pairing is refused",
71
+
Added:
`Quick,
72
+
Added:
fun () ->
73
+
Added:
match
74
+
Added:
Stimulus.make
75
+
Added:
(Stimulus.Pre_exhaust
76
+
Added:
{
77
+
Added:
isolation = move "dumbbell-flyes" 20. 9;
78
+
Added:
compound = move "squats" 100. 8;
79
+
Added:
})
80
+
Added:
with
81
+
Added:
| Error (Stimulus.Not_a_pre_exhaust { isolation; compound }) ->
82
+
Added:
Alcotest.(check string)
83
+
Added:
"isolation" "dumbbell-flyes"
84
+
Added:
(isolation :> string);
85
+
Added:
Alcotest.(check string) "compound" "squats" (compound :> string)
86
+
Added:
| Ok _ -> Alcotest.fail "expected Not_a_pre_exhaust" );
87
+
Added:
( "extensions are gathered across a pre-exhaust's movements",
88
+
Added:
`Quick,
89
+
Added:
fun () ->
90
+
Added:
let s =
91
+
Added:
ok
92
+
Added:
(Stimulus.make
93
+
Added:
(Stimulus.Pre_exhaust
94
+
Added:
{
95
+
Added:
isolation = move "lying-french-press" 30. 9;
96
+
Added:
compound =
97
+
Added:
move
98
+
Added:
~outcome:
99
+
Added:
(Stimulus.Beyond_failure
100
+
Added:
(Stimulus.Forced_reps, [ Stimulus.Negatives ]))
101
+
Added:
"dips" 0. 6;
102
+
Added:
}))
103
+
Added:
in
104
+
Added:
Alcotest.(check bool) "extended" true (Stimulus.is_extended s);
105
+
Added:
Alcotest.(check int)
106
+
Added:
"two extensions" 2
107
+
Added:
(List.length (Stimulus.extensions s)) );
108
+
Added:
]
109
+
Added:
110
+
Added:
let warm_up_tests =
111
+
Added:
[
112
+
Added:
( "warm-ups sit alongside the stimulus, not inside it",
113
+
Added:
`Quick,
114
+
Added:
fun () ->
115
+
Added:
let w =
116
+
Added:
Stimulus.Warm_up.make ~exercise:(get "squats") ~load:(kg 40.)
117
+
Added:
~reps:(reps 10)
118
+
Added:
in
119
+
Added:
let s =
120
+
Added:
ok
121
+
Added:
(Stimulus.make ~warm_ups:[ w ]
122
+
Added:
(Stimulus.Single (move "squats" 100. 8)))
123
+
Added:
in
124
+
Added:
Alcotest.(check int) "one warm-up" 1 (List.length (Stimulus.warm_ups s));
125
+
Added:
Alcotest.(check int)
126
+
Added:
"still one drive to failure" 1
127
+
Added:
(List.length (Stimulus.movements s)) );
128
+
Added:
( "a stimulus needs no warm-up",
129
+
Added:
`Quick,
130
+
Added:
fun () ->
131
+
Added:
let s = ok (Stimulus.make (Stimulus.Single (move "sit-ups" 0. 12))) in
132
+
Added:
Alcotest.(check int) "none" 0 (List.length (Stimulus.warm_ups s)) );
133
+
Added:
]
134
+
Added:
135
+
Added:
let suite =
136
+
Added:
[
137
+
Added:
("stimulus.outcome", outcome_tests);
138
+
Added:
("stimulus.delivery", delivery_tests);
139
+
Added:
("stimulus.warm_up", warm_up_tests);
140
+
Added:
]