Skip to content

Commit

Permalink
test: add regression test that ensures the maximum number of steps th…
Browse files Browse the repository at this point in the history
…e interpreter can process
  • Loading branch information
susisu committed Aug 26, 2023
1 parent ca688dd commit f2ed268
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/__tests__/vm.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Recurse } from "../util";
import type { Brainfuck } from "../vm";
import type { Assert, Equal } from "./assert";

Expand Down Expand Up @@ -29,3 +30,24 @@ type Output_2 = Brainfuck<Program_2, Input_2>;
export type Test_Brainfuck_2 = Assert<
Equal<Output_2, "Hello, world!" | "!dlrow ,olleH" | "Bye" | "eyB">
>;

type Repeat<S extends string, N extends number> = Recurse<RepeatSub<S, N, "", []>>;
type RepeatSub<
S extends string,
N extends number,
R extends string,
L extends unknown[],
> = L["length"] extends N ? R : { __rec: RepeatSub<S, N, `${R}${S}`, [...L, unknown]> };

type Reverse<S extends string> = Recurse<ReverseSub<S, "">>;
// prettier-ignore
type ReverseSub<S extends string, R extends string> =
S extends "" ? R
: S extends `${infer A}${infer B}` ? { __rec: ReverseSub<B, `${A}${R}`> }
: never;

type Program_3 = ">,[>,]<[.<]";
type Input_3 = Repeat<"ABCD", 1000>;
type Output_3 = Brainfuck<Program_3, Input_3>;
type Expected_3 = Reverse<Input_3>;
export type Test_Brainfuck_3 = Assert<Equal<Output_3, Expected_3>>;

0 comments on commit f2ed268

Please sign in to comment.