From f5acac09f14fc1667cdc0523c436d21baf237242 Mon Sep 17 00:00:00 2001 From: porink0424 Date: Wed, 10 Apr 2024 14:46:42 +0900 Subject: [PATCH] Add detailed test items to journal.test --- tslib/storage/test/journal.test.mjs | 46 +++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/tslib/storage/test/journal.test.mjs b/tslib/storage/test/journal.test.mjs index 1e8bd274..130dba74 100644 --- a/tslib/storage/test/journal.test.mjs +++ b/tslib/storage/test/journal.test.mjs @@ -1,19 +1,53 @@ 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)) + ) + const errors = storage.getErrors() - assert.strictEqual(studies.length, n_studies) + 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", () => { + assert.strictEqual(errors.length, 1) + assert.strictEqual( + errors[0].message, + `Unexpected token '.', ..."op_code": ..., "work"... is not valid JSON` + ) + }) + + it("Check the number of studies", () => { + const N_STUDIES = 4 + assert.strictEqual(studies.length, N_STUDIES) + }) })