Skip to content

Instantly share code, notes, and snippets.

@froots froots/vector.js
Last active Oct 5, 2016

Embed
What would you like to do?
Stubbing Math.random()
export function random(vmin, vmax) {
return [
vmin[0] + Math.random() * (vmax[0] - vmin[0]),
vmin[1] + Math.random() * (vmax[1] - vmin[1])
];
}
import * as V from './vector';
import td from 'testdouble';
it('returns a random vector within the bounds given', () => {
const rand = td.replace(Math, 'random');
td.when(rand()).thenReturn(0.2, 0.8);
const vmin = [-50, -100];
const vmax = [50, 0];
const actual = V.random(vmin, vmax);
expect(actual).toEqual([-30, -20]);
td.reset();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.