Skip to content

Commit

Permalink
Add complexity tests.
Browse files Browse the repository at this point in the history
- Add large graph creation utilities.
- Add timeout test.
- Add maxDeepIteration test.
- Add developer playground for large graph tests.
  • Loading branch information
davidlehn committed Aug 26, 2023
1 parent 6690a9d commit f52439f
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/graphs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Test graphs.
*/
// N subjects, N objects, fully connected S->O, no self refs
exports.makeDataA = function makeDataA({subjects, objects}) {
let n = 0;
let nq = '';
for(let subject = 0; subject < subjects; ++subject) {
for(let object = 0; object < objects; ++object) {
if(subject !== object) {
n++;
nq += `_:s_${subject} <ex:p> _:o_${object} .\n`;
}
}
}
return {n, data: nq};
};

// N subjects, fully connected, with self refs
exports.makeDataB = function makeDataB({subjects}) {
let n = 0;
let nq = '';
for(let subject = 0; subject < subjects; ++subject) {
for(let object = 0; object < subjects; ++object) {
n++;
nq += `_:s_${subject} <ex:p> _:s_${object} .\n`;
}
}
return {n, data: nq};
};

// NN style, N levels of blank nodes, each level fully connected to next
exports.makeDataC = function makeDataC({counts}) {
if(counts.length < 2) {
throw new Error('Need more counts');
}
let n = 0;
let nq = '';
for(let level = 0; level < counts.length; ++level) {
if((level + 1) < counts.length) {
for(let cur = 0; cur < counts[level]; ++cur) {
for(let next = 0; next < counts[level + 1]; ++next) {
n++;
nq += `_:s_${level}_${cur} <ex:p> _:s_${level + 1}_${next} .\n`;
}
}
}
}
return {n, data: nq};
};
83 changes: 83 additions & 0 deletions test/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// disable so tests can be copy & pasted
/* eslint-disable quotes, quote-props */
const assert = require('assert');
const graphs = require('./graphs.js');
const rdfCanonize = require('..');

describe('API tests', () => {
Expand Down Expand Up @@ -80,4 +81,86 @@ _:c14n1 <urn:p1> "v1" .
}
assert(error);
});

it('should abort (timeout)', async () => {
const {data} = graphs.makeDataC({
counts: [10, 10, 10]
});
let error;
let output;
try {
output = await rdfCanonize.canonize(data, {
algorithm: 'RDFC-1.0',
inputFormat: 'application/n-quads',
format: 'application/n-quads',
signal: AbortSignal.timeout(100),
maxDeepIterations: Infinity
});
} catch(e) {
error = e;
}
assert(error, 'no abort error');
assert(!output, 'abort should have no output');
});

it('should abort (iterations)', async () => {
const {data} = graphs.makeDataA({
subjects: 6,
objects: 6
});
let error;
let output;
try {
output = await rdfCanonize.canonize(data, {
algorithm: 'RDFC-1.0',
inputFormat: 'application/n-quads',
format: 'application/n-quads',
signal: null,
maxDeepIterations: 1000
});
} catch(e) {
error = e;
}
assert(error, 'no abort error');
assert(!output, 'abort should have no output');
});

/*
it.only('should abort (playground)', async () => {
//const {data, n} = graphs.makeDataA({
// subjects: 6,
// objects: 6
//});
//const {data, n} = graphs.makeDataB({
// subjects: 6
//});
const {data, n} = graphs.makeDataC({
counts: [10, 10, 10]
});
console.log('INPUT', data);
console.log('INPUTN', n);
console.log('INPUTSIZE', data.length);
let error;
let output;
const start = performance.now();
try {
const p = rdfCanonize.canonize(data, {
algorithm: 'RDFC-1.0',
inputFormat: 'application/n-quads',
format: 'application/n-quads',
signal: AbortSignal.timeout(100),
maxDeepIterations: 1000
});
output = await p;
//console.log('OUTPUT', output);
} catch(e) {
console.log('ERROR', e);
error = e;
}
const dt = performance.now() - start;
console.log('DT(ms)', dt);
assert(error, 'no abort error');
assert(!output, 'abort should have no output');
});
*/
});

0 comments on commit f52439f

Please sign in to comment.