From 3ee432d4277546b38aea0ce119269d168446e507 Mon Sep 17 00:00:00 2001 From: Timm Stelzer Date: Sat, 4 May 2024 23:07:02 +0200 Subject: [PATCH] DIRTY [skip ci] --- workspace/cli/src/index.ts | 23 +- workspace/core/src/Classify.ts | 103 +------- workspace/core/src/DisplayConfig.ts | 21 ++ workspace/core/src/Json.ts | 2 - workspace/core/src/Show.ts | 73 +++++- workspace/core/src/Show/DisplayConfig.ts | 35 --- workspace/core/src/Test.ts | 233 ++---------------- workspace/core/src/index.ts | 4 +- workspace/core/src/internal/Classify.ts | 103 ++++++++ workspace/core/src/internal/DisplayConfig.ts | 17 ++ workspace/core/src/internal/Test.ts | 221 +++++++++++++++++ .../core/src/{Show => internal}/common.ts | 2 +- workspace/core/src/{Show => internal}/diff.ts | 51 ++-- .../src/{Show => internal}/format-diff.ts | 0 .../core/src/{Show => internal}/stats.ts | 41 ++- .../core/src/{Show => internal}/summarize.ts | 67 ++--- workspace/examples/src/as-library/async.ts | 8 +- workspace/examples/src/as-library/complex.ts | 88 ------- workspace/examples/src/as-library/simple.ts | 8 +- 19 files changed, 537 insertions(+), 563 deletions(-) create mode 100644 workspace/core/src/DisplayConfig.ts delete mode 100644 workspace/core/src/Json.ts delete mode 100644 workspace/core/src/Show/DisplayConfig.ts create mode 100644 workspace/core/src/internal/Classify.ts create mode 100644 workspace/core/src/internal/DisplayConfig.ts create mode 100644 workspace/core/src/internal/Test.ts rename workspace/core/src/{Show => internal}/common.ts (98%) rename workspace/core/src/{Show => internal}/diff.ts (63%) rename workspace/core/src/{Show => internal}/format-diff.ts (100%) rename workspace/core/src/{Show => internal}/stats.ts (67%) rename workspace/core/src/{Show => internal}/summarize.ts (78%) delete mode 100644 workspace/examples/src/as-library/complex.ts diff --git a/workspace/cli/src/index.ts b/workspace/cli/src/index.ts index b1b60a0..5042540 100644 --- a/workspace/cli/src/index.ts +++ b/workspace/cli/src/index.ts @@ -6,11 +6,11 @@ import * as PT from '@creative-introvert/prediction-testing'; import * as P from './prelude.js'; export type Config = { - testSuite: PT.TestSuite; + testSuite: PT.Test.TestSuite; dirPath: string; filePostfix: string; testSuiteName: string; - displayConfig?: Partial | undefined; + displayConfig?: Partial | undefined; showInput?: undefined | ((input: I) => string); showExpected?: undefined | ((expected: T) => string); showResult?: undefined | ((result: O, expected: T) => string); @@ -38,13 +38,13 @@ const labels = Options.text('labels').pipe( const createFilterLabel = (maybeLables: P.O.Option) => - (tr: PT.TestResult) => + (tr: PT.Test.TestResult) => P.O.match(maybeLables, { onNone: () => true, onSome: labels => labels.includes(tr.label), }); -const TestRunSchema = P.Schema.parseJson(PT.TestRunSchema); +const TestRunSchema = P.Schema.parseJson(PT.Test.TestRunSchema); const readPreviousTestRun = P.E.gen(function* () { const {testSuiteName, dirPath, filePostfix} = yield* Config; @@ -67,9 +67,9 @@ const summarize = Command.make('summarize', {labels}, ({labels}) => const filterLabel = createFilterLabel(labels); const previousTestRun = yield* readPreviousTestRun; - const testRun = yield* PT.testAll(testSuite).pipe( + const testRun = yield* PT.Test.all(testSuite).pipe( P.Stream.filter(filterLabel), - PT.runFoldEffect, + PT.Test.runFoldEffect, ); if (testRun.testResultIds.length === 0) { @@ -114,7 +114,7 @@ const diff = Command.make('diff', {ci}, ({ci}) => const previousTestRun = yield* readPreviousTestRun; - const testRun = yield* PT.testAll(testSuite).pipe( + const testRun = yield* PT.Test.all(testSuite).pipe( P.Stream.filter(next => P.pipe( P.O.flatMap(previousTestRun, prevTestRun => @@ -128,7 +128,7 @@ const diff = Command.make('diff', {ci}, ({ci}) => P.O.getOrElse(() => true), ), ), - PT.runFoldEffect, + PT.Test.runFoldEffect, ); if (testRun.testResultIds.length === 0) { @@ -145,8 +145,7 @@ const diff = Command.make('diff', {ci}, ({ci}) => }), '', PT.Show.diff({ - testRun, - diff: PT.diff({testRun, previousTestRun}), + diff: PT.Test.diff({testRun, previousTestRun}), }), ].join('\n'), ); @@ -164,7 +163,9 @@ const write = Command.make('write', {}, () => yield* fs.makeDirectory(dirPath, {recursive: true}); - const testRun = yield* PT.testAll(testSuite).pipe(PT.runFoldEffect); + const testRun = yield* PT.Test.all(testSuite).pipe( + PT.Test.runFoldEffect, + ); const filePath = `${dirPath}/${testSuiteName}.${filePostfix}.json`; yield* fs.writeFileString(filePath, JSON.stringify(testRun, null, 2)); yield* P.Console.log(`Wrote to "${filePath}"`); diff --git a/workspace/core/src/Classify.ts b/workspace/core/src/Classify.ts index f24018c..19bd2e4 100644 --- a/workspace/core/src/Classify.ts +++ b/workspace/core/src/Classify.ts @@ -1,109 +1,14 @@ -import * as P from './prelude.js'; +import * as internal from './internal/Classify.js'; -export const Label = { - TN: 'TN', - TP: 'TP', - FP: 'FP', - FN: 'FN', -} as const; +export type Label = 'TP' | 'TN' | 'FP' | 'FN'; -export type Label = (typeof Label)[keyof typeof Label]; - -export const LabelSchema: P.Schema.Schema