Skip to content

Commit

Permalink
sortOutput option for challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
almost committed Jul 3, 2024
1 parent 7fb53d9 commit fced468
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/challenges/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Assertion<
> {
input: A;
output: R | ((play: (...args: A) => R, input: A) => R);
sortOutput?: boolean;
}

export interface Challenge<
Expand All @@ -27,7 +28,7 @@ export interface Challenge<
title: string;
description: string;
example: Example<A, R>;
assertions: readonly Assertion<A, R>[];
assertions: Assertion<A, R>[];
assertRules?: (playString: string) => void;
context?: Record<string, unknown>;
timeLimitMinutes?: number;
Expand Down
4 changes: 2 additions & 2 deletions src/challenges/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`,
};
})
);
Expand Down
5 changes: 5 additions & 0 deletions src/game/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit fced468

Please sign in to comment.