package de.bmoth.typechecker;

import static de.bmoth.typechecker.TestTypechecker.getFormulaTypes;
import static org.junit.Assert.assertEquals;

import java.util.Map;

import org.junit.Test;

public class RelationsTest {

    @Test
    public void testDirectProduct() {
        String formula = "a = {1 |-> TRUE} >< {b |-> 1}";
        Map<String, String> formulaTypes = getFormulaTypes(formula);
        assertEquals("POW(INTEGER*(BOOL*INTEGER))", formulaTypes.get("a"));
        assertEquals("INTEGER", formulaTypes.get("b"));
    }

    @Test
    public void testOverwriteRelation() {
        String formula = "k = {x|->2} <+ {1|->y}";
        Map<String, String> formulaTypes = getFormulaTypes(formula);
        assertEquals("POW(INTEGER*INTEGER)", formulaTypes.get("k"));
        assertEquals("INTEGER", formulaTypes.get("x"));
        assertEquals("INTEGER", formulaTypes.get("y"));
    }
    
    @Test
    public void testDomainRestriction() {
        String formula = "k = x <| {1|->1}";
        Map<String, String> formulaTypes = getFormulaTypes(formula);
        assertEquals("POW(INTEGER*INTEGER)", formulaTypes.get("k"));
        assertEquals("POW(INTEGER)", formulaTypes.get("x"));
    }

    @Test
    public void testDomainSubstraction() {
        String formula = "k = x <<| {1|->1}";
        Map<String, String> formulaTypes = getFormulaTypes(formula);
        assertEquals("POW(INTEGER*INTEGER)", formulaTypes.get("k"));
        assertEquals("POW(INTEGER)", formulaTypes.get("x"));
    }
    
    @Test
    public void testRangeRestriction() {
        String formula = "k = {1|->1} |> x";
        Map<String, String> formulaTypes = getFormulaTypes(formula);
        assertEquals("POW(INTEGER*INTEGER)", formulaTypes.get("k"));
        assertEquals("POW(INTEGER)", formulaTypes.get("x"));
    }

    @Test
    public void testRangeSubstraction() {
        String formula = "k = {1|->1} |>> x";
        Map<String, String> formulaTypes = getFormulaTypes(formula);
        assertEquals("POW(INTEGER*INTEGER)", formulaTypes.get("k"));
        assertEquals("POW(INTEGER)", formulaTypes.get("x"));
    }

    @Test
    public void testInverseRelation() {
        String formula = "k = {1|->TRUE}~";
        Map<String, String> formulaTypes = getFormulaTypes(formula);
        assertEquals("POW(BOOL*INTEGER)", formulaTypes.get("k"));
    }
    
}

@@ -24,16 +24,63 @@
 ecker;%0A%0A
+import org.junit.Test;%0A%0Aimport java.util.Map;%0A%0A
 import s
@@ -189,83 +189,231 @@
 s;%0A%0A
-import java.util.Map;%0A%0Aimport org.junit.Test;%0A%0Apublic class RelationsTest %7B
+public class RelationsTest %7B%0A    private static final String INTEGER = %22INTEGER%22;%0A    private static final String POW_INTEGER = %22POW(INTEGER)%22;%0A    private static final String POW_INTEGER_X_INTEGER = %22POW(INTEGER*INTEGER)%22;
 %0A%0A  
@@ -678,33 +678,31 @@
 ssertEquals(
-%22
 INTEGER
-%22
 , formulaTyp
@@ -915,38 +915,37 @@
 tEquals(
-%22
 POW
-(
+_
 INTEGER
-*
+_X_
 INTEGER
-)%22
 , formul
@@ -979,33 +979,31 @@
 ssertEquals(
-%22
 INTEGER
-%22
 , formulaTyp
@@ -1037,25 +1037,23 @@
 tEquals(
-%22
 INTEGER
-%22
 , formul
@@ -1068,36 +1068,32 @@
 et(%22y%22));%0A    %7D%0A
-    
 %0A    @Test%0A    p
@@ -1329,38 +1329,35 @@
 ssertEquals(
-%22
 POW
-(
+_
 INTEGER
-)%22
 , formulaTyp
@@ -1566,38 +1566,37 @@
 tEquals(
-%22
 POW
-(
+_
 INTEGER
-*
+_X_
 INTEGER
-)%22
 , formul
@@ -1630,38 +1630,35 @@
 ssertEquals(
-%22
 POW
-(
+_
 INTEGER
-)%22
 , formulaTyp
@@ -1677,20 +1677,16 @@
 ;%0A    %7D%0A
-    
 %0A    @Te
@@ -1929,38 +1929,35 @@
 ssertEquals(
-%22
 POW
-(
+_
 INTEGER
-)%22
 , formulaTyp
@@ -2165,38 +2165,37 @@
 tEquals(
-%22
 POW
-(
+_
 INTEGER
-*
+_X_
 INTEGER
-)%22
 , formul
@@ -2233,30 +2233,27 @@
 tEquals(
-%22
 POW
-(
+_
 INTEGER
-)%22
 , formul
@@ -2512,15 +2512,11 @@
 ;%0A    %7D%0A
-    
 %0A%7D%0A

introduce fields for strings