Skip to content

Commit 4f5c59f

Browse files
committed
noHandledMp check
1 parent e1765dd commit 4f5c59f

4 files changed

Lines changed: 71 additions & 7 deletions

File tree

check.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,29 @@ export const check = async (hash: { [name:string]: number }, type_id: number) =>
103103
return { nodes, mp };
104104
};
105105

106-
export const checkManual = async (links: [number, number, number, number, [number, number][]][], type_id: number, GRAPH_TABLE: string, MP_TABLE: string) => {
106+
export const checkManual = async (input: [number, number, number, number, [number, number][]][], type_id: number, GRAPH_TABLE: string, MP_TABLE: string) => {
107107
const { nodes, mp } = await fetch(type_id, ID_TYPE, GRAPH_TABLE, MP_TABLE);
108108

109109
const ns = [];
110110
const ls = [];
111+
const handledMP = {};
111112

112113
for (let i = 0; i < nodes.length; i++) {
113114
const n = nodes[i];
114-
const l = links[i];
115-
ns.push({ id: n.id, from_id: n.from_id || 0, to_id: n.to_id || 0, type_id: n.type_id || 0, _by_item: mp.filter(mp => mp.item_id === n.id).map(a => ({ root_id: a.root_id, path_item_id: a.path_item_id })) });
116-
ls.push({ id: l[0], from_id: l[1], to_id: l[2], type_id: l[3], _by_item: l[4].map(a => ({ root_id: a[0], path_item_id: a[1] })) });
115+
const l = input[i];
116+
ns.push({ id: n.id, from_id: n.from_id || 0, to_id: n.to_id || 0, type_id: n.type_id || 0, _by_item: mp.filter((mp) => {
117+
handledMP[mp.id] = true;
118+
return mp.item_id === n.id;
119+
}).map(a => ({ root_id: a.root_id, path_item_id: a.path_item_id })) });
120+
ls.push({ id: l[0], from_id: l[1], to_id: l[2], type_id: l[3], _by_item: l[4].map((a) => {
121+
return { root_id: a[0], path_item_id: a[1] };
122+
}) });
117123
}
118124
assert.deepStrictEqual(ns, ls);
125+
const notHandledMp = [];
126+
for (let i = 0; i < mp.length; i++) {
127+
const mark = mp[i];
128+
if (!handledMP[mark.id]) notHandledMp[mark.id];
129+
}
130+
if (notHandledMp.length) throw new Error(`Not handled MP marks: ${notHandledMp}`);
119131
}

imports/multidirectional.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,51 @@ export const testRecursiveSameRoot = (needCheck = true) => async () => {
188188
}
189189
if (!errored) throw new Error('Recursion error not exists');
190190
};
191+
export const testSeparation1 = (needCheck = true) => async () => {
192+
debug('testSeparation1');
193+
await clear(type_id);
194+
const a = await insertNode(type_id, 'node');
195+
const b = await insertNode(type_id, 'node');
196+
const c = await insertNode(type_id, 'node');
197+
const d = await insertNode(type_id, 'node');
198+
const e = await insertNode(type_id, 'node');
199+
const x = await insertLink(a, b, type_id, 'down');
200+
const y = await insertLink(b, c, type_id, 'down');
201+
const z = await insertLink(c, d, type_id, 'down');
202+
const w = await insertLink(d, e, type_id, 'down');
203+
if (needCheck) await checkManual([
204+
[a,0,0,type_id,[[a,a]]],
205+
[b,0,0,type_id,[[a,a],[a,x],[a,b]]],
206+
[c,0,0,type_id,[[a,a],[a,x],[a,b],[a,y],[a,c]]],
207+
[d,0,0,type_id,[[a,a],[a,x],[a,b],[a,y],[a,c],[a,z],[a,d]]],
208+
[e,0,0,type_id,[[a,a],[a,x],[a,b],[a,y],[a,c],[a,z],[a,d],[a,w],[a,e]]],
209+
[x,a,b,type_id,[[a,a],[a,x]]],
210+
[y,b,c,type_id,[[a,a],[a,x],[a,b],[a,y]]],
211+
[z,c,d,type_id,[[a,a],[a,x],[a,b],[a,y],[a,c],[a,z]]],
212+
[w,d,e,type_id,[[a,a],[a,x],[a,b],[a,y],[a,c],[a,z],[a,d],[a,w]]],
213+
], type_id, GRAPH_TABLE, MP_TABLE);
214+
};
215+
export const testSeparation2 = (needCheck = true) => async () => {
216+
debug('testSeparation2');
217+
await clear(type_id);
218+
const a = await insertNode(type_id, 'node');
219+
const b = await insertNode(type_id, 'node');
220+
const c = await insertNode(type_id, 'node'); // -
221+
const d = await insertNode(type_id, 'node'); // |
222+
const e = await insertNode(type_id, 'node'); // |
223+
const x = await insertLink(a, b, type_id, 'down');
224+
const y = await insertLink(b, c, type_id, 'down'); // -
225+
const z = await insertLink(c, d, type_id, 'down'); // |
226+
const w = await insertLink(d, e, type_id, 'down'); // |
227+
await deleteNode(y); // -
228+
if (needCheck) await checkManual([
229+
[a,0,0,type_id,[[a,a]]],
230+
[b,0,0,type_id,[[a,a],[a,x],[a,b]]],
231+
[c,0,0,type_id,[[c,c]]],
232+
[d,0,0,type_id,[[c,c],[c,z],[c,d]]],
233+
[e,0,0,type_id,[[c,c],[c,z],[c,d],[c,w],[c,e]]],
234+
[x,a,b,type_id,[[a,a],[a,x]]],
235+
[z,c,d,type_id,[[c,c],[c,z]]],
236+
[w,d,e,type_id,[[c,c],[c,z],[c,d],[c,w]]],
237+
], type_id, GRAPH_TABLE, MP_TABLE);
238+
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
"package:build": "npx tsc --project tsconfig.json && (cd ./migrations && rm -f ./*.js; rm -f ./*.js.map; rm -f ./*.d.ts)",
2626
"package:unbuild": "rm -f ./*.js; rm -f ./*.js.map; rm -f ./*.d.ts && (cd ./migrations && rm -f ./*.js; rm -f ./*.js.map; rm -f ./*.d.ts) && (cd ./tests && rm -f ./*.js; rm -f ./*.js.map; rm -f ./*.d.ts)",
2727
"package:publish": "npm run package:build; npm publish --access public; npm run package:unbuild",
28-
"test": "export HASURA_PATH=localhost:8080; export HASURA_SSL=0; export HASURA_SECRET=myadminsecretkey; DEBUG='deepcase:*' jest",
28+
"test": "export HASURA_PATH=localhost:8080; export HASURA_SSL=0; export HASURA_SECRET=myadminsecretkey; DEBUG='materialized-path:*' jest",
2929
"migrate": "export MIGRATIONS_HASURA_PATH=localhost:8080; export MIGRATIONS_HASURA_SSL=0; export MIGRATIONS_HASURA_SECRET=myadminsecretkey; export $(grep -v '^#' .env | xargs); yes | DEBUG='deepcase:*' npx migrate up --compiler='ts:@deep-foundation/hasura/compiler/index.js'",
3030
"unmigrate": "export MIGRATIONS_HASURA_PATH=localhost:8080; export MIGRATIONS_HASURA_SSL=0; export MIGRATIONS_HASURA_SECRET=myadminsecretkey; export $(grep -v '^#' .env | xargs); yes | DEBUG='deepcase:*' npx migrate down --compiler='ts:@deep-foundation/hasura/compiler/index.js'",
3131
"hasura": "(cd node_modules/@deep-foundation/hasura; npm run docker)",
3232
"clear": "(killall screen; rm -rf .migrate; cd node_modules/@deep-foundation/hasura/local/; docker-compose down; docker rm -f $(docker ps -a -q); docker volume rm $(docker volume ls -q))",
33-
"benchmark": "export HASURA_PATH=localhost:8080; export HASURA_SSL=0; export HASURA_SECRET=myadminsecretkey; DEBUG='deepcase:*' ts-node benchmarks/index.ts"
33+
"benchmark": "export HASURA_PATH=localhost:8080; export HASURA_SSL=0; export HASURA_SECRET=myadminsecretkey; DEBUG='materialized-path:*' ts-node benchmarks/index.ts"
3434
},
3535
"devDependencies": {
3636
"@deep-foundation/hasura": "^0.0.3",

tests/multidirectional.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Chance from 'chance';
66
import { check, checkManual } from '../check';
77
import { client } from '../client';
88
import fs from 'fs';
9-
import { beforeAllHandler, prepare, testMinus15, testPlus15, testRecursive, testRecursiveSameRoot } from '../imports/multidirectional';
9+
import { beforeAllHandler, prepare, testMinus15, testPlus15, testRecursive, testRecursiveSameRoot, testSeparation1, testSeparation2 } from '../imports/multidirectional';
1010

1111
const chance = new Chance();
1212
const debug = Debug('materialized-path:test');
@@ -36,3 +36,7 @@ itDelay();
3636
it('recursive', testRecursive(true));
3737
itDelay();
3838
it('recursiveSameRoot', testRecursiveSameRoot(true));
39+
itDelay();
40+
it('testSeparation1', testSeparation1(true));
41+
itDelay();
42+
it('testSeparation2', testSeparation2(true));

0 commit comments

Comments
 (0)