|
1 | | -import { describe, expect, test } from '@jest/globals'; |
| 1 | +import { describe, expect, test, beforeEach, afterEach } from '@jest/globals'; |
2 | 2 | import { |
3 | 3 | randomShipRegistryNumber, |
4 | 4 | randomStardate, |
@@ -33,24 +33,33 @@ function loadDie(...values) { |
33 | 33 | } |
34 | 34 |
|
35 | 35 | describe('randomStardate', () => { |
36 | | - test('stardate is between 41000 and 42000', () => { |
| 36 | + let restore; |
| 37 | + |
| 38 | + beforeEach(() => { |
37 | 39 | const min = 0; |
38 | 40 | const max = 1 - Number.EPSILON * 32; |
39 | 41 |
|
40 | 42 | // prettier-ignore |
41 | | - const restore = loadDie( |
| 43 | + restore = loadDie( |
42 | 44 | min, min, min, min, min, min, |
43 | 45 | max, max, max, max, max, max, |
44 | 46 | 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 |
45 | 47 | ); |
| 48 | + }); |
| 49 | + |
| 50 | + afterEach(() => { |
| 51 | + if (restore) { |
| 52 | + restore(); |
| 53 | + restore = undefined; |
| 54 | + } |
| 55 | + }); |
46 | 56 |
|
| 57 | + test('stardate is between 41000 and 42000', () => { |
47 | 58 | for (let i = 0; i < 10_000; i++) { |
48 | 59 | const starDate = randomStardate(); |
49 | 60 | expect(starDate).toBeGreaterThanOrEqual(41_000); |
50 | 61 | expect(starDate).toBeLessThan(42_000); |
51 | 62 | } |
52 | | - |
53 | | - restore(); |
54 | 63 | }); |
55 | 64 | }); |
56 | 65 |
|
|
0 commit comments