Skip to content

Commit

Permalink
Fix test:dos
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Jan 14, 2025
1 parent 2dd1f53 commit 5f27e7c
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync } from 'node:fs';
import { gunzipSync } from 'node:zlib';
import { dirname, join as joinPath } from 'node:path';
import { pathToFileURL, fileURLToPath } from 'node:url';
import { fileURLToPath } from 'node:url';

export const _dirname = dirname(fileURLToPath(import.meta.url));

Expand All @@ -22,6 +22,37 @@ export function json(path) {
}
}

function median(list) {
const values = list.slice().sort((a, b) => a - b);
const half = (values.length / 2) | 0;
return values.length % 2 ? values[half] : (values[half - 1] + values[half]) / 2.0;
}
export function stats(list) {
let [min, max, cnt, sum, absSum] = [+Infinity, -Infinity, 0, 0, 0];
for (let value of list) {
const num = Number(value);
min = Math.min(min, num);
max = Math.max(max, num);
cnt++;
sum += num;
absSum += Math.abs(num);
}
const sumDiffPercent = (absSum / sum) * 100;
const difference = [];
for (let i = 1; i < list.length; i++) difference.push(list[i] - list[i - 1]);
return {
min,
max,
avg: sum / cnt,
sum,
median: median(list),
absSum,
cnt,
sumDiffPercent,
difference,
};
}

// Everything except undefined, string, Uint8Array
const TYPE_TEST_BASE = [
null,
Expand Down

0 comments on commit 5f27e7c

Please sign in to comment.