package be.functional.dataflow.model;

import org.junit.Assert;
import org.junit.Test;

import be.functional.dataflow.core.Expression;
import be.functional.dataflow.core.IValue;
import be.functional.dataflow.core.IExpression;
import be.functional.dataflow.core.IProperty;
import be.functional.dataflow.model.Model;

public class ModelTest {

  @Test
  public void basicTest() {
    final Model model = new Model();

    final IProperty<Integer> c = model.<Integer>getProperty("a", "b", "c");
    c.set(2);

    final IProperty<Integer> d = model.<Integer>getProperty("a", "b", "d");
    d.set(3);

    final IValue<Integer> e = new Expression<Integer>() {
      @Override
      protected Integer calculate() {
        return c.get(this) + d.get(this);
      }
    };

    Assert.assertEquals(e.get(IExpression.SIDE_EFFECT), (Integer) 5);

    final Model bReplacement = new Model();
    bReplacement.getProperty("c").set(7);
    bReplacement.getProperty("d").set(9);
    model.getProperty("a", "b").set(bReplacement);

    Assert.assertEquals((Integer) 7, c.get(IExpression.SIDE_EFFECT));
    Assert.assertEquals((Integer) 9, d.get(IExpression.SIDE_EFFECT));
    Assert.assertEquals((Integer) 16, e.get(IExpression.SIDE_EFFECT));
  }
}

@@ -92,48 +92,42 @@
 ort 
-be.functional.dataflow.core.Express
+com.google.common.base.Funct
 ion;%0A
+%0A
 impo
@@ -157,22 +157,22 @@
 ow.core.
-IValue
+Domain
 ;%0Aimport
@@ -293,19 +293,19 @@
 low.
-model.Model
+core.IValue
 ;%0A%0Ap
@@ -333,18 +333,16 @@
  %7B%0A%0A
-  
+%09
 @Test%0A
-  
+%09
 publ
@@ -363,20 +363,64 @@
 est() %7B%0A
-    
+%0A%09%09final Domain domain = new Domain(%22test%22);%0A%0A%09%09
 final Mo
@@ -441,24 +441,28 @@
 w Model(
-);%0A%0A    
+domain);%0A%0A%09%09
 final IP
@@ -525,20 +525,18 @@
 , %22c%22);%0A
-    
+%09%09
 c.set(2)
@@ -534,28 +534,26 @@
 %09c.set(2);%0A%0A
-    
+%09%09
 final IPrope
@@ -612,20 +612,18 @@
 , %22d%22);%0A
-    
+%09%09
 d.set(3)
@@ -621,28 +621,26 @@
 %09d.set(3);%0A%0A
-    
+%09%09
 final IValue
@@ -653,20 +653,51 @@
 er%3E e = 
-new 
+domain.newExpression(new Function%3CI
 Expressi
@@ -699,16 +699,20 @@
 ression%3C
+?%3E, 
 Integer%3E
@@ -716,22 +716,19 @@
 er%3E() %7B%0A
-      
+%09%09%09
 @Overrid
@@ -733,54 +733,64 @@
 ide%0A
-      protected Integer calculate() %7B%0A        
+%09%09%09public Integer apply(final IExpression%3C?%3E dep) %7B%0A%09%09%09%09
 retu
@@ -798,20 +798,19 @@
 n c.get(
-this
+dep
 ) + d.ge
@@ -815,84 +815,57 @@
 get(
-this);%0A      %7D%0A    %7D;%0A%0A    Assert.assertEquals(e.get(IExpression.SIDE_EFFECT
+dep);%0A%09%09%09%7D%0A%09%09%7D);%0A%0A%09%09Assert.assertEquals(e.output(
 ), (
@@ -878,20 +878,18 @@
 r) 5);%0A%0A
-    
+%09%09
 final Mo
@@ -917,23 +917,27 @@
 w Model(
-);%0A    
+domain);%0A%09%09
 bReplace
@@ -966,20 +966,18 @@
 set(7);%0A
-    
+%09%09
 bReplace
@@ -1006,20 +1006,18 @@
 set(9);%0A
-    
+%09%09
 model.ge
@@ -1056,20 +1056,18 @@
 ment);%0A%0A
-    
+%09%09
 Assert.a
@@ -1097,113 +1097,69 @@
 , c.
-get(IExpression.SIDE_EFFECT));%0A    Assert.assertEquals((Integer) 9, d.get(IExpression.SIDE_EFFECT));%0A    
+output());%0A%09%09Assert.assertEquals((Integer) 9, d.output());%0A%09%09
 Asse
@@ -1194,41 +1194,20 @@
 , e.
-get(IExpression.SIDE_EFFECT
+output(
 ));%0A
-  
+%09
 %7D%0A%7D%0A

modify test