package edu.kit.iti.formal.pse.worthwhile.interpreter;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import edu.kit.iti.formal.pse.worthwhile.common.tests.TestASTProvider;
import edu.kit.iti.formal.pse.worthwhile.model.ast.Annotation;
import edu.kit.iti.formal.pse.worthwhile.model.ast.Program;
import edu.kit.iti.formal.pse.worthwhile.prover.SpecificationChecker;

public class InterpreterValueTest {

	@Test
	public void testArrayAssignments() {
		Program testProgram = TestASTProvider
		                .getRootASTNode("Integer[] j := {1, 2, 43}\nj[5] := 9\n_assert j[2] ≠ 9\n");
		Interpreter interpreter = new Interpreter(testProgram, new SpecificationChecker());
		WorthwhileTestExecutionListener listener = new WorthwhileTestExecutionListener() {

			@Override
                        public void annotationSucceeded(Annotation annotation) {
	                        this.check = true;
                        }
			
			@Override
			public void annotationFailed(Annotation annotation) {
				this.check = false;
			}
			
		};
		interpreter.addExecutionEventHandler(listener);
		
		interpreter.execute();
		assertEquals(true, listener.check);
	}
	
}

@@ -94,16 +94,98 @@
 Equals;%0A
+import java.io.IOException;%0Aimport java.math.BigInteger;%0A%0Aimport org.junit.Assert;
 %0Aimport 
@@ -272,16 +272,77 @@
 ovider;%0A
+import edu.kit.iti.formal.pse.worthwhile.model.IntegerValue;%0A
 import e
@@ -456,16 +456,78 @@
 rogram;%0A
+import edu.kit.iti.formal.pse.worthwhile.model.ast.Statement;%0A
 import e
@@ -1375,10 +1375,879 @@
 );%0A%09%7D%0A%09%0A
+%09%0A%09@Test%0A%09public void testReturnStatmentExit() throws IOException %7B%0A%09%09// the testFunction should return after the first return statement, so it should return 20.%0A%09%09Program program = TestASTProvider.getRootASTNode(%22function Integer testFunction () %7B%5Cn if (true) %7B%5Cn return 20%5Cn%7D%5Cn return 10%5Cn return 0%5Cn %7D%5Cn Integer a := testFunction()%5Cn%22);%0A%09%09final Interpreter interpreter = new Interpreter(program, new SpecificationChecker());%0A%09%09%0A%09%09interpreter.addExecutionEventHandler(new AbstractExecutionEventListener() %7B%0A%09%09%09@Override%0A%09%09%09public void statementExecuted(Statement statement) %7B%0A%09%09%09%09if (interpreter.getSymbol(%22a%22) != null) %7B%0A%09%09%09%09%09Assert.assertTrue(interpreter.getSymbol(%22a%22) instanceof IntegerValue);%0A%09%09%09%09%09Assert.assertEquals(new BigInteger(%2220%22),%0A%09%09%09%09%09%09%09((IntegerValue) interpreter.getSymbol(%22a%22))%0A%09%09%09%09%09%09%09%09%09.getValue());%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09interpreter.execute();%0A%09%09%0A%09%7D%0A
 %7D%0A

Add test for "function returns after the first return statement".