Skip to content

Commit

Permalink
refactor(curriculum): use RandomMocker from curriculum-helpers (freeC…
Browse files Browse the repository at this point in the history
  • Loading branch information
ojeytonwilliams authored Oct 1, 2024
1 parent 0f5cb9d commit a3e6a35
Showing 1 changed file with 6 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,25 @@ assert.lengthOf(diceValuesArr, 5);
When your `rollDiceBtn` is clicked a second time, your `diceValuesArr` array should contain only five new elements.

```js
__setRandom();
const __mocker = new __helpers.RandomMocker();
try {
__mocker.mock();
rollDiceBtn.click();
const old = [...diceValuesArr];
rollDiceBtn.click();
assert.lengthOf(diceValuesArr, 5);
assert.notDeepEqual(old, diceValuesArr);
} finally {
__restoreRandom();
__mocker.restore();
}
```

Each of your random numbers should be between 1 and 6 inclusive.

```js
__setRandom();
const __mocker = new __helpers.RandomMocker();
try {
__mocker.mock();
for (let i = 1; i < 20; i++) {
rollDiceBtn.click();
for (const val of diceValuesArr) {
Expand All @@ -48,7 +50,7 @@ try {
}
}
} finally {
__restoreRandom();
__mocker.restore();
}

```
Expand All @@ -62,30 +64,6 @@ assert.deepEqual(numbers, diceValuesArr);

# --seed--

## --before-user-code--

```js
const __oldRandom = Math.random;
const __createRandom = () => {
let seed = 42;
const a = 1664525;
const c = 1013904223;
const mod = 2**32;
return () => {
seed = (a * seed + c) % mod;
return seed / mod;
};
};

const __setRandom = () => {
Math.random = __createRandom();
};

const __restoreRandom = () => {
Math.random = __oldRandom;
};
```

## --seed-contents--

```html
Expand Down

0 comments on commit a3e6a35

Please sign in to comment.