Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Y
yjs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sweng-group-15
yjs
Commits
66a7d272
Commit
66a7d272
authored
9 years ago
by
Kevin Jahns
Browse files
Options
Downloads
Patches
Plain Diff
split the big text suite into smaller ones
parent
d50d34dc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.eslintrc
+5
-1
5 additions, 1 deletion
.eslintrc
src/Types/Array.spec.js
+93
-0
93 additions, 0 deletions
src/Types/Array.spec.js
src/Types/Map.spec.js
+145
-0
145 additions, 0 deletions
src/Types/Map.spec.js
src/helper.spec.js
+99
-0
99 additions, 0 deletions
src/helper.spec.js
with
342 additions
and
1 deletion
.eslintrc
+
5
−
1
View file @
66a7d272
...
...
@@ -29,6 +29,10 @@
"getRandom": true,
"RBTree": true,
"compareIds": true,
"EventHandler": true
"EventHandler": true,
"compareAllUsers": true,
"createUsers": true,
"getRandomNumber": true,
"applyRandomTransactions": true
}
}
This diff is collapsed.
Click to expand it.
src/Types/Array.spec.js
0 → 100644
+
93
−
0
View file @
66a7d272
/* @flow */
/*eslint-env browser,jasmine */
var
numberOfYArrayTests
=
10
;
describe
(
"
Array Type
"
,
function
(){
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
3000
;
beforeEach
(
function
(
done
){
createUsers
(
this
,
5
,
done
);
});
describe
(
"
Basic tests
"
,
function
(){
it
(
"
insert three elements
"
,
function
(
done
){
var
y
=
this
.
users
[
0
].
root
;
y
.
set
(
"
Array
"
,
Y
.
Array
).
then
(
function
(
array
)
{
array
.
insert
(
0
,
[
1
,
2
,
3
]);
return
y
.
get
(
"
Array
"
);
}).
then
(
function
(
array
){
expect
(
array
.
toArray
()).
toEqual
([
1
,
2
,
3
]);
done
();
});
});
it
(
"
Basic insert 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
;
y
.
connector
.
flushAll
();
l1
.
insert
(
0
,
[
0
]);
return
this
.
users
[
1
].
root
.
get
(
"
Array
"
);
}).
then
((
array
)
=>
{
l2
=
array
;
l2
.
insert
(
0
,
[
1
]);
return
this
.
users
[
2
].
root
.
get
(
"
Array
"
);
}).
then
((
array
)
=>
{
l3
=
array
;
l3
.
insert
(
0
,
[
2
]);
y
.
connector
.
flushAll
();
expect
(
l1
.
toArray
()).
toEqual
(
l2
.
toArray
());
expect
(
l2
.
toArray
()).
toEqual
(
l3
.
toArray
());
compareAllUsers
(
this
.
users
);
done
();
});
});
});
describe
(
"
Random tests
"
,
function
(){
var
randomMapTransactions
=
[
function
insert
(
array
)
{
array
.
insert
(
getRandomNumber
(
array
.
toArray
().
length
),
[
getRandomNumber
()]);
}
];
function
compareArrayValues
(
arrays
){
var
firstArray
;
for
(
var
l
of
arrays
)
{
var
val
=
l
.
toArray
();
if
(
firstArray
==
null
)
{
firstArray
=
val
;
}
else
{
expect
(
val
).
toEqual
(
firstArray
);
}
}
}
beforeEach
(
function
(
done
){
this
.
users
[
0
].
root
.
set
(
"
Array
"
,
Y
.
Array
);
this
.
users
[
0
].
connector
.
flushAll
();
var
then
=
Promise
.
resolve
();
var
arrays
=
[];
for
(
var
u
of
this
.
users
)
{
then
=
then
.
then
(
function
(){
//eslint-disable-line
return
u
.
root
.
get
(
"
Array
"
);
}).
then
(
function
(
array
){
//eslint-disable-line
arrays
.
push
(
array
);
});
}
this
.
arrays
=
arrays
;
then
.
then
(
function
(){
done
();
});
});
it
(
"
arrays.length equals users.length
"
,
function
(){
expect
(
this
.
arrays
.
length
).
toEqual
(
this
.
users
.
length
);
});
it
(
`succeed after
${
numberOfYArrayTests
}
actions`
,
function
(
done
){
applyRandomTransactions
(
this
.
users
,
this
.
arrays
,
randomMapTransactions
,
numberOfYArrayTests
);
setTimeout
(()
=>
{
compareAllUsers
(
this
.
users
);
compareArrayValues
(
this
.
arrays
);
done
();
},
500
);
});
});
});
This diff is collapsed.
Click to expand it.
src/
y
.spec.js
→
src/
Types/Map
.spec.js
+
145
−
0
View file @
66a7d272
/* @flow */
/*eslint-env browser,jasmine */
// returns a random element of o
// works on Object, and Array
function
getRandom
(
o
)
{
if
(
o
instanceof
Array
)
{
return
o
[
Math
.
floor
(
Math
.
random
()
*
o
.
length
)];
}
else
if
(
o
.
constructor
===
Object
)
{
var
ks
=
[];
for
(
var
key
in
o
)
{
ks
.
push
(
key
);
}
return
o
[
getRandom
(
ks
)];
}
}
function
getRandomNumber
(
n
)
{
if
(
n
==
null
)
{
n
=
9999
;
}
return
Math
.
floor
(
Math
.
random
()
*
n
);
}
var
numberOfYMapTests
=
5
;
function
applyRandomTransactions
(
users
,
objects
,
transactions
,
numberOfTransactions
)
{
function
randomTransaction
(
root
)
{
var
f
=
getRandom
(
transactions
);
f
(
root
);
}
for
(
var
i
=
0
;
i
<
numberOfTransactions
;
i
++
)
{
var
r
=
Math
.
random
();
if
(
r
>=
0.9
)
{
// 10% chance to flush
users
[
0
].
connector
.
flushOne
();
}
else
{
randomTransaction
(
getRandom
(
objects
));
}
}
}
function
compareAllUsers
(
users
){
var
s1
,
s2
;
function
*
t1
(){
s1
=
yield
*
this
.
getStateSet
();
}
function
*
t2
(){
s2
=
yield
*
this
.
getStateSet
();
}
users
[
0
].
connector
.
flushAll
();
for
(
var
uid
=
0
;
uid
+
1
<
users
.
length
;
uid
++
)
{
var
u1
=
users
[
uid
];
var
u2
=
users
[
uid
+
1
];
u1
.
db
.
requestTransaction
(
t1
);
u2
.
db
.
requestTransaction
(
t2
);
expect
(
s1
).
toEqual
(
s2
);
var
db1
=
[];
var
db2
=
[];
u1
.
db
.
os
.
iterate
(
null
,
null
,
function
(
o
){
//eslint-disable-line
db1
.
push
(
o
);
});
u2
.
db
.
os
.
iterate
(
null
,
null
,
function
(
o
){
//eslint-disable-line
db2
.
push
(
o
);
});
for
(
var
key
in
db1
)
{
expect
(
db1
[
key
]).
toEqual
(
db2
[
key
]);
}
}
}
describe
(
"
Yjs
"
,
function
(){
describe
(
"
Map Type
"
,
function
(){
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
3000
;
beforeEach
(
function
(
done
){
if
(
this
.
users
!=
null
)
{
for
(
var
y
of
this
.
users
)
{
y
.
destroy
();
}
}
this
.
users
=
[];
var
promises
=
[];
for
(
var
i
=
0
;
i
<
5
;
i
++
)
{
promises
.
push
(
Y
({
db
:
{
name
:
"
Memory
"
},
connector
:
{
name
:
"
Test
"
,
debug
:
false
}
}));
}
Promise
.
all
(
promises
).
then
(
users
=>
{
this
.
users
=
users
;
done
();
});
createUsers
(
this
,
5
,
done
);
});
describe
(
"
Basic tests
"
,
function
(){
...
...
@@ -182,30 +94,8 @@ describe("Yjs", function(){
done
();
},
50
);
});
it
(
"
Basic insert 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
;
y
.
connector
.
flushAll
();
l1
.
insert
(
0
,
[
0
]);
return
this
.
users
[
1
].
root
.
get
(
"
Array
"
);
}).
then
((
array
)
=>
{
l2
=
array
;
l2
.
insert
(
0
,
[
1
]);
return
this
.
users
[
2
].
root
.
get
(
"
Array
"
);
}).
then
((
array
)
=>
{
l3
=
array
;
l3
.
insert
(
0
,
[
2
]);
y
.
connector
.
flushAll
();
expect
(
l1
.
toArray
()).
toEqual
(
l2
.
toArray
());
expect
(
l2
.
toArray
()).
toEqual
(
l3
.
toArray
());
compareAllUsers
(
this
.
users
);
done
();
});
});
});
describe
(
"
Map r
andom tests
"
,
function
(){
describe
(
"
R
andom tests
"
,
function
(){
var
randomMapTransactions
=
[
function
set
(
map
)
{
map
.
set
(
"
somekey
"
,
getRandomNumber
());
...
...
@@ -252,53 +142,4 @@ describe("Yjs", function(){
},
500
);
});
});
var
numberOfYArrayTests
=
10
;
describe
(
"
Array random tests
"
,
function
(){
var
randomMapTransactions
=
[
function
insert
(
array
)
{
array
.
insert
(
getRandomNumber
(
array
.
toArray
().
length
),
[
getRandomNumber
()]);
}
];
function
compareArrayValues
(
arrays
){
var
firstArray
;
for
(
var
l
of
arrays
)
{
var
val
=
l
.
toArray
();
if
(
firstArray
==
null
)
{
firstArray
=
val
;
}
else
{
expect
(
val
).
toEqual
(
firstArray
);
}
}
}
beforeEach
(
function
(
done
){
this
.
users
[
0
].
root
.
set
(
"
Array
"
,
Y
.
Array
);
this
.
users
[
0
].
connector
.
flushAll
();
var
then
=
Promise
.
resolve
();
var
arrays
=
[];
for
(
var
u
of
this
.
users
)
{
then
=
then
.
then
(
function
(){
//eslint-disable-line
return
u
.
root
.
get
(
"
Array
"
);
}).
then
(
function
(
array
){
//eslint-disable-line
arrays
.
push
(
array
);
});
}
this
.
arrays
=
arrays
;
then
.
then
(
function
(){
done
();
});
});
it
(
"
arrays.length equals users.length
"
,
function
(){
expect
(
this
.
arrays
.
length
).
toEqual
(
this
.
users
.
length
);
});
it
(
`succeed after
${
numberOfYArrayTests
}
actions`
,
function
(
done
){
applyRandomTransactions
(
this
.
users
,
this
.
arrays
,
randomMapTransactions
,
numberOfYArrayTests
);
setTimeout
(()
=>
{
compareAllUsers
(
this
.
users
);
compareArrayValues
(
this
.
arrays
);
done
();
},
500
);
});
});
});
This diff is collapsed.
Click to expand it.
src/helper.spec.js
0 → 100644
+
99
−
0
View file @
66a7d272
/* @flow */
/*eslint-env browser,jasmine */
/***
This is "just" a compilation of functions that help to test this library!
***/
// returns a random element of o
// works on Object, and Array
function
getRandom
(
o
)
{
if
(
o
instanceof
Array
)
{
return
o
[
Math
.
floor
(
Math
.
random
()
*
o
.
length
)];
}
else
if
(
o
.
constructor
===
Object
)
{
var
ks
=
[];
for
(
var
key
in
o
)
{
ks
.
push
(
key
);
}
return
o
[
getRandom
(
ks
)];
}
}
function
getRandomNumber
(
n
)
{
//eslint-disable-line
if
(
n
==
null
)
{
n
=
9999
;
}
return
Math
.
floor
(
Math
.
random
()
*
n
);
}
function
applyRandomTransactions
(
users
,
objects
,
transactions
,
numberOfTransactions
)
{
//eslint-disable-line
function
randomTransaction
(
root
)
{
var
f
=
getRandom
(
transactions
);
f
(
root
);
}
for
(
var
i
=
0
;
i
<
numberOfTransactions
;
i
++
)
{
var
r
=
Math
.
random
();
if
(
r
>=
0.9
)
{
// 10% chance to flush
users
[
0
].
connector
.
flushOne
();
}
else
{
randomTransaction
(
getRandom
(
objects
));
}
}
}
function
compareAllUsers
(
users
){
//eslint-disable-line
var
s1
,
s2
;
function
*
t1
(){
s1
=
yield
*
this
.
getStateSet
();
}
function
*
t2
(){
s2
=
yield
*
this
.
getStateSet
();
}
users
[
0
].
connector
.
flushAll
();
for
(
var
uid
=
0
;
uid
+
1
<
users
.
length
;
uid
++
)
{
var
u1
=
users
[
uid
];
var
u2
=
users
[
uid
+
1
];
u1
.
db
.
requestTransaction
(
t1
);
u2
.
db
.
requestTransaction
(
t2
);
expect
(
s1
).
toEqual
(
s2
);
var
db1
=
[];
var
db2
=
[];
u1
.
db
.
os
.
iterate
(
null
,
null
,
function
(
o
){
//eslint-disable-line
db1
.
push
(
o
);
});
u2
.
db
.
os
.
iterate
(
null
,
null
,
function
(
o
){
//eslint-disable-line
db2
.
push
(
o
);
});
for
(
var
key
in
db1
)
{
expect
(
db1
[
key
]).
toEqual
(
db2
[
key
]);
}
}
}
function
createUsers
(
self
,
numberOfUsers
,
done
)
{
//eslint-disable-line
if
(
self
.
users
!=
null
)
{
for
(
var
y
of
self
.
users
)
{
y
.
destroy
();
}
}
self
.
users
=
[];
var
promises
=
[];
for
(
var
i
=
0
;
i
<
numberOfUsers
;
i
++
)
{
promises
.
push
(
Y
({
db
:
{
name
:
"
Memory
"
},
connector
:
{
name
:
"
Test
"
,
debug
:
false
}
}));
}
Promise
.
all
(
promises
).
then
(
users
=>
{
self
.
users
=
users
;
done
();
});
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment