-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ts
More file actions
49 lines (40 loc) · 1.52 KB
/
test.ts
File metadata and controls
49 lines (40 loc) · 1.52 KB
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
import * as fs from 'fs';
import TestsGenerator, { TestsAndResults } from './tools/testsGenerator';
import TestWith from './tools/testSortModule';
import testConfig from './testconfig';
import createTableMD from './tools/createTableMD';
import createTableHTML from './tools/createTableHTML';
import { TestResults } from './tools/runSortModuleInThread';
export type Result = { [key: string]: { [key: string]: TestResults } };
async function main(argv = process.argv) {
const dir = './sorts/',
whiteList = argv.slice(2);
let cd = fs.readdirSync(dir).filter((f) => f[0] != '.');
if (whiteList.length) {
cd = cd.filter((f) => whiteList.some((str) => f.indexOf(str) == 0));
}
const testSets: { [key: string]: TestsAndResults } = {};
for (const key in testConfig) {
testSets[key] = TestsGenerator(testConfig[key]);
}
const results = {} as any;
for (const set in testSets) {
const testSet = testSets[set];
results[set] = {};
for (const sortFile of cd) {
const sortPath = '../sorts/' + sortFile,
sortName = sortFile.split('.')[0];
const res = await TestWith(sortPath, testSet, { timeout: 15_000 });
if (res.status === 'error') {
throw new Error('Wrong result with ' + sortName);
}
res.time = Math.round(res.time * 1e7) / 1e7;
results[set][sortName] = res;
}
console.log(set);
console.table(results[set]);
}
fs.writeFileSync('./test_results.md', createTableMD(results));
fs.writeFileSync('./test_results.html', createTableHTML(results));
}
main();