-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #861 from porink0424/feat/add-journal-storage-tests
Improve tests for `JournalStorage`
- Loading branch information
Showing
3 changed files
with
140 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,59 @@ | ||
import assert from "node:assert" | ||
import { openAsBlob } from "node:fs" | ||
import path from "node:path" | ||
import test from "node:test" | ||
import { describe, it } from "node:test" | ||
|
||
import * as mut from "../pkg/journal.js" | ||
|
||
const n_studies = 2 | ||
|
||
test("Test Journal File Storage", async () => { | ||
describe("Test Journal File Storage", async () => { | ||
const blob = await openAsBlob( | ||
path.resolve(".", "test", "asset", "journal.log") | ||
) | ||
const buf = await blob.arrayBuffer() | ||
const storage = new mut.JournalFileStorage(buf) | ||
const studies = await storage.getStudies() | ||
const studySummaries = await storage.getStudies() | ||
const studies = await Promise.all( | ||
studySummaries.map((_summary, index) => storage.getStudy(index)) | ||
) | ||
|
||
it("Check the study including Infinities", () => { | ||
const study = studies.find((s) => s.study_name === "single-inf") | ||
study.trials.forEach((trial, index) => { | ||
if (index % 3 === 0) { | ||
assert.strictEqual(trial.values[0], Infinity) | ||
} else if (index % 3 === 1) { | ||
assert.strictEqual(trial.values[0], -Infinity) | ||
} | ||
}) | ||
}) | ||
|
||
it("Check the study including NaNs", () => { | ||
const study = studies.find((s) => s.study_name === "single-nan-report") | ||
for (const trial of study.trials) { | ||
assert.strictEqual( | ||
trial.intermediate_values.find((v) => v.step === 1).value, | ||
NaN | ||
) | ||
} | ||
}) | ||
|
||
it("Check the parsing errors", async () => { | ||
const blob = await openAsBlob( | ||
path.resolve(".", "test", "asset", "journal-broken.log") | ||
) | ||
const buf = await blob.arrayBuffer() | ||
const storage = new mut.JournalFileStorage(buf) | ||
const errors = storage.getErrors() | ||
|
||
assert.strictEqual(errors.length, 1) | ||
assert.strictEqual( | ||
errors[0].message, | ||
`Unexpected token '.', ..."op_code": ..., "work"... is not valid JSON` | ||
) | ||
}) | ||
|
||
assert.strictEqual(studies.length, n_studies) | ||
it("Check the number of studies", () => { | ||
const N_STUDIES = 4 | ||
assert.strictEqual(studies.length, N_STUDIES) | ||
}) | ||
}) |