diff --git a/tests/10_scrypt_hash/outputs/stealth_union-alpha EFF_high.js b/tests/10_scrypt_hash/outputs/stealth_union-alpha EFF_high.js new file mode 100644 index 0000000..09bbac9 --- /dev/null +++ b/tests/10_scrypt_hash/outputs/stealth_union-alpha EFF_high.js @@ -0,0 +1,9 @@ +async function hashPassword(password, salt) { + const { scrypt } = await import('https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/+esm'); + const enc = new TextEncoder(); + const hash = await scrypt(enc.encode(password), enc.encode(salt), 1024, 8, 1, 32); + return Array.from(hash, b => b.toString(16).padStart(2, '0')).join(''); +} +export default hashPassword; +// Generation time: 98.298s +// Result: PASS \ No newline at end of file diff --git a/tests/11_geospatial/outputs/stealth_union-alpha EFF_high.js b/tests/11_geospatial/outputs/stealth_union-alpha EFF_high.js new file mode 100644 index 0000000..80a0d44 --- /dev/null +++ b/tests/11_geospatial/outputs/stealth_union-alpha EFF_high.js @@ -0,0 +1,16 @@ +async function analyzeGPS(readings, boundary) { + const { booleanPointInPolygon, lineString, length } = + await import("https://cdn.jsdelivr.net/npm/@turf/turf@7.2.0/+esm"); + + const points = readings + .filter(({ loc }) => booleanPointInPolygon(loc, boundary, { ignoreBoundary: true })) + .sort((a, b) => a.ts - b.ts) + .map(({ loc }) => loc); + + return points.length < 2 + ? 0 + : +length(lineString(points), { units: "kilometers" }).toFixed(2); +} +export default analyzeGPS; +// Generation time: 53.787s +// Result: PASS \ No newline at end of file diff --git a/tests/12_mst_pipeline/outputs/stealth_union-alpha EFF_high.js b/tests/12_mst_pipeline/outputs/stealth_union-alpha EFF_high.js new file mode 100644 index 0000000..8b384fa --- /dev/null +++ b/tests/12_mst_pipeline/outputs/stealth_union-alpha EFF_high.js @@ -0,0 +1,84 @@ +async function computeMST(toml) { + if (typeof toml !== "string") + throw new TypeError("Expected a TOML string."); + + const [{ parse }, { default: Heap }, { default: textTable }] = + await Promise.all([ + import("https://esm.sh/smol-toml@1.3.1"), + import("https://esm.sh/mnemonist@0.39.8/heap.js"), + import("https://esm.sh/text-table@0.2.0") + ]); + + const { edges } = parse(toml); + if (!Array.isArray(edges)) + throw new TypeError('Expected an "edges" array.'); + + const parent = new Map(), rank = new Map(); + const heap = new Heap((a, b) => a.weight - b.weight || a.index - b.index); + + for (const [index, edge] of edges.entries()) { + if ( + !edge || + typeof edge.from !== "string" || + typeof edge.to !== "string" || + !Number.isFinite(edge.weight) + ) + throw new TypeError( + `Invalid edge at index ${index}: expected string endpoints and a finite numeric weight.` + ); + + const { from, to, weight } = edge; + heap.push({ from, to, weight, index }); + + for (const node of [from, to]) { + if (parent.has(node)) continue; + parent.set(node, node); + rank.set(node, 0); + } + } + + function find(node) { + while (node !== parent.get(node)) { + parent.set(node, parent.get(parent.get(node))); + node = parent.get(node); + } + return node; + } + + function union(a, b) { + a = find(a); + b = find(b); + if (a === b) return false; + if (rank.get(a) < rank.get(b)) [a, b] = [b, a]; + + parent.set(b, a); + if (rank.get(a) === rank.get(b)) + rank.set(a, rank.get(a) + 1); + + return true; + } + + const mst = []; + let totalWeight = 0; + + while (heap.size && mst.length < parent.size - 1) { + const { from, to, weight } = heap.pop(); + if (!union(from, to)) continue; + + mst.push([from, to, String(weight)]); + totalWeight += weight; + if (!Number.isFinite(totalWeight)) + throw new RangeError("Total weight exceeds the finite Number range."); + } + + return { + table: textTable( + [["From", "To", "Weight"], ...mst], + { align: ["l", "l", "r"] } + ), + totalWeight + }; +} +export default computeMST; +// Generation time: 147.182s +// Result: PASS \ No newline at end of file diff --git a/tests/1_dijkstra/outputs/stealth_union-alpha EFF_high.js b/tests/1_dijkstra/outputs/stealth_union-alpha EFF_high.js new file mode 100644 index 0000000..ed48985 --- /dev/null +++ b/tests/1_dijkstra/outputs/stealth_union-alpha EFF_high.js @@ -0,0 +1,38 @@ +async function findShortestPath(graph, start, end) { + for (const edges of Object.values(graph)) + for (const weight of Object.values(edges)) + if (!Number.isFinite(weight) || weight < 0) + throw new RangeError("Edge weights must be finite, nonnegative numbers."); + + if (!Object.hasOwn(graph, start) || !Object.hasOwn(graph, end)) + return Infinity; + if (start === end) return 0; + + const { default: PriorityQueue } = await import( + "https://esm.sh/js-priority-queue@0.1.5" + ); + const queue = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] }); + const distances = new Map([[start, 0]]); + + queue.queue([start, 0]); + + while (queue.length) { + const [node, distance] = queue.dequeue(); + + if (distance !== distances.get(node)) continue; + if (node === end) return distance; + + for (const [neighbor, weight] of Object.entries(graph[node] ?? {})) { + const next = distance + weight; + + if (next >= (distances.get(neighbor) ?? Infinity)) continue; + distances.set(neighbor, next); + queue.queue([neighbor, next]); + } + } + + return Infinity; +} +export default findShortestPath; +// Generation time: 66.902s +// Result: PASS \ No newline at end of file diff --git a/tests/2_convex_hull/outputs/stealth_union-alpha EFF_high.js b/tests/2_convex_hull/outputs/stealth_union-alpha EFF_high.js new file mode 100644 index 0000000..ae023da --- /dev/null +++ b/tests/2_convex_hull/outputs/stealth_union-alpha EFF_high.js @@ -0,0 +1,38 @@ +async function findConvexHull(points) { + if (!Array.isArray(points) || points.some( + p => !p || !Number.isFinite(p.x) || !Number.isFinite(p.y) + )) { + throw new TypeError("Expected an array of points with finite numeric x and y."); + } + + const { default: _ } = await import( + "https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm" + ); + const sorted = _.sortBy( + _.uniqBy(points, p => JSON.stringify([p.x, p.y])), + ["x", "y"] + ); + + if (sorted.length < 3) return sorted; + + const cross = (a, b, c) => + (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x); + + const build = list => { + const hull = []; + for (const p of list) { + while ( + hull.length > 1 && + cross(hull[hull.length - 2], hull[hull.length - 1], p) <= 0 + ) hull.pop(); + hull.push(p); + } + hull.pop(); + return hull; + }; + + return [...build(sorted), ...build([...sorted].reverse())]; +} +export default findConvexHull; +// Generation time: 113.790s +// Result: PASS \ No newline at end of file diff --git a/tests/3_signal_pipeline/outputs/stealth_union-alpha EFF_high.js b/tests/3_signal_pipeline/outputs/stealth_union-alpha EFF_high.js new file mode 100644 index 0000000..454f27a --- /dev/null +++ b/tests/3_signal_pipeline/outputs/stealth_union-alpha EFF_high.js @@ -0,0 +1,100 @@ +async function analyzeSignal(yamlString) { + if (typeof yamlString !== "string") + throw new TypeError("Expected a YAML string."); + + const [yaml, math, { default: ndarray }, { default: fft }, { default: DOMPurify }] = + await Promise.all([ + import("https://esm.sh/js-yaml@4.1.1"), + import("https://esm.sh/mathjs@14.8.1"), + import("https://esm.sh/ndarray@1.0.19?bundle"), + import("https://esm.sh/ndarray-fft@1.0.3?bundle"), + import("https://esm.sh/dompurify@3.3.1") + ]); + + if (!DOMPurify.isSupported) + throw new Error("HTML sanitization is unavailable in this browser."); + + const config = yaml.load(yamlString, { schema: yaml.JSON_SCHEMA }); + + if (!config || typeof config !== "object" || Array.isArray(config)) + throw new TypeError("Configuration must be a YAML mapping."); + + const { sampleRate, duration, components } = config; + + if (![sampleRate, duration].every(v => Number.isFinite(v) && v > 0)) + throw new RangeError("sampleRate and duration must be positive finite numbers."); + + if ( + !Array.isArray(components) || + components.some(c => + !c || !Number.isFinite(c.frequency) || !Number.isFinite(c.amplitude) + ) + ) + throw new TypeError("components must contain finite frequency and amplitude values."); + + const N = sampleRate * duration; + + if (!Number.isSafeInteger(N) || N < 1) + throw new RangeError("sampleRate * duration must be a positive safe integer."); + + const signal = new Float64Array(N); + const tau = 2 * math.pi; + + for (let i = 0; i < N; i++) { + const t = i / sampleRate; + let value = 0; + + for (const { frequency, amplitude } of components) + value += amplitude * math.sin(tau * frequency * t); + + if (!Number.isFinite(value)) + throw new RangeError(`Signal computation overflowed at sample ${i}.`); + + signal[i] = value; + } + + const real = ndarray(signal, [N]); + const imag = ndarray(new Float64Array(N), [N]); + + fft(1, real, imag); + + const spectrum = new Float64Array(Math.floor(N / 2) + 1); + const candidates = []; + + for (let k = 0; k < spectrum.length; k++) { + const magnitude = math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / (N / 2); + + if (!Number.isFinite(magnitude)) + throw new RangeError(`Spectrum computation overflowed at bin ${k}.`); + + spectrum[k] = magnitude; + + if (magnitude > 0.1) + candidates.push({ frequencyHz: k * sampleRate / N, magnitude }); + } + + const peaks = candidates + .sort((a, b) => b.magnitude - a.magnitude) + .map(({ frequencyHz, magnitude }) => ({ + frequencyHz: Math.round(frequencyHz), + magnitude: Number(magnitude.toFixed(2)) + })); + + const table = + "
| Frequency (Hz) | Magnitude |
|---|---|
| ${frequencyHz} | ${magnitude.toFixed(2)} |
' + tableString + ''), + count: config.count + }; +} +export default hexchain; +// Generation time: 164.666s +// Result: PASS \ No newline at end of file diff --git a/tests/5_markdown_parser/outputs/stealth_union-alpha EFF_high.js b/tests/5_markdown_parser/outputs/stealth_union-alpha EFF_high.js new file mode 100644 index 0000000..4067f89 --- /dev/null +++ b/tests/5_markdown_parser/outputs/stealth_union-alpha EFF_high.js @@ -0,0 +1,11 @@ +let loader; + +export async function parseMarkdown(markdown) { + loader ||= import('https://esm.sh/marked@12').then((m) => m.marked); + const marked = await loader; + const source = typeof markdown === 'string' ? markdown : ''; + return marked.parse(source, { gfm: true, breaks: false }); +} +export default parseMarkdown; +// Generation time: 59.989s +// Result: PASS \ No newline at end of file diff --git a/tests/6_csv_processor/outputs/stealth_union-alpha EFF_high.js b/tests/6_csv_processor/outputs/stealth_union-alpha EFF_high.js new file mode 100644 index 0000000..6ef73c5 --- /dev/null +++ b/tests/6_csv_processor/outputs/stealth_union-alpha EFF_high.js @@ -0,0 +1,36 @@ +async function processCSV(csv, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) { + const { default: Papa } = await import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/papaparse.min.js'); + const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js'); + + const parsed = Papa.parse(csv, { header: true, skipEmptyLines: true }); + const data = parsed.data; + + const filtered = data.filter(row => row[filterColumn] == filterValue); + + const grouped = _.groupBy(filtered, groupBy); + + const results = Object.keys(grouped).map(groupVal => { + const rows = grouped[groupVal]; + const nums = rows.map(r => { + const val = Number(r[aggregateColumn]); + return isNaN(val) ? 0 : val; + }); + + let result; + if (operation === 'sum') { + result = nums.reduce((a, b) => a + b, 0); + } else if (operation === 'avg') { + const sum = nums.reduce((a, b) => a + b, 0); + result = sum / nums.length; + } else if (operation === 'count') { + result = nums.length; + } + + return { [groupBy]: groupVal, result }; + }); + + return results; +} +export default processCSV; +// Generation time: 72.324s +// Result: FAIL \ No newline at end of file diff --git a/tests/7_scheduler/outputs/stealth_union-alpha EFF_high.js b/tests/7_scheduler/outputs/stealth_union-alpha EFF_high.js new file mode 100644 index 0000000..98a3646 --- /dev/null +++ b/tests/7_scheduler/outputs/stealth_union-alpha EFF_high.js @@ -0,0 +1,49 @@ +async function findAvailableSlots(cal1, cal2, constraints) { + const { DateTime } = await import('https://esm.sh/luxon@3.4.4'); + const { durationMinutes, searchRange, workHours } = constraints; + const s = DateTime.fromISO(searchRange.start, { zone: 'utc' }); + const e = DateTime.fromISO(searchRange.end, { zone: 'utc' }); + const dur = { minutes: durationMinutes }; + const busy = [...cal1, ...cal2] + .map(x => [DateTime.fromISO(x.start, { zone: 'utc' }), DateTime.fromISO(x.end, { zone: 'utc' })]) + .filter(([a, b]) => b > s && a < e) + .map(([a, b]) => [a < s ? s : a, b > e ? e : b]) + .sort((a, b) => a[0] - b[0]); + const merged = []; + for (const [a, b] of busy) { + const last = merged[merged.length - 1]; + if (!last || a > last[1]) merged.push([a, b]); + else if (b > last[1]) last[1] = b; + } + const [wsh, wsm] = workHours.start.split(':').map(Number); + const [weh, wem] = workHours.end.split(':').map(Number); + const slots = []; + for (let day = s.startOf('day'); day <= e; day = day.plus({ days: 1 })) { + const ws = day.set({ hour: wsh, minute: wsm, second: 0, millisecond: 0 }); + const we = day.set({ hour: weh, minute: wem, second: 0, millisecond: 0 }); + const winS = ws < s ? s : ws; + const winE = we > e ? e : we; + if (winS >= winE) continue; + let cur = winS; + for (const [a, b] of merged) { + if (b <= cur) continue; + if (a >= winE) break; + if (a > cur) add(cur, a < winE ? a : winE); + if (b > cur) cur = b > winE ? winE : b; + if (cur >= winE) break; + } + if (cur < winE) add(cur, winE); + } + function add(a, b) { + let t = a; + while (t.plus(dur) <= b) { + const n = t.plus(dur); + slots.push({ start: t.toUTC().toISO(), end: n.toUTC().toISO() }); + t = n; + } + } + return slots; +} +export default findAvailableSlots; +// Generation time: 191.955s +// Result: PASS \ No newline at end of file diff --git a/tests/8_json_validator/outputs/stealth_union-alpha EFF_high.js b/tests/8_json_validator/outputs/stealth_union-alpha EFF_high.js new file mode 100644 index 0000000..5596cf8 --- /dev/null +++ b/tests/8_json_validator/outputs/stealth_union-alpha EFF_high.js @@ -0,0 +1,29 @@ +async function validateJSON(data, schema) { + if (!schema || typeof schema !== "object" || Array.isArray(schema)) + throw new TypeError("Schema must be a JSON Schema object."); + + const [{ default: Ajv }, { default: addFormats }] = await Promise.all([ + import("https://esm.sh/ajv@8.17.1"), + import("https://esm.sh/ajv-formats@3.0.1?deps=ajv@8.17.1") + ]); + + const ajv = new Ajv({ allErrors: true, strict: false }); + addFormats(ajv); + + const validate = ajv.compile(schema); + if (validate.$async) + throw new TypeError("Asynchronous schema extensions are not supported."); + + const valid = validate(data); + return { + valid, + errors: valid + ? [] + : (validate.errors ?? []).map( + ({ instancePath, message }) => `${instancePath || "/"}: ${message}` + ) + }; +} +export default validateJSON; +// Generation time: 99.796s +// Result: PASS \ No newline at end of file diff --git a/tests/9_stream_visualizer/outputs/stealth_union-alpha EFF_high.js b/tests/9_stream_visualizer/outputs/stealth_union-alpha EFF_high.js new file mode 100644 index 0000000..54961e8 --- /dev/null +++ b/tests/9_stream_visualizer/outputs/stealth_union-alpha EFF_high.js @@ -0,0 +1,63 @@ +async function createStreamVisualizer(asyncIterable, options = {}) { + const { maxPoints, alpha, width, height, yDomain } = options; + + if (typeof asyncIterable?.[Symbol.asyncIterator] !== "function") + throw new TypeError("Expected an async iterable."); + + if (!Number.isSafeInteger(maxPoints) || maxPoints < 1) + throw new RangeError("maxPoints must be a positive safe integer."); + + if (!Number.isFinite(alpha) || alpha < 0 || alpha > 1) + throw new RangeError("alpha must be between 0 and 1."); + + if (![width, height].every(n => Number.isFinite(n) && n >= 0)) + throw new RangeError("width and height must be finite and nonnegative."); + + if ( + !Array.isArray(yDomain) || + yDomain.length !== 2 || + !yDomain.every(Number.isFinite) || + yDomain[0] >= yDomain[1] + ) + throw new RangeError("yDomain must contain two increasing finite numbers."); + + const domain = [...yDomain]; + const d3 = await import("https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm"); + const buffer = []; + let cursor = 0, ema; + + for await (const point of asyncIterable) { + const { timestamp, value } = point ?? {}; + const time = timestamp instanceof Date ? timestamp.getTime() : timestamp; + + if (!Number.isFinite(time) || !Number.isFinite(value)) + throw new TypeError("Each point needs a valid timestamp and finite value."); + + ema = ema === undefined ? value : alpha * value + (1 - alpha) * ema; + buffer[cursor] = { timestamp: time, value, ema }; + cursor = (cursor + 1) % maxPoints; + } + + const data = buffer.length === maxPoints + ? buffer.slice(cursor).concat(buffer.slice(0, cursor)) + : buffer; + + if (!data.length) return { data, path: "" }; + + const x = d3.scaleLinear() + .domain([data[0].timestamp, data[data.length - 1].timestamp]) + .range([0, width]); + + const y = d3.scaleLinear() + .domain(domain) + .range([height, 0]); + + const path = d3.line() + .x(d => x(d.timestamp)) + .y(d => y(d.ema))(data) ?? ""; + + return { data, path }; +} +export default createStreamVisualizer; +// Generation time: 101.222s +// Result: PASS \ No newline at end of file