diff --git a/tests/10_scrypt_hash/outputs/z-ai_glm-5.1.js b/tests/10_scrypt_hash/outputs/z-ai_glm-5.1.js new file mode 100644 index 0000000..b9bdaf3 --- /dev/null +++ b/tests/10_scrypt_hash/outputs/z-ai_glm-5.1.js @@ -0,0 +1,9 @@ +async function hashPassword(password, salt) { + const { scrypt } = await import('https://esm.sh/scrypt-js') + const e = new TextEncoder() + const h = await scrypt(e.encode(password), e.encode(salt), 1024, 8, 1, 32) + return [...h].map(b => b.toString(16).padStart(2, '0')).join('') +} +export default hashPassword; +// Generation time: 33.046s +// Result: PASS \ No newline at end of file diff --git a/tests/11_geospatial/outputs/z-ai_glm-5.1.js b/tests/11_geospatial/outputs/z-ai_glm-5.1.js new file mode 100644 index 0000000..bd8762b --- /dev/null +++ b/tests/11_geospatial/outputs/z-ai_glm-5.1.js @@ -0,0 +1,10 @@ +async function analyzeGPS(readings, boundary) { + const t = await import('https://esm.sh/@turf/turf') + const v = readings + .filter(r => t.booleanPointInPolygon(t.point(r.loc), boundary)) + .sort((a, b) => a.ts - b.ts) + return v.length < 2 ? 0 : Math.round(t.length(t.lineString(v.map(r => r.loc))) * 100) / 100 +} +export default analyzeGPS; +// Generation time: 54.397s +// Result: PASS \ No newline at end of file diff --git a/tests/12_mst_pipeline/outputs/z-ai_glm-5.1.js b/tests/12_mst_pipeline/outputs/z-ai_glm-5.1.js new file mode 100644 index 0000000..b9ec935 --- /dev/null +++ b/tests/12_mst_pipeline/outputs/z-ai_glm-5.1.js @@ -0,0 +1,39 @@ +const computeMST = async s => { + const [{ parse }, { Heap }, { default: tt }] = await Promise.all([ + import('https://esm.sh/smol-toml'), + import('https://esm.sh/mnemonist'), + import('https://esm.sh/text-table') + ]) + const { edges } = parse(s) + const p = {}, r = {} + const find = x => p[x] === x ? x : (p[x] = find(p[x])) + const union = (a, b) => { + a = find(a); b = find(b) + if (a === b) return false + if (r[a] < r[b]) [a, b] = [b, a] + p[b] = a + if (r[a] === r[b]) r[a]++ + return true + } + const h = new Heap((a, b) => a.weight - b.weight) + const n = new Set() + for (const e of edges) { + if (!(e.from in p)) { p[e.from] = e.from; r[e.from] = 0 } + if (!(e.to in p)) { p[e.to] = e.to; r[e.to] = 0 } + h.push(e) + n.add(e.from); n.add(e.to) + } + const m = [] + let w = 0 + while (m.length < n.size - 1 && h.size) { + const { from, to, weight } = h.pop() + if (union(from, to)) { + m.push([from, to, String(weight)]) + w += weight + } + } + return { table: tt([['From', 'To', 'Weight'], ...m]), totalWeight: w } +} +export default computeMST; +// Generation time: 47.623s +// Result: PASS \ No newline at end of file diff --git a/tests/1_dijkstra/outputs/z-ai_glm-5.1.js b/tests/1_dijkstra/outputs/z-ai_glm-5.1.js new file mode 100644 index 0000000..ef866d6 --- /dev/null +++ b/tests/1_dijkstra/outputs/z-ai_glm-5.1.js @@ -0,0 +1,22 @@ +async function findShortestPath(g, s, e) { + const { default: PQ } = await import('https://cdn.jsdelivr.net/npm/js-priority-queue/+esm'); + const q = new PQ({ comparator: (a, b) => a[1] - b[1] }); + const d = { [s]: 0 }; + q.queue([s, 0]); + while (q.length) { + const [n, c] = q.dequeue(); + if (n === e) return c; + if (c > (d[n] ?? 1/0)) continue; + for (const nb in g[n] || {}) { + const nd = c + g[n][nb]; + if (nd < (d[nb] ?? 1/0)) { + d[nb] = nd; + q.queue([nb, nd]); + } + } + } + return d[e] ?? 1/0; +} +export default findShortestPath; +// Generation time: 39.949s +// Result: PASS \ No newline at end of file diff --git a/tests/2_convex_hull/outputs/z-ai_glm-5.1.js b/tests/2_convex_hull/outputs/z-ai_glm-5.1.js new file mode 100644 index 0000000..338c450 --- /dev/null +++ b/tests/2_convex_hull/outputs/z-ai_glm-5.1.js @@ -0,0 +1,25 @@ +const findConvexHull = async (pts) => { + const _ = await import("https://esm.run/lodash"); + const p = _.uniqBy(_.sortBy(pts, ["x", "y"]), p => p.x + "," + p.y); + if (p.length < 3) return p; + + const c = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x); + const h = []; + + for (const pt of p) { + while (h.length >= 2 && c(h.at(-2), h.at(-1), pt) <= 0) h.pop(); + h.push(pt); + } + + const l = h.length + 1; + for (let i = p.length - 2; i >= 0; i--) { + while (h.length >= l && c(h.at(-2), h.at(-1), p[i]) <= 0) h.pop(); + h.push(p[i]); + } + + h.pop(); + return h; +}; +export default findConvexHull; +// Generation time: 35.612s +// Result: FAIL \ No newline at end of file diff --git a/tests/3_signal_pipeline/outputs/z-ai_glm-5.1.js b/tests/3_signal_pipeline/outputs/z-ai_glm-5.1.js new file mode 100644 index 0000000..70b4323 --- /dev/null +++ b/tests/3_signal_pipeline/outputs/z-ai_glm-5.1.js @@ -0,0 +1,44 @@ +const analyzeSignal = async (yamlStr) => { + const [yaml, math, ndarray, fft, DOMPurify] = await Promise.all([ + import('https://esm.sh/js-yaml').then(m => m.default), + import('https://esm.sh/mathjs').then(m => m.default), + import('https://esm.sh/ndarray').then(m => m.default), + import('https://esm.sh/ndarray-fft').then(m => m.default), + import('https://esm.sh/dompurify').then(m => m.default) + ]) + + const { sampleRate: sr, duration, components } = yaml.load(yamlStr) + const N = sr * duration + const signal = new Float64Array(N) + + for (let i = 0; i < N; i++) { + const t = i / sr + signal[i] = components.reduce( + (s, { amplitude: a, frequency: f }) => s + a * math.sin(2 * math.pi * f * t), 0) + } + + const re = ndarray(signal, [N]) + const im = ndarray(new Float64Array(N), [N]) + fft(1, re, im) + + const peaks = [] + for (let k = 0; k <= N / 2; k++) { + const mag = math.sqrt(re.get(k) ** 2 + im.get(k) ** 2) / (N / 2) + if (mag > 0.1) + peaks.push({ + frequencyHz: Math.round(k * sr / N), + magnitude: Math.round(mag * 100) / 100 + }) + } + + peaks.sort((a, b) => b.magnitude - a.magnitude) + + const html = `
| Frequency (Hz) | Magnitude |
|---|---|
| ${p.frequencyHz} | ${p.magnitude} |
${tableStr}`),
+ count: config.count
+ }
+}
+export default hexchain;
+// Generation time: 101.900s
+// Result: PASS
\ No newline at end of file
diff --git a/tests/5_markdown_parser/outputs/z-ai_glm-5.1.js b/tests/5_markdown_parser/outputs/z-ai_glm-5.1.js
new file mode 100644
index 0000000..c8722f4
--- /dev/null
+++ b/tests/5_markdown_parser/outputs/z-ai_glm-5.1.js
@@ -0,0 +1,7 @@
+async function parseMarkdown(m) {
+ const { marked } = await import('https://esm.sh/marked')
+ return marked.parse(m)
+}
+export default parseMarkdown;
+// Generation time: 29.156s
+// Result: PASS
\ No newline at end of file
diff --git a/tests/6_csv_processor/outputs/z-ai_glm-5.1.js b/tests/6_csv_processor/outputs/z-ai_glm-5.1.js
new file mode 100644
index 0000000..b0e88a9
--- /dev/null
+++ b/tests/6_csv_processor/outputs/z-ai_glm-5.1.js
@@ -0,0 +1,12 @@
+async function processCSV(csv, { filterColumn: fc, filterValue: fv, groupBy: gb, aggregateColumn: ac, operation: op }) {
+ const { default: P } = await import("https://cdn.jsdelivr.net/npm/papaparse@5/+esm")
+ const rows = P.parse(csv, { header: true, skipEmptyLines: true }).data.filter(r => r[fc] == fv)
+ const groups = rows.reduce((a, r) => ((a[r[gb]] ??= []).push(r), a), {})
+ return Object.entries(groups).map(([k, v]) => {
+ const sum = v.reduce((s, r) => s + (Number(r[ac]) || 0), 0)
+ return { [gb]: k, result: op == 'count' ? v.length : op == 'sum' ? sum : sum / v.length }
+ })
+}
+export default processCSV;
+// Generation time: 46.157s
+// Result: PASS
\ No newline at end of file
diff --git a/tests/7_scheduler/outputs/z-ai_glm-5.1.js b/tests/7_scheduler/outputs/z-ai_glm-5.1.js
new file mode 100644
index 0000000..ae4d8c2
--- /dev/null
+++ b/tests/7_scheduler/outputs/z-ai_glm-5.1.js
@@ -0,0 +1,35 @@
+const findAvailableSlots = async (c1, c2, cn) => {
+ const { DateTime: D } = await import('https://cdn.jsdelivr.net/npm/luxon@3/+esm');
+ const f = s => D.fromISO(s, { zone: 'UTC' });
+ const m = t => { const [h, v] = t.split(':'); return +h * 60 + +v; };
+ const g = d => d.hour * 60 + d.minute;
+ const ws = m(cn.workHours.start), we = m(cn.workHours.end), dur = cn.durationMinutes;
+ let merged = [...c1, ...c2].map(x => ({ s: f(x.start), e: f(x.end) })).sort((a, b) => a.s - b.s);
+ let busy = [];
+ for (let b of merged) {
+ if (!busy.length || b.s > busy[busy.length - 1].e) busy.push(b);
+ else if (b.e > busy[busy.length - 1].e) busy[busy.length - 1].e = b.e;
+ }
+ let res = [], cur = f(cn.searchRange.start), end = f(cn.searchRange.end);
+ const nWs = d => d.plus({ days: 1 }).startOf('day').plus({ minutes: ws });
+ const proc = (fS, fE) => {
+ let c = fS;
+ if (g(c) < ws) c = c.startOf('day').plus({ minutes: ws });
+ while (c < fE) {
+ if (g(c) >= we) { c = nWs(c); continue; }
+ let e = c.plus({ minutes: dur });
+ if (e > fE) break;
+ if (g(e) <= we) { res.push({ start: c.toISO(), end: e.toISO() }); c = e; }
+ else { if (g(c) <= ws) break; c = nWs(c); }
+ }
+ };
+ for (let b of busy) {
+ if (cur < b.s) proc(cur, b.s);
+ if (cur < b.e) cur = b.e;
+ }
+ if (cur < end) proc(cur, end);
+ return res;
+};
+export default findAvailableSlots;
+// Generation time: 134.745s
+// Result: PASS
\ No newline at end of file
diff --git a/tests/8_json_validator/outputs/z-ai_glm-5.1.js b/tests/8_json_validator/outputs/z-ai_glm-5.1.js
new file mode 100644
index 0000000..e9963a9
--- /dev/null
+++ b/tests/8_json_validator/outputs/z-ai_glm-5.1.js
@@ -0,0 +1,9 @@
+async function validateJSON(json, schema) {
+ const { default: Ajv } = await import('https://esm.sh/ajv')
+ const ajv = new Ajv()
+ const valid = ajv.validate(schema, json)
+ return { valid, errors: valid ? [] : ajv.errors.map(e => e.message) }
+}
+export default validateJSON;
+// Generation time: 28.047s
+// Result: PASS
\ No newline at end of file
diff --git a/tests/9_stream_visualizer/outputs/z-ai_glm-5.1.js b/tests/9_stream_visualizer/outputs/z-ai_glm-5.1.js
new file mode 100644
index 0000000..db6f652
--- /dev/null
+++ b/tests/9_stream_visualizer/outputs/z-ai_glm-5.1.js
@@ -0,0 +1,14 @@
+async function createStreamVisualizer(s, {maxPoints: m, alpha: a, width: w, height: h, yDomain: [y0, y1]}) {
+ const {scaleLinear, line} = await import("https://cdn.jsdelivr.net/npm/d3@7/+esm")
+ let d = [], e
+ for await (const {timestamp: t, value: v} of s) {
+ d.push({timestamp: t, value: v, ema: e = d.length ? a * v + (1 - a) * e : v})
+ if (d.length > m) d.shift()
+ }
+ const x = scaleLinear([d[0].timestamp, d.at(-1).timestamp], [0, w]),
+ y = scaleLinear([y0, y1], [h, 0])
+ return {data: d, path: line().x(p => x(p.timestamp)).y(p => y(p.ema))(d)}
+}
+export default createStreamVisualizer;
+// Generation time: 93.516s
+// Result: PASS
\ No newline at end of file