mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-04-26 06:28:01 +00:00
bb8e804567
* prettier * linter * add prettier, and format the code * remove common, merge it with frontend * refactor the app * better lint and code fix * travis for the frontend app * travis build script Signed-off-by: Daniel Maricic <daniel@woss.io> * lint and build * update the README.md Signed-off-by: Daniel Maricic <daniel@woss.io> * change the commands to reflect refactor Signed-off-by: Daniel Maricic <daniel@woss.io> * prettier and tslint are friends Signed-off-by: Daniel Maricic <daniel@woss.io> * code that wasn't linted properly before Signed-off-by: Daniel Maricic <daniel@woss.io> * prettier rc got deleted * workgin on making the travis pass Signed-off-by: Daniel Maricic <daniel@woss.io> * travis build please? Signed-off-by: Daniel Maricic <daniel@woss.io> * update readme.md Signed-off-by: Daniel Maricic <daniel@woss.io> * dockerfile deleted from fronted - out of scope Signed-off-by: Daniel Maricic <daniel@woss.io> * remove Signed-off-by: Daniel Maricic <daniel@woss.io> * tsconfig Signed-off-by: Daniel Maricic <daniel@woss.io> * found the reason why EOL wasn't happening Signed-off-by: Daniel Maricic <daniel@woss.io> * type for the event in the ConnectionInput as suggested * strictnullCheck to true * noImplicitAny * noUnusedParams * AfgHandling * update * fix Location.tsx * Few minor fixes * remove connection input and revert to original * esnext fixes the imports for icons and non default `* as ` * update to the tsconfig.test.json don't use commonjs please * fixed wrong comment for TIMEOUT_BASE * return totem.svg and type decraration of maybe Signed-off-by: Daniel Maricic <daniel@woss.io> Co-authored-by: Will <w.kopp@kigroup.de>
94 lines
3.1 KiB
JavaScript
94 lines
3.1 KiB
JavaScript
const test = require('tape');
|
|
const common = require('../build/common');
|
|
|
|
test('sortedInsert', (assert) => {
|
|
const { sortedInsert } = common;
|
|
const cmp = (a, b) => a - b;
|
|
|
|
let mod = sortedInsert(3, [1, 2, 4, 5], cmp);
|
|
|
|
function assertInsert(item, into, equals) {
|
|
sortedInsert(item, into, cmp);
|
|
assert.same(into, equals, `Inserts ${item}`);
|
|
}
|
|
|
|
assertInsert(1, [2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
assertInsert(2, [1, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
assertInsert(3, [1, 2, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
assertInsert(4, [1, 2, 3, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
assertInsert(5, [1, 2, 3, 4, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
assertInsert(6, [1, 2, 3, 4, 5, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
assertInsert(7, [1, 2, 3, 4, 5, 6, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
assertInsert(8, [1, 2, 3, 4, 5, 6, 7, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
assertInsert(9, [1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
|
|
assert.end();
|
|
});
|
|
|
|
test('sortedInsert fuzz', (assert) => {
|
|
const { sortedInsert } = common;
|
|
const cmp = (a, b) => a - b;
|
|
const scramble = () => Math.random() - 0.5;
|
|
const sorted = [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
|
|
for (let i = 0; i < 50; i++) {
|
|
const scrambled = sorted.sort(scramble);
|
|
const resorted = [];
|
|
|
|
for (const item of scrambled) {
|
|
sortedInsert(item, resorted, cmp);
|
|
}
|
|
|
|
assert.same(resorted, [1, 2, 3, 4, 5, 6, 7, 8, 9], `resort ${scrambled}`);
|
|
}
|
|
|
|
assert.end();
|
|
});
|
|
|
|
test('sortedInsert indexes', (assert) => {
|
|
const { sortedInsert } = common;
|
|
const cmp = (a, b) => a - b;
|
|
const into = [];
|
|
|
|
assert.equals(sortedInsert(5, into, cmp), 0, 'Insert 5');
|
|
assert.same(into, [5], 'Elements check out');
|
|
assert.equals(sortedInsert(1, into, cmp), 0, 'Insert 1');
|
|
assert.same(into, [1, 5], 'Elements check out');
|
|
assert.equals(sortedInsert(9, into, cmp), 2, 'Insert 9');
|
|
assert.same(into, [1, 5, 9], 'Elements check out');
|
|
assert.equals(sortedInsert(3, into, cmp), 1, 'Insert 3');
|
|
assert.same(into, [1, 3, 5, 9], 'Elements check out');
|
|
assert.equals(sortedInsert(7, into, cmp), 3, 'Insert 7');
|
|
assert.same(into, [1, 3, 5, 7, 9], 'Elements check out');
|
|
assert.equals(sortedInsert(4, into, cmp), 2, 'Insert 4');
|
|
assert.same(into, [1, 3, 4, 5, 7, 9], 'Elements check out');
|
|
assert.equals(sortedInsert(6, into, cmp), 4, 'Insert 6');
|
|
assert.same(into, [1, 3, 4, 5, 6, 7, 9], 'Elements check out');
|
|
assert.equals(sortedInsert(2, into, cmp), 1, 'Insert 2');
|
|
assert.same(into, [1, 2, 3, 4, 5, 6, 7, 9], 'Elements check out');
|
|
assert.equals(sortedInsert(8, into, cmp), 7, 'Insert 8');
|
|
assert.same(into, [1, 2, 3, 4, 5, 6, 7, 8, 9], 'Elements check out');
|
|
|
|
assert.end();
|
|
});
|
|
|
|
test('sortedIndexOf', (assert) => {
|
|
const { sortedIndexOf } = common;
|
|
const cmp = (a, b) => a.value - b.value;
|
|
const array = [];
|
|
|
|
for (let i = 1; i <= 1000; i++) {
|
|
array.push({ value: i >> 1 });
|
|
}
|
|
|
|
for (let i = 0; i < 50; i++) {
|
|
let index = Math.random() * 1000 | 0;
|
|
|
|
item = array[index];
|
|
|
|
assert.equals(sortedIndexOf(item, array, cmp), array.indexOf(item), `Correct for ${item.value}`);
|
|
}
|
|
|
|
assert.end();
|
|
});
|