-
Notifications
You must be signed in to change notification settings - Fork 34
/
test.js
80 lines (70 loc) · 2.67 KB
/
test.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
var jot = require("./jot");
var deepEqual = require("deep-equal");
var createRandomOp = jot.createRandomOp; // require('./jot/values.js').createRandomOp;
// Create two complex simultaneous edits.
var opsize = 1;
while (true) {
var initial_value = jot.createRandomValue();
var op1 = jot.createRandomOpSequence(initial_value, opsize);
var op2 = jot.createRandomOpSequence(initial_value, opsize);
/*
var initial_value = false;
var op1 = jot.opFromJSON({"_type":"meta.LIST","ops":[{"_type":"values.SET","new_value":-226.62491332471424},{"_type":"values.NO_OP"}]});
var op2 = jot.opFromJSON({"_type":"meta.LIST","ops":[{"_type":"values.MATH","operator":"and","operand":true},{"_type":"values.MATH","operator":"and","operand":false}]});
*/
//console.log(initial_value)
//console.log(op1)
//console.log(op2)
try {
// Compute the end results.
var val1 = op1.apply(initial_value);
var val2 = op2.apply(initial_value);
// Check that the parallel rebases match.
var op2r = op2.rebase(op1, { document: initial_value });
var val1b = op2r ? op2r.apply(val1) : null;
var op1r = op1.rebase(op2, { document: initial_value });
var val2b = op1r ? op1r.apply(val2) : null;
// Check that they also match using composition.
var val1c = op2r ? op1.compose(op2r).apply(initial_value) : null;
var val2c = op1r ? op2.compose(op1r).apply(initial_value) : null;
// Check that we can compute a diff.
var d = jot.diff(initial_value, val1b);
if (op2r === null || op1r === null
|| !deepEqual(val1b, val2b, { strict: true })
) {
console.log("rebase failed or did not have same result");
console.log("init", initial_value)
console.log();
console.log("op1", JSON.stringify(op1.toJSON()));
console.log("val", val1);
console.log("op2r", op2r);
console.log("val", val1b);
console.log();
console.log("op2", JSON.stringify(op2.toJSON()));
console.log("val", val2);
console.log("op1r", op1r);
console.log("val", val2b);
break;
} else if (!deepEqual(val1b, val1c, { strict: true }) || !deepEqual(val1c, val2c, { strict: true })) {
console.log("composition did not have same result");
console.log("init", initial_value)
console.log();
console.log("op1", JSON.stringify(op1.toJSON()));
console.log("val", val1);
console.log("op2r", op2r);
console.log("val", val1c);
console.log();
console.log("op2", JSON.stringify(op2.toJSON()));
console.log("val", val2);
console.log("op1r", op1r);
console.log("val", val2c);
break;
}
} catch (e) {
console.error(e);
console.log("init", initial_value)
console.log("op1", JSON.stringify(op1.toJSON()));
console.log("op2", JSON.stringify(op2.toJSON()));
break;
}
}