Skip to content

Commit 5fbe8cf

Browse files
Update captains-log.spec.js
1 parent ef7aa46 commit 5fbe8cf

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed
Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,69 @@
11
import { describe, expect, test } from '@jest/globals';
22
import { randomShipRegistryNumber, randomStardate, randomPlanetClass } from './captains-log';
3-
describe('randomShipRegistryNumber',() => {
4-
test('registry numbers are valid',() => {
5-
for (let i=0;i<4; i++){
6-
expect(randomShipRegistryNumber()).toMatch(/NCC-[1-9][0-9]{3}/)
3+
4+
describe('randomShipRegistryNumber', () => {
5+
test('registry numbers are valid', () => {
6+
for (let i = 0; i < 4; i++) {
7+
expect(randomShipRegistryNumber()).toMatch(/NCC-[1-9][0-9]{3}/);
78
}
89
});
9-
test('returns a random registry number',() => {
10-
expect(randomShipRegistryNumber()).not.toEqual(randomShipRegistryNumber())
10+
11+
test('returns a random registry number', () => {
12+
expect(randomShipRegistryNumber()).not.toEqual(randomShipRegistryNumber());
1113
});
1214
});
15+
1316
function loadDie(...values) {
14-
const originalRandom = Math.random()
17+
const originalRandom = Math.random();
1518

1619
Math.random = function loadedDie() {
1720
if (values.length === 0) {
1821
return originalRandom();
1922
}
2023
return values.shift();
21-
}
24+
};
25+
2226
return () => {
2327
Math.random = originalRandom;
24-
}
28+
};
2529
}
26-
describe('randomStardate',() => {
27-
test('stardate is between 41000 and 42000',() => {
30+
31+
describe('randomStardate', () => {
32+
test('stardate is between 41000 and 42000', () => {
2833
const restore = loadDie(
2934
0, 0, 0, 0, 0, 0,
3035
1, 1, 1, 1, 1, 1,
3136
0.5, 0.5, 0.5, 0.5, 0.5, 0.5
3237
);
38+
3339
for (let i = 0; i < 10_000; i++) {
34-
const starDate = randomStardate()
40+
const starDate = randomStardate();
3541
expect(starDate).toBeGreaterThanOrEqual(41_000);
3642
expect(starDate).toBeLessThan(42_000);
3743
}
44+
3845
restore();
39-
}
40-
}
46+
});
47+
});
48+
4149
describe('randomPlanetClass', () => {
42-
test('planet classes are valid', () => {
43-
const expected = 'DHJKLMNRTY'
44-
const seen = {}
45-
for (let i=0; i < 1_000; i++){
46-
const actual = randomPlanetClass()
47-
expect(expected).toContain(actual)
50+
test('planet classes are valid', () => {
51+
const expected = 'DHJKLMNRTY';
52+
for (let i = 0; i < 1_000; i++) {
53+
const actual = randomPlanetClass();
54+
expect(expected).toContain(actual);
4855
}
49-
})
50-
test('all planet classes can be returned', () => {
51-
const expected = 'DHJKLMNRTY'
52-
const seen = {}
53-
for (let i=0; i < 1_000; i++){
54-
const actual = randomPlanetClass()
55-
seen[actual] = true
56+
});
57+
58+
test('all planet classes can be returned', () => {
59+
const expected = 'DHJKLMNRTY';
60+
const seen = {};
61+
62+
for (let i = 0; i < 1_000; i++) {
63+
const actual = randomPlanetClass();
64+
seen[actual] = true;
5665
}
57-
expected(Object.keys(seen).length).toBe(expected.length);
58-
})
59-
})
66+
67+
expect(Object.keys(seen).length).toBe(expected.length);
68+
});
69+
});

0 commit comments

Comments
 (0)