Skip to content

Commit fced468

Browse files
committed
sortOutput option for challenges
1 parent 7fb53d9 commit fced468

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Diff for: src/challenges/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface Assertion<
1818
> {
1919
input: A;
2020
output: R | ((play: (...args: A) => R, input: A) => R);
21+
sortOutput?: boolean;
2122
}
2223

2324
export interface Challenge<
@@ -27,7 +28,7 @@ export interface Challenge<
2728
title: string;
2829
description: string;
2930
example: Example<A, R>;
30-
assertions: readonly Assertion<A, R>[];
31+
assertions: Assertion<A, R>[];
3132
assertRules?: (playString: string) => void;
3233
context?: Record<string, unknown>;
3334
timeLimitMinutes?: number;

Diff for: src/challenges/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export const getChallenges = async (challengeDir: string) => {
5252
key,
5353
solution: fs.readFileSync(solutionPath, UTF8),
5454
...challenge,
55-
example: `(${challenge.example.input
55+
example: `play(${challenge.example.input
5656
.map(formatValue)
57-
.join(', ')}) => ${formatValue(challenge.example.output)}`,
57+
.join(', ')}) ==== ${formatValue(challenge.example.output)}`,
5858
};
5959
})
6060
);

Diff for: src/game/verifier.ts

+5
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ process.on('message', (entry: VerifyJob) => {
8181
)
8282
: assertion.output;
8383

84+
if (assertion.sortOutput && Array.isArray(result) && Array.isArray(expected)) {
85+
result.sort();
86+
expected.sort()
87+
}
88+
8489
if (!lodash.isEqual(result, expected)) {
8590
throw new Error(
8691
`Expected ${formatTypeAndValue(

0 commit comments

Comments
 (0)