-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.test.ts
78 lines (77 loc) · 1.38 KB
/
.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { apply, toString } from "./util.ts"
Deno.test("basic rewriting", () => {
apply
`double $x = $x $x`
`double v`
`(v v)`
})
Deno.test("toString", () => {
toString
`a (b)`
`(a b)`
})
Deno.test("partial rewrite", () => {
apply
`1 = p 0`
`p 1`
`(p (p 0))`
})
Deno.test("peano", () => {
apply
`
1 = p 0
2 = p 1
`
`2`
`(p (p 0))`
apply
`
1 = p 0
2 = p 1
`
`2 + 1`
`((p (p 0)) + (p 0))`
apply
`
$a + (p $b) = p ($a + $b)
$a + 0 = $a
`
`((p (p 0)) + (p 0))`
`(p (p (p 0)))`
/*
apply
`
1 = p 0
2 = p 1
3 = p 2
$a + (p $b) = p ($a + $b)
$a + 0 = $a
p 0 = 1
p 1 = 2
p 2 = 3
`
`2 + 1`
`3`
*/
})
Deno.test("math", () => {
apply
`
sqrt $a = $a ^ (1 / 2)
$a / $b = $a * ($b ^ (- 1))
1 * $a = $a
($a ^ $b) ^ $c = $a ^ ($b * $c)
`
`1 / (sqrt 2)`
`(2 ^ ((2 ^ (- 1)) * (- 1)))`
})
Deno.test("var", () => {
apply
`$v $v = double $v`
`v v`
`(double v)`
apply
`$v $v = double $v`
`x y`
`(x y)`
})