event 325 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..ac04ed4c72748f2a1f253864d2a6a0cd4bf3372d
|
||||
--- /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.throws(() => 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.throws(() => 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/0000000325.json
Normal file
1
events/0000000325.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":"0x1be364d3b091e596b0466db334b58343db47c0302f5aea508baafe864718f5176dc2c0f5a9a337ca7429b6de6dd8837bdc6b5e54588e25a7f7e73edb3b3d75e2"},"mainHead":null,"message":{"author":"0x16808507970f18ea89a07ad1d30b53e7e3a3891d","baseCommit":"0x65e902c7c4640842ff3087a5a9aa3950d8d86679","basePartial":"0x0000000000000000000000000000000000000000000000000000000000000000","citesHash":"0x0000000000000000000000000000000000000000000000000000000000000000","issueId":"0x98f19ce946d4ef692a1354cdda7c9c22c3deb8168f1eb224b4d56b790e2ca305","issuedAt":"1790926062","lines":13,"nonce":"1790926062000","patchHash":"0x430f30a26bcb1f23aeaf8bce594793578a421a3f9504660f07bb785b4787b80a","project":"0x16d6e75341c5f21003a4d9e89b416a545f7335094d7df139fd20942c9b7fb2de","repo":"0xa1bb61fe185a9ec2921347a472a1d2f0ee4fb72bfb65d5be4fccd49e428ccf6a"},"pr":"elffuss/translator:item/0x51341970906a1fd3227c4224d8c075bd722f9c06dcc276acceeb52c37efa2774"},"eventHash":"0x2a129ad4e9ec5bae139d5dfac1a147ca0e9814fd5bc6a6d206ed2c28b9898f85","gatewaySignature":"0xf3339f00cb57eb4197df0e6ffbac14dc483a04e3ece898dc8ef1951fbc1d464a07558eac2ee831a5178b90466e660ea15969071ca4269bd2aaaa431e2a8e51d81c","prev":"0x826d50ce30cf41e7a0ef89f4c568c9cdfc5fb22fbd5b4bdcee7eed0beece4524","seq":325,"ts":1790926063,"type":"solution","v":2}
|
||||
Reference in New Issue
Block a user