-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.js
81 lines (76 loc) · 3.07 KB
/
tests.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const icepick = require('icepick')
const mori = require('mori')
const Immutable = require('immutable')
const seamless = require('seamless-immutable')
const immer = require('immer')
let input
const randomInt = (max = 10) => (Math.random() * max) | 0
function randomKey (max = 10) {
return `key${randomInt(max)}`
}
const simpleClone = (val) => { input = JSON.parse(JSON.stringify(val)) }
exports.defaultSetup = (suite, op) => {
if (op === 'create') {
return simpleClone
}
return (val) => {
simpleClone(val)
input = suite.create()
}
}
exports.libSuites = {
vanilla: {
create: () => input,
access: () => input[randomKey()],
assoc: () => { input[randomKey()] = Math.random() },
dissoc: () => { delete input[randomKey()] },
accessNested: () => input[randomKey()][randomInt()][randomKey()],
assocNested: () => { input[randomKey()][randomInt()][randomKey()] = Math.random() },
thaw: () => input
},
icepick: {
create: () => icepick.freeze(input),
access: () => input[randomKey()],
assoc: () => icepick.assoc(input, randomKey(), Math.random()),
dissoc: () => icepick.dissoc(input, randomKey()),
accessNested: () => input[randomKey()][randomInt()][randomKey()],
assocNested: () => icepick.assocIn(input, [randomKey(), randomInt(), randomKey()], Math.random()),
thaw: () => icepick.thaw(input)
},
seamless: {
create: () => seamless(input),
access: () => input[randomKey()],
assoc: () => seamless.set(input, randomKey(), Math.random()),
dissoc: () => seamless.without(input, randomKey()),
accessNested: () => input[randomKey()][randomInt()][randomKey()],
assocNested: () => seamless.setIn(input, [randomKey(), randomInt(), randomKey()], Math.random()),
thaw: () => seamless.asMutable(input, {deep: true})
},
immer: {
create: () => immer.produce(input, draft => {}),
access: () => input[randomKey()],
assoc: () => immer.produce(input, draft => { draft[randomKey()] = Math.random() }),
dissoc: () => immer.produce(input, draft => { delete draft[randomKey()] }),
accessNested: () => input[randomKey()][randomInt()][randomKey()],
assocNested: () => immer.produce(input, draft => { draft[randomKey()][randomInt()][randomKey()] = Math.random() }),
thaw: () => input
},
Immutable: {
create: () => Immutable.fromJS(input),
access: () => input.get(randomKey()),
assoc: () => input.set(randomKey(), Math.random()),
dissoc: () => input.delete(randomKey()),
accessNested: () => input.getIn([randomKey(), randomInt(), randomKey()]),
assocNested: () => input.setIn([randomKey(), randomInt(), randomKey()], Math.random()),
thaw: () => input.toJS()
},
mori: {
create: () => mori.toClj(input),
access: () => mori.get(input, randomKey()),
assoc: () => mori.assoc(input, randomKey(), Math.random()),
dissoc: () => mori.dissoc(input, randomKey()),
accessNested: () => mori.getIn(input, [randomKey(), randomInt(), randomKey()]),
assocNested: () => mori.assocIn(input, [randomKey(), randomInt(), randomKey()], Math.random()),
thaw: () => mori.toJs(input)
}
}