package org.avmframework.examples.inputdatageneration.line;

import org.avmframework.examples.inputdatageneration.ExecutionTrace;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class TestLineObjectiveFunction {

    @Test
    public void testTrace() {
        class LineObjectiveFunctionTrace extends LineBranchTargetObjectiveFunction {

            public LineObjectiveFunctionTrace() {
                super(null);
            }

            public ExecutionTrace getTrace(Line a, Line b) {
                trace = new ExecutionTrace();
                intersect(a, b);
                return trace;
            }
        }

        LineObjectiveFunctionTrace loft = new LineObjectiveFunctionTrace();

        // TODO: split these into three tests and update messages

        // Second line starts where first line ends
        ExecutionTrace t = loft.getTrace(new Line(10, 10, 20, 20), new Line(20, 20, 30, 30));
        assertEquals("ExecutionTrace should be of length 2", 2, t.getBranchExecutions().size());
        assertEquals("1st entry in 1st trace should be 1F", "1F", t.getBranchExecution(0).getBranch().toString());
        assertEquals("2nd entry in 1st trace should be 6T", "6T", t.getBranchExecution(1).getBranch().toString());

        // Intersection
        t = loft.getTrace(new Line(10, 10, 20, 20), new Line(10, 20, 20, 10));
        assertEquals("ExecutionTrace should be of length 5", 5, t.getBranchExecutions().size());
        assertEquals("1st entry in 2nd trace should be 1T", "1T", t.getBranchExecution(0).getBranch().toString());
        assertEquals("2nd entry in 2nd trace should be 2T", "2T", t.getBranchExecution(1).getBranch().toString());
        assertEquals("3rd entry in 2nd trace should be 3T", "3T", t.getBranchExecution(2).getBranch().toString());
        assertEquals("4th entry in 2nd trace should be 4T", "4T", t.getBranchExecution(3).getBranch().toString());
        assertEquals("5th entry in 2nd trace should be 5T", "5T", t.getBranchExecution(4).getBranch().toString());

        // Parallel
        t = loft.getTrace(new Line(10, 10, 20, 20), new Line(10, 20, 30, 40));
        assertEquals("ExecutionTrace should be of length 3", 3, t.getBranchExecutions().size());
        assertEquals("1st entry in 3rd trace should be 1F", "1F", t.getBranchExecution(0).getBranch().toString());
        assertEquals("2nd entry in 3rd trace should be 6F", "6F", t.getBranchExecution(1).getBranch().toString());
        assertEquals("3rd entry in 3rd trace should be 7F", "7F", t.getBranchExecution(2).getBranch().toString());
    }

}

@@ -239,52 +239,8 @@
  %7B%0A%0A
-    @Test%0A    public void testTrace() %7B%0A    
     
@@ -321,28 +321,24 @@
  %7B%0A%0A        
-    
 public LineO
@@ -375,20 +375,16 @@
         
-    
 super(nu
@@ -392,35 +392,27 @@
 l);%0A        
- 
-   %7D%0A%0A    
+%7D%0A%0A
         publ
@@ -468,20 +468,16 @@
         
-   
- 
 trace = 
@@ -498,20 +498,16 @@
 race();%0A
-    
         
@@ -539,20 +539,16 @@
         
-    
 return t
@@ -565,24 +565,90 @@
     
+%7D%0A
     %7D%0A
+%0A
     
-    %7D%0A
+@Test%0A    public void testTraceSecondLineStartsWhereFirstLineEnds() %7B
 %0A   
@@ -725,127 +725,8 @@
 );%0A%0A
-        // TODO: split these into three tests and update messages%0A%0A        // Second line starts where first line ends%0A
     
@@ -940,37 +940,24 @@
 (%221st entry 
-in 1st trace 
 should be 1F
@@ -1050,21 +1050,8 @@
 try 
-in 1st trace 
 shou
@@ -1120,40 +1120,168 @@
 ));%0A
-%0A        // Intersection%0A       
+    %7D%0A%0A    @Test%0A    public void testTraceLinesIntersect() %7B%0A        LineObjectiveFunctionTrace loft = new LineObjectiveFunctionTrace();%0A%0A        ExecutionTrace
  t =
@@ -1473,37 +1473,24 @@
 (%221st entry 
-in 2nd trace 
 should be 1T
@@ -1575,37 +1575,24 @@
 (%222nd entry 
-in 2nd trace 
 should be 2T
@@ -1677,37 +1677,24 @@
 (%223rd entry 
-in 2nd trace 
 should be 3T
@@ -1779,37 +1779,24 @@
 (%224th entry 
-in 2nd trace 
 should be 4T
@@ -1889,21 +1889,8 @@
 try 
-in 2nd trace 
 shou
@@ -1959,28 +1959,63 @@
 ));%0A
-%0A        // 
+    %7D%0A%0A    @Test%0A    public void testTraceLines
 Parallel
 %0A   
@@ -2010,16 +2010,20 @@
 Parallel
+() %7B
 %0A       
@@ -2023,16 +2023,108 @@
         
+LineObjectiveFunctionTrace loft = new LineObjectiveFunctionTrace();%0A%0A        ExecutionTrace 
 t = loft
@@ -2311,37 +2311,24 @@
 (%221st entry 
-in 3rd trace 
 should be 1F
@@ -2413,37 +2413,24 @@
 (%222nd entry 
-in 3rd trace 
 should be 6F
@@ -2523,21 +2523,8 @@
 try 
-in 3rd trace 
 shou

Split TestLineObjectiveFunction test into three separate tests