-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.ts
61 lines (42 loc) · 1.35 KB
/
index.test.ts
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { create } from "./index";
describe('scrambler', () => {
it('should scramble and restore a number', () => {
const digits = 6
const n1 = 138361
const n2 = 855241
const seed = 123456789
const stages = 10
const s = create(digits, n1, n2, seed, stages)
const n = 1234
const scrambled = s.scramble(n)
expect(scrambled).not.toBe(n)
const restored = s.restore(scrambled)
expect(restored).toBe(n)
})
it('should scramble and restore a max number', () => {
const digits = 6
const n1 = 138361
const n2 = 855241
const seed = 123456789
const stages = 4
const s = create(digits, n1, n2, seed, stages)
const n = 999999
const scrambled = s.scramble(n)
expect(scrambled).not.toBe(n)
const restored = s.restore(scrambled)
expect(restored).toBe(n)
})
it('should 9999 numbers should be unique', () => {
const digits = 4
const n1 = 1101
const n2 = 8901
const seed = 123456789
const stages = 10
const s = create(digits, n1, n2, seed, stages)
const scrambled = new Set<number>()
for (let i = 0; i < 10000; i++) {
scrambled.add(s.scramble(i))
}
expect(scrambled.size).toBe(10000)
})
})