-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrand.js
More file actions
42 lines (34 loc) · 969 Bytes
/
rand.js
File metadata and controls
42 lines (34 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import test from 'ava'
import litecanvas from '../src/index.js'
import * as sinon from 'sinon'
/** @type {LitecanvasInstance} */
let local
const N = 1000
const MIN = 50
const MAX = 100
test.before(() => {
sinon.stub(console) // silent console
local = litecanvas({})
})
test.after(() => {
local.quit()
})
test('produces random float numbers between MIN and MAX', async (t) => {
for (let i = 0; i < N; i++) {
const randomNumber = local.rand(MIN, MAX)
t.true(randomNumber >= MIN && randomNumber <= MAX)
}
})
test('by default, produces random float numbers between 0 and 1.0', async (t) => {
for (let i = 0; i < N; i++) {
const randomNumber = local.rand()
t.true(randomNumber >= 0 && randomNumber < 1.0)
}
})
test('MIN and MAX with same input', async (t) => {
for (let i = 0; i < N; i++) {
const x = 10
const randomNumber = local.rand(x, x)
t.true(randomNumber === x)
}
})