event 315 solution
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
diff --git a/diarize.mjs b/diarize.mjs
|
||||
index 622b5267a17a6e3142931024ae45611ecb21b712..b47059b51d5db5fdbffabbefb6320b38dafa0c3b 100644
|
||||
--- a/diarize.mjs
|
||||
+++ b/diarize.mjs
|
||||
@@ -25,7 +25,18 @@ export async function loadDiarizer(TF, { device = 'wasm' } = {}) {
|
||||
return { seg, segP, emb, embP };
|
||||
}
|
||||
|
||||
-const cos = (a, b) => { let dt = 0, na = 0, nb = 0; for (let i = 0; i < a.length; i++) { dt += a[i]*b[i]; na += a[i]*a[i]; nb += b[i]*b[i]; } return dt / (Math.sqrt(na)*Math.sqrt(nb) || 1); };
|
||||
+const cos = (a, b) => {
|
||||
+ if (a.length !== b.length) {
|
||||
+ throw new Error('cosine: vectors must have the same length');
|
||||
+ }
|
||||
+ let dt = 0, na = 0, nb = 0;
|
||||
+ for (let i = 0; i < a.length; i++) {
|
||||
+ dt += a[i]*b[i];
|
||||
+ na += a[i]*a[i];
|
||||
+ nb += b[i]*b[i];
|
||||
+ }
|
||||
+ return dt / (Math.sqrt(na)*Math.sqrt(nb) || 1);
|
||||
+};
|
||||
const rms = (a) => { let s = 0; for (const v of a) s += v*v; return Math.sqrt(s/a.length); };
|
||||
|
||||
async function embed(D, slice) {
|
||||
diff --git a/tests/acceptance/1/CRITERIA.json b/tests/acceptance/1/CRITERIA.json
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..b7be116c5920b5a10f292bbcce161d6cfe2c9a1b
|
||||
--- /dev/null
|
||||
+++ b/tests/acceptance/1/CRITERIA.json
|
||||
@@ -0,0 +1,30 @@
|
||||
+{
|
||||
+ "schema": "elffuss-t2t/criteria@2",
|
||||
+ "issue": 1,
|
||||
+ "criteria": [
|
||||
+ {
|
||||
+ "index": 1,
|
||||
+ "tests": [
|
||||
+ "tests/acceptance/1/criteria.test.js::criterion 1"
|
||||
+ ]
|
||||
+ },
|
||||
+ {
|
||||
+ "index": 2,
|
||||
+ "tests": [
|
||||
+ "tests/acceptance/1/criteria.test.js::criterion 2"
|
||||
+ ]
|
||||
+ },
|
||||
+ {
|
||||
+ "index": 3,
|
||||
+ "tests": [
|
||||
+ "tests/acceptance/1/criteria.test.js::criterion 3"
|
||||
+ ]
|
||||
+ },
|
||||
+ {
|
||||
+ "index": 4,
|
||||
+ "tests": [
|
||||
+ "tests/acceptance/1/criteria.test.js::criterion 4"
|
||||
+ ]
|
||||
+ }
|
||||
+ ]
|
||||
+}
|
||||
diff --git a/tests/acceptance/1/criteria.test.js b/tests/acceptance/1/criteria.test.js
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..ed79561c1a8c3e57aab5126288e9109c119bdaab
|
||||
--- /dev/null
|
||||
+++ b/tests/acceptance/1/criteria.test.js
|
||||
@@ -0,0 +1,25 @@
|
||||
+import { test } from 'node:test'
|
||||
+import assert from 'node:assert/strict'
|
||||
+import { readFileSync } from 'node:fs'
|
||||
+import * as mod from '../../../diarize.mjs' // the code under test: call it as mod.<name>(...)
|
||||
+const source = readFileSync(new URL('../../../diarize.mjs', import.meta.url), 'utf8') // the text of diarize.mjs, for a criterion about how the file is written
|
||||
+
|
||||
+test('criterion 1', () => {
|
||||
+ // `cosine([1, 2, 3], [1, 2])` throws an Error whose message starts with `cosine:`.
|
||||
+ assert.rejects(() => mod.cosine([1, 2, 3], [1, 2]), /cosine:/)
|
||||
+})
|
||||
+
|
||||
+test('criterion 2', () => {
|
||||
+ // `cosine([1, 0], [1, 0, 5])` throws an Error whose message starts with `cosine:`.
|
||||
+ assert.rejects(() => mod.cosine([1, 0], [1, 0, 5]), /cosine:/)
|
||||
+})
|
||||
+
|
||||
+test('criterion 3', () => {
|
||||
+ // `cosine([1, 0], [1, 0])` returns 1.
|
||||
+ assert.deepEqual(mod.cosine([1, 0], [1, 0]), 1)
|
||||
+})
|
||||
+
|
||||
+test('criterion 4', () => {
|
||||
+ // `cosine([0, 0], [0, 0])` returns 0.
|
||||
+ assert.deepEqual(mod.cosine([0, 0], [0, 0]), 0)
|
||||
+})
|
||||
1
events/0000000315.json
Normal file
1
events/0000000315.json
Normal file
@@ -0,0 +1 @@
|
||||
{"data":{"cites":[],"envelope":{"delegation":{"identity":"0x16808507970f18ea89a07ad1d30b53e7e3a3891d","nonce":"1790923316","project":"0x0000000000000000000000000000000000000000000000000000000000000000","scopes":3,"sessionX":"0xcb850292d34644fc2c21598b934b94b5fcb0e6f2359c727df7666df8700d940c","sessionY":"0x7a30e145e0151461b43fcdd2b4789b81b5efe08af3688be6b8d3efb666860734","validFrom":"1790923316","validUntil":"1791528116"},"delegationSignature":"0x169fdc790559880429426a2d1a3c7fc0c46a15950a5e4ca2d1d0b90815225e1e486644e860f3dc98c672ace2f20aee152cd41e467020580ab096b1721cbd70e41b","kind":"session","signature":"0x3a6686c8172b3b906ff6c24a49934a395ed7a883472168de5d73090cc3dfb83d39638823c1b99443f7932225393d0caa43f3db330871a50081df9bb65091bd53"},"mainHead":null,"message":{"author":"0x16808507970f18ea89a07ad1d30b53e7e3a3891d","baseCommit":"0xe4c6cf14da9e132bab1cfe0c8fc8a119ca21a23a","basePartial":"0x0000000000000000000000000000000000000000000000000000000000000000","citesHash":"0x0000000000000000000000000000000000000000000000000000000000000000","issueId":"0x98062380597bea3942e80b35090b356d0ac3e0e54c88cbbf251faa36758056f4","issuedAt":"1790926023","lines":13,"nonce":"1790926023000","patchHash":"0x3cfe540572eb87786d4124722535b2058afa7d5a08cf4b12748bb1301161ad3c","project":"0x16d6e75341c5f21003a4d9e89b416a545f7335094d7df139fd20942c9b7fb2de","repo":"0x90a759ddaced884b468c522f85ec668e8d519bb91389041e0513c3ef0d1053e8"},"pr":"elffuss/copilot:item/0x8f0c563f9b856c1260d72d24bcf08af92697fd1617558c23633d97ff7c761b73"},"eventHash":"0x73440d36fafd6d811f7152fc3455c5ae4a88daea7a2eaefb952314a26f1f535c","gatewaySignature":"0xe09070f5c28a1d18bf4e6290aa7ce15b39b9ee5ccda3654ca8fee18548cdd3d4548e820ab57c0cc025150a59ba3a622a4b43469033263a222a71944f1e61857b1b","prev":"0x850aae320d74e5efde28fda8c7f42415cd5b233c6f92be2eaadcb696cc8d3dd8","seq":315,"ts":1790926023,"type":"solution","v":2}
|
||||
Reference in New Issue
Block a user