summaryrefslogtreecommitdiff
path: root/java/TermTest.java
blob: f11ca77b338d1d25715c03c60882623545bd6731 (plain)
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
package org.lambdanantes.lcgoji.ast;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.lambdanantes.lcgoji.ast.Abs.λ;
import static org.lambdanantes.lcgoji.ast.App.apply;
import static org.lambdanantes.lcgoji.ast.Var.var;

public class TermTest {

    @Test
    public void les_equals_des_termes_sont_corrects() {
        // x == x
        assertThat(var("x"), is(var("x")));
        // x != y
        assertThat(var("x"), is(not(var("y"))));
        // λx.x == λx.x
        assertThat(λ("x", var("x")), is(λ("x", var("x"))));
        // λx.x != λy.x
        assertThat(λ("x", var("x")), is(not(λ("y", var("x")))));
        // x y == x y
        assertThat(apply(var("x"), var("y")), is(apply(var("x"), var("y"))));
        // x x != x y
        assertThat(apply(var("x"), var("x")), is(not(apply(var("x"), var("y")))));
    }

    @Test
    public void les_toString_des_termes_utilisent_la_notation_consacree() {
        assertThat(var("x").toString(), is("x"));
        assertThat(λ("x", var("x")).toString(), is("λx.x"));
        assertThat(apply(λ("x", var("x")), var("x")).toString(), is("(λx.x) x"));
        assertThat(apply(λ("x", λ("x", var("x"))), var("y")).toString(), is("(λx.λx.x) y"));
    }

}