delete support for Array & Map
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
/* @flow */
|
||||
/*eslint-env browser,jasmine */
|
||||
|
||||
var numberOfYArrayTests = 10;
|
||||
var numberOfYArrayTests = 20;
|
||||
|
||||
describe("Array Type", function(){
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 3000;
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
|
||||
beforeEach(function(done){
|
||||
createUsers(this, 5, done);
|
||||
});
|
||||
@@ -42,11 +42,64 @@ describe("Array Type", function(){
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("Basic insert&delete in array (handle three conflicts)", function(done){
|
||||
var y = this.users[0];
|
||||
var l1, l2, l3;
|
||||
y.root.set("Array", Y.Array).then((array)=>{
|
||||
l1 = array;
|
||||
l1.insert(0, ["x", "y", "z"]);
|
||||
y.connector.flushAll();
|
||||
l1.insert(1, [0]);
|
||||
return this.users[1].root.get("Array");
|
||||
}).then((array)=>{
|
||||
l2 = array;
|
||||
l2.delete(0);
|
||||
l2.delete(1);
|
||||
return this.users[2].root.get("Array");
|
||||
}).then((array)=>{
|
||||
l3 = array;
|
||||
l3.insert(1, [2]);
|
||||
y.connector.flushAll();
|
||||
expect(l1.toArray()).toEqual(l2.toArray());
|
||||
expect(l2.toArray()).toEqual(l3.toArray());
|
||||
expect(l2.toArray()).toEqual([0, 2, "y"]);
|
||||
compareAllUsers(this.users);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("Basic insert. Then delete the whole array", function(done){
|
||||
var y = this.users[0];
|
||||
var l1, l2, l3;
|
||||
y.root.set("Array", Y.Array).then((array)=>{
|
||||
l1 = array;
|
||||
l1.insert(0, ["x", "y", "z"]);
|
||||
y.connector.flushAll();
|
||||
l1.delete(0, 3);
|
||||
return this.users[1].root.get("Array");
|
||||
}).then((array)=>{
|
||||
l2 = array;
|
||||
return this.users[2].root.get("Array");
|
||||
}).then((array)=>{
|
||||
l3 = array;
|
||||
y.connector.flushAll();
|
||||
expect(l1.toArray()).toEqual(l2.toArray());
|
||||
expect(l2.toArray()).toEqual(l3.toArray());
|
||||
expect(l2.toArray()).toEqual([]);
|
||||
compareAllUsers(this.users);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("Random tests", function(){
|
||||
var randomMapTransactions = [
|
||||
describe(`${numberOfYArrayTests} Random tests`, function(){
|
||||
var randomArrayTransactions = [
|
||||
function insert (array) {
|
||||
array.insert(getRandomNumber(array.toArray().length), [getRandomNumber()]);
|
||||
},
|
||||
function _delete (array) {
|
||||
var length = array.toArray().length;
|
||||
if (length > 0) {
|
||||
array.delete(getRandomNumber(length - 1));
|
||||
}
|
||||
}
|
||||
];
|
||||
function compareArrayValues(arrays){
|
||||
@@ -82,7 +135,7 @@ describe("Array Type", function(){
|
||||
expect(this.arrays.length).toEqual(this.users.length);
|
||||
});
|
||||
it(`succeed after ${numberOfYArrayTests} actions`, function(done){
|
||||
applyRandomTransactions(this.users, this.arrays, randomMapTransactions, numberOfYArrayTests);
|
||||
applyRandomTransactions(this.users, this.arrays, randomArrayTransactions, numberOfYArrayTests);
|
||||
setTimeout(()=>{
|
||||
compareAllUsers(this.users);
|
||||
compareArrayValues(this.arrays);
|
||||
|
||||
Reference in New Issue
Block a user