diff --git a/exercises/concept/captains-log/.docs/instructions.md b/exercises/concept/captains-log/.docs/instructions.md index 5b8b2a8d61..c774bc04aa 100644 --- a/exercises/concept/captains-log/.docs/instructions.md +++ b/exercises/concept/captains-log/.docs/instructions.md @@ -36,6 +36,12 @@ randomStardate(); // => 41458.15721310934 ``` + +~~~exercism/caution +It is expected that the smallest random number (0) results in the smallest random stardate (41000.0) and +the largest random number (just under 1) results in the largest random stardate (41999.999...). +~~~ + ## 3. Generate a random planet The Starship Enterprise encounters many planets in its travels. diff --git a/exercises/concept/captains-log/captains-log.spec.js b/exercises/concept/captains-log/captains-log.spec.js index 5cfd79d0bb..52350d56c7 100644 --- a/exercises/concept/captains-log/captains-log.spec.js +++ b/exercises/concept/captains-log/captains-log.spec.js @@ -1,4 +1,4 @@ -import { describe, expect, test } from '@jest/globals'; +import { describe, expect, test, beforeEach, afterEach } from '@jest/globals'; import { randomShipRegistryNumber, randomStardate, @@ -12,7 +12,7 @@ describe('randomShipRegistryNumber', () => { } }); - test('returns a random registry number', () => { + test('is a random registry number', () => { expect(randomShipRegistryNumber()).not.toEqual(randomShipRegistryNumber()); }); }); @@ -33,24 +33,33 @@ function loadDie(...values) { } describe('randomStardate', () => { - test('stardate is between 41000 and 42000', () => { + let restore; + + beforeEach(() => { const min = 0; const max = 1 - Number.EPSILON * 32; // prettier-ignore - const restore = loadDie( + restore = loadDie( min, min, min, min, min, min, max, max, max, max, max, max, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ); + }); + + afterEach(() => { + if (restore) { + restore(); + restore = undefined; + } + }); + test('stardate is between 41000 and 42000', () => { for (let i = 0; i < 10_000; i++) { const starDate = randomStardate(); expect(starDate).toBeGreaterThanOrEqual(41_000); expect(starDate).toBeLessThan(42_000); } - - restore(); }); });