65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
import { test, expect, describe } from "bun:test";
|
|
import {
|
|
abs1,
|
|
abs2,
|
|
app1,
|
|
app2,
|
|
arr,
|
|
convertToDebruijn,
|
|
infer,
|
|
unitTy,
|
|
var1,
|
|
var2,
|
|
} from ".";
|
|
|
|
describe("convertToDeBruijn", () => {
|
|
test("K combinator", () => {
|
|
const expr = abs1("x", unitTy(), abs1("y", unitTy(), var1("x")));
|
|
const expr2 = abs2(unitTy(), abs2(unitTy(), var2(1)));
|
|
|
|
expect(convertToDebruijn(expr)).toEqual(expr2);
|
|
});
|
|
|
|
test("S combinator", () => {
|
|
const expr = abs1(
|
|
"x",
|
|
arr(unitTy(), arr(unitTy(), unitTy())),
|
|
abs1(
|
|
"y",
|
|
arr(unitTy(), unitTy()),
|
|
abs1(
|
|
"z",
|
|
unitTy(),
|
|
app1(app1(var1("x"), var1("z")), app1(var1("y"), var1("z"))),
|
|
),
|
|
),
|
|
);
|
|
const expr2 = abs2(
|
|
arr(unitTy(), arr(unitTy(), unitTy())),
|
|
abs2(
|
|
arr(unitTy(), unitTy()),
|
|
abs2(unitTy(), app2(app2(var2(2), var2(0)), app2(var2(1), var2(0)))),
|
|
),
|
|
);
|
|
|
|
expect(convertToDebruijn(expr)).toEqual(expr2);
|
|
});
|
|
});
|
|
|
|
describe("infer", () => {
|
|
test("K combinator", () => {
|
|
const expr = abs1("x", unitTy(), abs1("y", unitTy(), var1("x")));
|
|
const expr2 = convertToDebruijn(expr);
|
|
const ty = arr(unitTy(), arr(unitTy(), unitTy()));
|
|
|
|
expect(infer(expr2)).toEqual(ty);
|
|
});
|
|
|
|
test("K combinator", () => {
|
|
const expr = abs1("x", unitTy(), abs1("y", unitTy(), var1("x")));
|
|
const expr2 = convertToDebruijn(expr);
|
|
const ty = arr(unitTy(), arr(unitTy(), arr(unitTy(), unitTy())));
|
|
|
|
expect(infer(expr2)).not.toEqual(ty);
|
|
});
|
|
});
|