From fced468d21e57a1f9fe226729b7ee13c7790e3ef Mon Sep 17 00:00:00 2001 From: Thomas Parslow Date: Wed, 3 Jul 2024 14:05:44 +0100 Subject: [PATCH] sortOutput option for challenges --- src/challenges/types.ts | 3 ++- src/challenges/utils.ts | 4 ++-- src/game/verifier.ts | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/challenges/types.ts b/src/challenges/types.ts index abdfd42..277879a 100644 --- a/src/challenges/types.ts +++ b/src/challenges/types.ts @@ -18,6 +18,7 @@ export interface Assertion< > { input: A; output: R | ((play: (...args: A) => R, input: A) => R); + sortOutput?: boolean; } export interface Challenge< @@ -27,7 +28,7 @@ export interface Challenge< title: string; description: string; example: Example; - assertions: readonly Assertion[]; + assertions: Assertion[]; assertRules?: (playString: string) => void; context?: Record; timeLimitMinutes?: number; diff --git a/src/challenges/utils.ts b/src/challenges/utils.ts index ee13e48..65fbdfd 100644 --- a/src/challenges/utils.ts +++ b/src/challenges/utils.ts @@ -52,9 +52,9 @@ export const getChallenges = async (challengeDir: string) => { key, solution: fs.readFileSync(solutionPath, UTF8), ...challenge, - example: `(${challenge.example.input + example: `play(${challenge.example.input .map(formatValue) - .join(', ')}) => ${formatValue(challenge.example.output)}`, + .join(', ')}) ==== ${formatValue(challenge.example.output)}`, }; }) ); diff --git a/src/game/verifier.ts b/src/game/verifier.ts index e11cd1b..b44b0ea 100644 --- a/src/game/verifier.ts +++ b/src/game/verifier.ts @@ -81,6 +81,11 @@ process.on('message', (entry: VerifyJob) => { ) : assertion.output; + if (assertion.sortOutput && Array.isArray(result) && Array.isArray(expected)) { + result.sort(); + expected.sort() + } + if (!lodash.isEqual(result, expected)) { throw new Error( `Expected ${formatTypeAndValue(