Utils test
This commit is contained in:
parent
63ea3ff952
commit
dc7787707c
1 changed files with 22 additions and 0 deletions
22
utils.test.ts
Normal file
22
utils.test.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { expect, test, spyOn } from "bun:test"
|
||||
import { arrayOfLength, arrayShuffle } from './utils';
|
||||
|
||||
test('arrayOfLength', () => {
|
||||
expect(arrayOfLength(3)).toHaveLength(3)
|
||||
})
|
||||
|
||||
test('arrayShuffle', () => {
|
||||
spyOn(global.Math, 'random').mockReturnValue(0.123);
|
||||
|
||||
const unshuffled = [1, 2, 3]
|
||||
const shuffled = arrayShuffle(unshuffled)
|
||||
|
||||
expect(shuffled.includes(unshuffled[0])).toBe(true)
|
||||
expect(shuffled.includes(unshuffled[1])).toBe(true)
|
||||
expect(shuffled.includes(unshuffled[2])).toBe(true)
|
||||
expect(shuffled[0]).not.toBe(unshuffled[0])
|
||||
expect(shuffled[1]).not.toBe(unshuffled[1])
|
||||
expect(shuffled[2]).not.toBe(unshuffled[2])
|
||||
|
||||
spyOn(global.Math, 'random').mockRestore();
|
||||
}, { repeats: 9 })
|
||||
Loading…
Add table
Reference in a new issue