|
1 | | -import { describe, expect, test, xtest } from "@jest/globals"; |
2 | | -import { SplitSecondStopwatch } from "./split-second-stopwatch"; |
| 1 | +import { describe, expect, test, xtest } from '@jest/globals'; |
| 2 | +import { SplitSecondStopwatch } from './split-second-stopwatch'; |
3 | 3 |
|
4 | | -describe("SplitSecondStopwatch", () => { |
5 | | - test("new stopwatch starts in ready state", () => { |
| 4 | +describe('SplitSecondStopwatch', () => { |
| 5 | + test('new stopwatch starts in ready state', () => { |
6 | 6 | const stopwatch = new SplitSecondStopwatch(); |
7 | | - expect(stopwatch.state).toBe("ready"); |
| 7 | + expect(stopwatch.state).toBe('ready'); |
8 | 8 | }); |
9 | 9 |
|
10 | 10 | xtest("new stopwatch's current lap has no elapsed time", () => { |
11 | 11 | const stopwatch = new SplitSecondStopwatch(); |
12 | | - expect(stopwatch.currentLap).toBe("00:00:00"); |
| 12 | + expect(stopwatch.currentLap).toBe('00:00:00'); |
13 | 13 | }); |
14 | 14 |
|
15 | 15 | xtest("new stopwatch's total has no elapsed time", () => { |
16 | 16 | const stopwatch = new SplitSecondStopwatch(); |
17 | | - expect(stopwatch.total).toBe("00:00:00"); |
| 17 | + expect(stopwatch.total).toBe('00:00:00'); |
18 | 18 | }); |
19 | 19 |
|
20 | | - xtest("new stopwatch does not have previous laps", () => { |
| 20 | + xtest('new stopwatch does not have previous laps', () => { |
21 | 21 | const stopwatch = new SplitSecondStopwatch(); |
22 | 22 | expect(stopwatch.previousLaps).toEqual([]); |
23 | 23 | }); |
24 | 24 |
|
25 | | - xtest("start from ready state changes state to running", () => { |
| 25 | + xtest('start from ready state changes state to running', () => { |
26 | 26 | const stopwatch = new SplitSecondStopwatch(); |
27 | 27 | stopwatch.start(); |
28 | | - expect(stopwatch.state).toBe("running"); |
| 28 | + expect(stopwatch.state).toBe('running'); |
29 | 29 | }); |
30 | 30 |
|
31 | | - xtest("start does not change previous laps", () => { |
| 31 | + xtest('start does not change previous laps', () => { |
32 | 32 | const stopwatch = new SplitSecondStopwatch(); |
33 | 33 | stopwatch.start(); |
34 | 34 | expect(stopwatch.previousLaps).toEqual([]); |
35 | 35 | }); |
36 | 36 |
|
37 | | - xtest("start initiates time tracking for current lap", () => { |
| 37 | + xtest('start initiates time tracking for current lap', () => { |
38 | 38 | const stopwatch = new SplitSecondStopwatch(); |
39 | 39 | stopwatch.start(); |
40 | | - stopwatch.advanceTime("00:00:05"); |
41 | | - expect(stopwatch.currentLap).toBe("00:00:05"); |
| 40 | + stopwatch.advanceTime('00:00:05'); |
| 41 | + expect(stopwatch.currentLap).toBe('00:00:05'); |
42 | 42 | }); |
43 | 43 |
|
44 | | - xtest("start initiates time tracking for total", () => { |
| 44 | + xtest('start initiates time tracking for total', () => { |
45 | 45 | const stopwatch = new SplitSecondStopwatch(); |
46 | 46 | stopwatch.start(); |
47 | | - stopwatch.advanceTime("00:00:23"); |
48 | | - expect(stopwatch.total).toBe("00:00:23"); |
| 47 | + stopwatch.advanceTime('00:00:23'); |
| 48 | + expect(stopwatch.total).toBe('00:00:23'); |
49 | 49 | }); |
50 | 50 |
|
51 | | - xtest("start cannot be called from running state", () => { |
| 51 | + xtest('start cannot be called from running state', () => { |
52 | 52 | const stopwatch = new SplitSecondStopwatch(); |
53 | 53 | stopwatch.start(); |
54 | | - expect(() => stopwatch.start()).toThrow("cannot start an already running stopwatch"); |
| 54 | + expect(() => stopwatch.start()).toThrow( |
| 55 | + 'cannot start an already running stopwatch', |
| 56 | + ); |
55 | 57 | }); |
56 | 58 |
|
57 | | - xtest("stop from running state changes state to stopped", () => { |
| 59 | + xtest('stop from running state changes state to stopped', () => { |
58 | 60 | const stopwatch = new SplitSecondStopwatch(); |
59 | 61 | stopwatch.start(); |
60 | 62 | stopwatch.stop(); |
61 | | - expect(stopwatch.state).toBe("stopped"); |
| 63 | + expect(stopwatch.state).toBe('stopped'); |
62 | 64 | }); |
63 | 65 |
|
64 | | - xtest("stop pauses time tracking for current lap", () => { |
| 66 | + xtest('stop pauses time tracking for current lap', () => { |
65 | 67 | const stopwatch = new SplitSecondStopwatch(); |
66 | 68 | stopwatch.start(); |
67 | | - stopwatch.advanceTime("00:00:05"); |
| 69 | + stopwatch.advanceTime('00:00:05'); |
68 | 70 | stopwatch.stop(); |
69 | | - stopwatch.advanceTime("00:00:08"); |
70 | | - expect(stopwatch.currentLap).toBe("00:00:05"); |
| 71 | + stopwatch.advanceTime('00:00:08'); |
| 72 | + expect(stopwatch.currentLap).toBe('00:00:05'); |
71 | 73 | }); |
72 | 74 |
|
73 | | - xtest("stop pauses time tracking for total", () => { |
| 75 | + xtest('stop pauses time tracking for total', () => { |
74 | 76 | const stopwatch = new SplitSecondStopwatch(); |
75 | 77 | stopwatch.start(); |
76 | | - stopwatch.advanceTime("00:00:13"); |
| 78 | + stopwatch.advanceTime('00:00:13'); |
77 | 79 | stopwatch.stop(); |
78 | | - stopwatch.advanceTime("00:00:44"); |
79 | | - expect(stopwatch.total).toBe("00:00:13"); |
| 80 | + stopwatch.advanceTime('00:00:44'); |
| 81 | + expect(stopwatch.total).toBe('00:00:13'); |
80 | 82 | }); |
81 | 83 |
|
82 | | - xtest("stop cannot be called from ready state", () => { |
| 84 | + xtest('stop cannot be called from ready state', () => { |
83 | 85 | const stopwatch = new SplitSecondStopwatch(); |
84 | | - expect(() => stopwatch.stop()).toThrow("cannot stop a stopwatch that is not running"); |
| 86 | + expect(() => stopwatch.stop()).toThrow( |
| 87 | + 'cannot stop a stopwatch that is not running', |
| 88 | + ); |
85 | 89 | }); |
86 | 90 |
|
87 | | - xtest("stop cannot be called from stopped state", () => { |
| 91 | + xtest('stop cannot be called from stopped state', () => { |
88 | 92 | const stopwatch = new SplitSecondStopwatch(); |
89 | 93 | stopwatch.start(); |
90 | 94 | stopwatch.stop(); |
91 | | - expect(() => stopwatch.stop()).toThrow("cannot stop a stopwatch that is not running"); |
| 95 | + expect(() => stopwatch.stop()).toThrow( |
| 96 | + 'cannot stop a stopwatch that is not running', |
| 97 | + ); |
92 | 98 | }); |
93 | 99 |
|
94 | | - xtest("start from stopped state changes state to running", () => { |
| 100 | + xtest('start from stopped state changes state to running', () => { |
95 | 101 | const stopwatch = new SplitSecondStopwatch(); |
96 | 102 | stopwatch.start(); |
97 | 103 | stopwatch.stop(); |
98 | 104 | stopwatch.start(); |
99 | | - expect(stopwatch.state).toBe("running"); |
| 105 | + expect(stopwatch.state).toBe('running'); |
100 | 106 | }); |
101 | 107 |
|
102 | | - xtest("start from stopped state resumes time tracking for current lap", () => { |
| 108 | + xtest('start from stopped state resumes time tracking for current lap', () => { |
103 | 109 | const stopwatch = new SplitSecondStopwatch(); |
104 | 110 | stopwatch.start(); |
105 | | - stopwatch.advanceTime("00:01:20"); |
| 111 | + stopwatch.advanceTime('00:01:20'); |
106 | 112 | stopwatch.stop(); |
107 | | - stopwatch.advanceTime("00:00:20"); |
| 113 | + stopwatch.advanceTime('00:00:20'); |
108 | 114 | stopwatch.start(); |
109 | | - stopwatch.advanceTime("00:00:08"); |
110 | | - expect(stopwatch.currentLap).toBe("00:01:28"); |
| 115 | + stopwatch.advanceTime('00:00:08'); |
| 116 | + expect(stopwatch.currentLap).toBe('00:01:28'); |
111 | 117 | }); |
112 | 118 |
|
113 | | - xtest("start from stopped state resumes time tracking for total", () => { |
| 119 | + xtest('start from stopped state resumes time tracking for total', () => { |
114 | 120 | const stopwatch = new SplitSecondStopwatch(); |
115 | 121 | stopwatch.start(); |
116 | | - stopwatch.advanceTime("00:00:23"); |
| 122 | + stopwatch.advanceTime('00:00:23'); |
117 | 123 | stopwatch.stop(); |
118 | | - stopwatch.advanceTime("00:00:44"); |
| 124 | + stopwatch.advanceTime('00:00:44'); |
119 | 125 | stopwatch.start(); |
120 | | - stopwatch.advanceTime("00:00:09"); |
121 | | - expect(stopwatch.total).toBe("00:00:32"); |
| 126 | + stopwatch.advanceTime('00:00:09'); |
| 127 | + expect(stopwatch.total).toBe('00:00:32'); |
122 | 128 | }); |
123 | 129 |
|
124 | | - xtest("lap adds current lap to previous laps", () => { |
| 130 | + xtest('lap adds current lap to previous laps', () => { |
125 | 131 | const stopwatch = new SplitSecondStopwatch(); |
126 | 132 | stopwatch.start(); |
127 | | - stopwatch.advanceTime("00:01:38"); |
| 133 | + stopwatch.advanceTime('00:01:38'); |
128 | 134 | stopwatch.lap(); |
129 | | - expect(stopwatch.previousLaps).toEqual(["00:01:38"]); |
130 | | - stopwatch.advanceTime("00:00:44"); |
| 135 | + expect(stopwatch.previousLaps).toEqual(['00:01:38']); |
| 136 | + stopwatch.advanceTime('00:00:44'); |
131 | 137 | stopwatch.lap(); |
132 | | - expect(stopwatch.previousLaps).toEqual(["00:01:38", "00:00:44"]); |
| 138 | + expect(stopwatch.previousLaps).toEqual(['00:01:38', '00:00:44']); |
133 | 139 | }); |
134 | 140 |
|
135 | | - xtest("lap resets current lap and resumes time tracking", () => { |
| 141 | + xtest('lap resets current lap and resumes time tracking', () => { |
136 | 142 | const stopwatch = new SplitSecondStopwatch(); |
137 | 143 | stopwatch.start(); |
138 | | - stopwatch.advanceTime("00:08:22"); |
| 144 | + stopwatch.advanceTime('00:08:22'); |
139 | 145 | stopwatch.lap(); |
140 | | - expect(stopwatch.currentLap).toBe("00:00:00"); |
141 | | - stopwatch.advanceTime("00:00:15"); |
142 | | - expect(stopwatch.currentLap).toBe("00:00:15"); |
| 146 | + expect(stopwatch.currentLap).toBe('00:00:00'); |
| 147 | + stopwatch.advanceTime('00:00:15'); |
| 148 | + expect(stopwatch.currentLap).toBe('00:00:15'); |
143 | 149 | }); |
144 | 150 |
|
145 | | - xtest("lap continues time tracking for total", () => { |
| 151 | + xtest('lap continues time tracking for total', () => { |
146 | 152 | const stopwatch = new SplitSecondStopwatch(); |
147 | 153 | stopwatch.start(); |
148 | | - stopwatch.advanceTime("00:00:22"); |
| 154 | + stopwatch.advanceTime('00:00:22'); |
149 | 155 | stopwatch.lap(); |
150 | | - stopwatch.advanceTime("00:00:33"); |
151 | | - expect(stopwatch.total).toBe("00:00:55"); |
| 156 | + stopwatch.advanceTime('00:00:33'); |
| 157 | + expect(stopwatch.total).toBe('00:00:55'); |
152 | 158 | }); |
153 | 159 |
|
154 | | - xtest("lap cannot be called from ready state", () => { |
| 160 | + xtest('lap cannot be called from ready state', () => { |
155 | 161 | const stopwatch = new SplitSecondStopwatch(); |
156 | | - expect(() => stopwatch.lap()).toThrow("cannot lap a stopwatch that is not running"); |
| 162 | + expect(() => stopwatch.lap()).toThrow( |
| 163 | + 'cannot lap a stopwatch that is not running', |
| 164 | + ); |
157 | 165 | }); |
158 | 166 |
|
159 | | - xtest("lap cannot be called from stopped state", () => { |
| 167 | + xtest('lap cannot be called from stopped state', () => { |
160 | 168 | const stopwatch = new SplitSecondStopwatch(); |
161 | 169 | stopwatch.start(); |
162 | 170 | stopwatch.stop(); |
163 | | - expect(() => stopwatch.lap()).toThrow("cannot lap a stopwatch that is not running"); |
| 171 | + expect(() => stopwatch.lap()).toThrow( |
| 172 | + 'cannot lap a stopwatch that is not running', |
| 173 | + ); |
164 | 174 | }); |
165 | 175 |
|
166 | | - xtest("stop does not change previous laps", () => { |
| 176 | + xtest('stop does not change previous laps', () => { |
167 | 177 | const stopwatch = new SplitSecondStopwatch(); |
168 | 178 | stopwatch.start(); |
169 | | - stopwatch.advanceTime("00:11:22"); |
| 179 | + stopwatch.advanceTime('00:11:22'); |
170 | 180 | stopwatch.lap(); |
171 | | - expect(stopwatch.previousLaps).toEqual(["00:11:22"]); |
| 181 | + expect(stopwatch.previousLaps).toEqual(['00:11:22']); |
172 | 182 | stopwatch.stop(); |
173 | | - expect(stopwatch.previousLaps).toEqual(["00:11:22"]); |
| 183 | + expect(stopwatch.previousLaps).toEqual(['00:11:22']); |
174 | 184 | }); |
175 | 185 |
|
176 | | - xtest("reset from stopped state changes state to ready", () => { |
| 186 | + xtest('reset from stopped state changes state to ready', () => { |
177 | 187 | const stopwatch = new SplitSecondStopwatch(); |
178 | 188 | stopwatch.start(); |
179 | 189 | stopwatch.stop(); |
180 | 190 | stopwatch.reset(); |
181 | | - expect(stopwatch.state).toBe("ready"); |
| 191 | + expect(stopwatch.state).toBe('ready'); |
182 | 192 | }); |
183 | 193 |
|
184 | | - xtest("reset resets current lap", () => { |
| 194 | + xtest('reset resets current lap', () => { |
185 | 195 | const stopwatch = new SplitSecondStopwatch(); |
186 | 196 | stopwatch.start(); |
187 | | - stopwatch.advanceTime("00:00:10"); |
| 197 | + stopwatch.advanceTime('00:00:10'); |
188 | 198 | stopwatch.stop(); |
189 | 199 | stopwatch.reset(); |
190 | | - expect(stopwatch.currentLap).toBe("00:00:00"); |
| 200 | + expect(stopwatch.currentLap).toBe('00:00:00'); |
191 | 201 | }); |
192 | 202 |
|
193 | | - xtest("reset clears previous laps", () => { |
| 203 | + xtest('reset clears previous laps', () => { |
194 | 204 | const stopwatch = new SplitSecondStopwatch(); |
195 | 205 | stopwatch.start(); |
196 | | - stopwatch.advanceTime("00:00:10"); |
| 206 | + stopwatch.advanceTime('00:00:10'); |
197 | 207 | stopwatch.lap(); |
198 | | - stopwatch.advanceTime("00:00:20"); |
| 208 | + stopwatch.advanceTime('00:00:20'); |
199 | 209 | stopwatch.lap(); |
200 | | - expect(stopwatch.previousLaps).toEqual(["00:00:10", "00:00:20"]); |
| 210 | + expect(stopwatch.previousLaps).toEqual(['00:00:10', '00:00:20']); |
201 | 211 | stopwatch.stop(); |
202 | 212 | stopwatch.reset(); |
203 | 213 | expect(stopwatch.previousLaps).toEqual([]); |
204 | 214 | }); |
205 | 215 |
|
206 | | - xtest("reset cannot be called from ready state", () => { |
| 216 | + xtest('reset cannot be called from ready state', () => { |
207 | 217 | const stopwatch = new SplitSecondStopwatch(); |
208 | | - expect(() => stopwatch.reset()).toThrow("cannot reset a stopwatch that is not stopped"); |
| 218 | + expect(() => stopwatch.reset()).toThrow( |
| 219 | + 'cannot reset a stopwatch that is not stopped', |
| 220 | + ); |
209 | 221 | }); |
210 | 222 |
|
211 | | - xtest("reset cannot be called from running state", () => { |
| 223 | + xtest('reset cannot be called from running state', () => { |
212 | 224 | const stopwatch = new SplitSecondStopwatch(); |
213 | 225 | stopwatch.start(); |
214 | | - expect(() => stopwatch.reset()).toThrow("cannot reset a stopwatch that is not stopped"); |
| 226 | + expect(() => stopwatch.reset()).toThrow( |
| 227 | + 'cannot reset a stopwatch that is not stopped', |
| 228 | + ); |
215 | 229 | }); |
216 | 230 |
|
217 | | - xtest("supports very long laps", () => { |
| 231 | + xtest('supports very long laps', () => { |
218 | 232 | const stopwatch = new SplitSecondStopwatch(); |
219 | 233 | stopwatch.start(); |
220 | | - stopwatch.advanceTime("01:23:45"); |
221 | | - expect(stopwatch.currentLap).toBe("01:23:45"); |
| 234 | + stopwatch.advanceTime('01:23:45'); |
| 235 | + expect(stopwatch.currentLap).toBe('01:23:45'); |
222 | 236 | stopwatch.lap(); |
223 | | - expect(stopwatch.previousLaps).toEqual(["01:23:45"]); |
224 | | - stopwatch.advanceTime("04:01:40"); |
225 | | - expect(stopwatch.currentLap).toBe("04:01:40"); |
226 | | - expect(stopwatch.total).toBe("05:25:25"); |
| 237 | + expect(stopwatch.previousLaps).toEqual(['01:23:45']); |
| 238 | + stopwatch.advanceTime('04:01:40'); |
| 239 | + expect(stopwatch.currentLap).toBe('04:01:40'); |
| 240 | + expect(stopwatch.total).toBe('05:25:25'); |
227 | 241 | stopwatch.lap(); |
228 | | - expect(stopwatch.previousLaps).toEqual(["01:23:45", "04:01:40"]); |
229 | | - stopwatch.advanceTime("08:43:05"); |
230 | | - expect(stopwatch.currentLap).toBe("08:43:05"); |
231 | | - expect(stopwatch.total).toBe("14:08:30"); |
| 242 | + expect(stopwatch.previousLaps).toEqual(['01:23:45', '04:01:40']); |
| 243 | + stopwatch.advanceTime('08:43:05'); |
| 244 | + expect(stopwatch.currentLap).toBe('08:43:05'); |
| 245 | + expect(stopwatch.total).toBe('14:08:30'); |
232 | 246 | stopwatch.lap(); |
233 | 247 | expect(stopwatch.previousLaps).toEqual([ |
234 | | - "01:23:45", |
235 | | - "04:01:40", |
236 | | - "08:43:05", |
| 248 | + '01:23:45', |
| 249 | + '04:01:40', |
| 250 | + '08:43:05', |
237 | 251 | ]); |
238 | 252 | }); |
239 | 253 | }); |
0 commit comments