Skip to content

Commit

Permalink
chore: add vitest to ci
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkrieger committed Apr 14, 2024
1 parent 9398eed commit c5de8bb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/vitest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Run unit tests

on:
- push
- pull_request

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v3
with:
version: 8
run_install: true

- name: Run tests
run: pnpm test run
38 changes: 22 additions & 16 deletions src/lib/cosinePairings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@ import EmbeddingCache from "@/worker/EmbeddingCache";

const cityFactsDataset = exampleDatasets.cityFacts;

test("computeCosinePairings should produce groundtruth cosine values within 5 decimal places", async () => {
const cityFactsPairingsResult = await fetch(cityFactsDataset.datasetURL);
const cityFactsPairings = await cityFactsPairingsResult.json();
const cityFactsEmbeddingsResult = await fetch(cityFactsDataset.embeddingsURL);
const cityFactsEmbeddings = await cityFactsEmbeddingsResult.json();
const embeddingCache = new EmbeddingCache();
embeddingCache.addToCache(cityFactsEmbeddings);
test(
"computeCosinePairings should produce groundtruth cosine values within 5 decimal places",
async () => {
const cityFactsPairingsResult = await fetch(cityFactsDataset.datasetURL);
const cityFactsPairings = await cityFactsPairingsResult.json();
const cityFactsEmbeddingsResult = await fetch(
cityFactsDataset.embeddingsURL
);
const cityFactsEmbeddings = await cityFactsEmbeddingsResult.json();
const embeddingCache = new EmbeddingCache();
embeddingCache.addToCache(cityFactsEmbeddings);

const tensorDataset = pairingToDataset(cityFactsPairings, embeddingCache);
const cosinePairings = await computeCosinePairings(tensorDataset);
for (let i = 0; i < cosinePairings.length; i++) {
expect(
cosinePairings[i][0],
`cosinePairings[${i}] is within 5 decimal places of groundtruth`
).toBeCloseTo(citiesCosinePairingsGroundtruth[i][0], 5);
}
});
const tensorDataset = pairingToDataset(cityFactsPairings, embeddingCache);
const cosinePairings = await computeCosinePairings(tensorDataset);
for (let i = 0; i < cosinePairings.length; i++) {
expect(
cosinePairings[i][0],
`cosinePairings[${i}] is within 5 decimal places of groundtruth`
).toBeCloseTo(citiesCosinePairingsGroundtruth[i][0], 5);
}
},
{ timeout: 15000 }
);

0 comments on commit c5de8bb

Please sign in to comment.