-
Notifications
You must be signed in to change notification settings - Fork 664
/
Copy pathtest321.js
162 lines (134 loc) · 4.12 KB
/
test321.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
} else {
__dirname = '.';
}
describe('Test 321 CREATE GRAPH', function () {
var gdata, vv;
it('1. READ DATA', function (done) {
alasql.options.modifier = undefined;
alasql(
'SELECT * FROM CSV("' + __dirname + '/test321a.csv",{headers:true})',
[],
function (data) {
gdata = data;
// Select unique
vv = alasql('SEARCH DISTINCT(UNION ALL(/[source],/[target])) FROM ?', [gdata]);
done();
}
);
});
it('2. CREATE DATABASE A', function (done) {
alasql('CREATE DATABASE test321a; USE test321a');
done();
});
it('3. CREATE GRAPH vertices', function (done) {
alasql(
'CREATE GRAPH ' +
vv.map(function (v) {
return '"' + v + '"';
})
);
done();
});
it('4. CREATE GRAPH edges', function (done) {
var res = alasql(
'CREATE GRAPH ' +
gdata.map(function (e) {
return '"' + e.source + '" > {[value]:' + e.value + '} > "' + e.target + '"';
})
);
done();
});
it('5. CREATE GRAPH', function (done) {
var res = alasql('SEARCH / "Harry" PATH("Roger") name');
assert.deepEqual(res, ['Mario', 'Alice', 'Sarah', 'James', 'Roger']);
var res = alasql('SEARCH / "Johan" PATH("Carol") name');
assert.deepEqual(res, ['Peter', 'Alice', 'Eveie', 'Harry', 'Carol']);
done();
});
it('6. DROP DATABASE', function (done) {
alasql('DROP DATABASE test321a');
done();
});
it('7. CREATE DATABASE A', function (done) {
alasql('CREATE DATABASE test321b; USE test321b');
done();
});
it('8. CREATE GRAPH edges', function (done) {
var res = alasql(
'CREATE GRAPH ' +
gdata.map(function (e) {
return '"' + e.source + '" > {[value]:' + e.value + '} > "' + e.target + '"';
})
);
done();
});
it('9. CREATE GRAPH', function (done) {
var res = alasql('SEARCH / "Harry" PATH("Roger") name');
assert.deepEqual(res, ['Mario', 'Alice', 'Sarah', 'James', 'Roger']);
var res = alasql('SEARCH / "Johan" PATH("Carol") name');
assert.deepEqual(res, ['Peter', 'Alice', 'Eveie', 'Harry', 'Carol']);
done();
});
it('10. DROP DATABASE', function (done) {
alasql('DROP DATABASE test321b');
done();
});
it('11. CREATE DATABASE C', function (done) {
alasql('CREATE DATABASE test321c; USE test321c');
done();
});
it('12. CREATE GRAPH edges', function (done) {
var res = alasql(
'CREATE GRAPH ' +
gdata.map(function (e) {
return e.source + ' > loves {[value]:' + e.value + '} > ' + e.target;
})
);
done();
});
it('13. CREATE GRAPH', function (done) {
var res = alasql('SEARCH / "Harry" PATH("Roger") VERTEX name');
assert.deepEqual(res, ['Mario', 'Alice', 'Sarah', 'James', 'Roger']);
var res = alasql('SEARCH / "Johan" PATH("Carol") VERTEX name');
assert.deepEqual(res, ['Peter', 'Alice', 'Eveie', 'Harry', 'Carol']);
done();
});
it('14. DROP DATABASE', function (done) {
alasql('DROP DATABASE test321c');
done();
});
it('15. CREATE DATABASE D', function (done) {
alasql('CREATE DATABASE test321d; USE test321d');
done();
});
it('16. Simple create graph', function (done) {
alasql('CREATE GRAPH Olga > loves > Michael, Michael > loves > Julia');
var res = alasql('SEARCH / "Julia" (<<)* name');
assert.deepEqual(res, ['Julia', 'Michael', 'Olga']);
var res = alasql('SEARCH / EDGE "loves" < name');
assert.deepEqual(res, ['Olga', 'Michael']);
var res = alasql('SEARCH / EDGE "loves" > name');
assert.deepEqual(res, ['Michael', 'Julia']);
var res = alasql('SEARCH / "Olga" PATH("Julia") VERTEX name');
assert.deepEqual(res, ['Michael', 'Julia']);
var res = alasql('SEARCH / "Olga" PATH("Julia") EDGE name');
assert.deepEqual(res, ['loves', 'loves']);
//console.log(res);
done();
});
it('17. Simple create graph', function (done) {
alasql('CREATE GRAPH Serge >> Helen, Helen > hates > Peter');
var res = alasql('SEARCH / "Serge" PATH("Peter") EDGE name');
assert.deepEqual(res, ['hates']);
var res = alasql('SEARCH / "Serge" PATH("Peter") EDGE ->name');
assert.deepEqual(res, [undefined, 'hates']);
done();
});
it('18. DROP DATABASE', function (done) {
alasql('DROP DATABASE test321d');
done();
});
});