Files
rand/index.test.ts
T
2024-06-11 08:17:39 +02:00

37 lines
891 B
TypeScript

import {expect, test} from 'bun:test'
import Random from '.'
test('same result', async () => {
const random1 = new Random(new Uint8Array(64))
const a = await random1.random(128n)
const a2 = await random1.random(128n)
expect(a2).not.toBe(a)
const random2 = new Random(new Uint8Array(64))
const b = await random2.random(128n)
expect(a).toBe(b)
})
test('Different state, different number', async () => {
const random1 = new Random(new Uint8Array(64))
const a = await random1.random(128n)
const state = new Uint8Array(64)
state[0] = 1
const random2= new Random(state)
const b = await random2.random(128n)
expect(a).not.toBe(b)
})
test('New random is random', async () => {
const r1 = new Random()
const r2 = new Random()
const a = await r1.random(100n)
const b = await r2.random(100n)
expect(b).not.toBe(a)
})