<commit_before>package edu.kit.iti.formal.pse.worthwhile.interpreter;

import static org.junit.Assert.*;
import java.math.BigInteger;

import org.junit.Before;
import org.junit.Test;
import edu.kit.iti.formal.pse.worthwhile.common.tests.TestASTProvider;
import edu.kit.iti.formal.pse.worthwhile.model.ast.Statement;

public class InterpreterExecutionEventListenerTest {
	
	public boolean test;
	Interpreter interpreter;
	
	@Before
	public void intitialize() {
		this.test = false;
	}
	
	@Test
	public void testStatementExecuted() {
		AbstractExecutionEventListener listener = new AbstractExecutionEventListener() {
			public void statementExecuted(Statement statement) {
				test = true;
			}
		};
		
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("Boolean a := true\n")), listener);
		this.interpreter.execute();
		assertTrue(this.test);
		//this.reset(new Interpreter(TestASTProvider.getRootASTNode("Integer a := 5\n")), listener);
		
	}
	
	@Test
	public void testStatementWillExecute() {
		AbstractExecutionEventListener listener = new AbstractExecutionEventListener() {
			public void statementWillExecute(Statement statement) {
				test = true;
			}
		};
		
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("Boolean a := true\n")), listener);
		this.interpreter.execute();
		assertTrue(this.test);
	}
	
	
	@Test
	public void testExecutionFailed() {
		AbstractExecutionEventListener listener = new AbstractExecutionEventListener() {
			public void executionFailed(Statement statement, InterpreterError interpreterError) {
				test = true;
			}
		};
		
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("Boolean a := true\n")), listener);
		this.interpreter.execute();
		assertTrue(this.test);
	}
	
	private void reset(Interpreter inter, AbstractExecutionEventListener listener ) {
		this.interpreter = inter;
		this.interpreter.addExecutionEventHandler(listener);
		this.test = false;
	}
}<commit_msg>[interpreter.tests] Complete test for method statementExecuted() and statementWillExecute() so far<commit_after>package edu.kit.iti.formal.pse.worthwhile.interpreter;

import static org.junit.Assert.*;
import java.math.BigInteger;

import org.junit.Before;
import org.junit.Test;
import edu.kit.iti.formal.pse.worthwhile.common.tests.TestASTProvider;
import edu.kit.iti.formal.pse.worthwhile.model.ast.Statement;

public class InterpreterExecutionEventListenerTest {
	
	public boolean test;
	public int counter;
	Interpreter interpreter;
	
	@Before
	public void intitialize() {
		this.test = false;
	}
	
	private void testStatements(AbstractExecutionEventListener listener) {
		//Boolean VariableDeclaration
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("Boolean a := true\n")), listener);
		assertFalse(this.test);
		this.interpreter.execute();
		assertTrue(this.test);
		
		//Integer VariableDeclaration
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("Integer a := 5\n")), listener);
		assertFalse(this.test);
		this.interpreter.execute();
		assertTrue(this.test);
		
		//Boolean Assignment
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("Boolean a := true\na := false\n")), listener);
		assertEquals(this.counter, 0);
		this.interpreter.execute();
		assertEquals(this.counter, 2);
		
		//Integer Assignment
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("Integer a := 5\na := 4\n")), listener);
		assertEquals(this.counter, 0);
		this.interpreter.execute();
		assertEquals(this.counter, 2);
		
		//Loop
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("while(false)\n")), listener);
		assertFalse(this.test);
		this.interpreter.execute();
		assertTrue(this.test);
		
		//Precondition Annotation
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("function Boolean test()\n_requires(true)\n{\n}\ntest()\n")), listener);
		assertEquals(this.counter, 0);
		this.interpreter.execute();
		assertEquals(this.counter, 2);
		
		//Postcondition Annotation
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("function Boolean test()\n{\n}\n_ensures(true)\ntest()\n")), listener);
		assertEquals(this.counter, 0);
		this.interpreter.execute();
		assertEquals(this.counter, 2);
		
		//Assertion Annotation
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("_assert(true)\n")), listener);
		assertFalse(this.test);
		this.interpreter.execute();
		assertTrue(this.test);
		
		//Assumption Annotation
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("_assume(true)\n")), listener);
		assertFalse(this.test);
		this.interpreter.execute();
		assertTrue(this.test);
		
		//Axiom Annotation
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("_axiom(true)\n")), listener);
		assertFalse(this.test);
		this.interpreter.execute();
		assertTrue(this.test);
		
		//Condition
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("if(true) {\n}\n")), listener);
		assertFalse(this.test);
		this.interpreter.execute();
		assertTrue(this.test);
		
		//Boolean ReturnStatement
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("function Boolean test() {\nreturn true\n}\ntest()\n")), listener);
		assertEquals(this.counter, 0);
		this.interpreter.execute();
		assertEquals(this.counter, 2);
		
		//Integer ReturnStatement
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("function Integer test() {\nreturn 3\n}\ntest()\n")), listener);
		assertEquals(this.counter, 0);
		this.interpreter.execute();
		assertEquals(this.counter, 2);
	}
	
	@Test
	public void testStatementExecuted() {
		AbstractExecutionEventListener listener = new AbstractExecutionEventListener() {
			public void statementExecuted(Statement statement) {
				test = true;
				counter++;
			}
		};
		
		this.testStatements(listener);
	}
	
	@Test
	public void testStatementWillExecute() {
		AbstractExecutionEventListener listener = new AbstractExecutionEventListener() {
			public void statementWillExecute(Statement statement) {
				test = true;
				counter++;
			}
		};
		
		this.testStatements(listener);
	}
	
	
	@Test
	public void testExecutionFailed() {
		AbstractExecutionEventListener listener = new AbstractExecutionEventListener() {
			public void executionFailed(Statement statement, InterpreterError interpreterError) {
				test = true;
			}
		};
		
		this.reset(new Interpreter(TestASTProvider.getRootASTNode("Boolean a := true\n")), listener);
		this.interpreter.execute();
		assertTrue(this.test);
	}
	
	private void reset(Interpreter inter, AbstractExecutionEventListener listener ) {
		this.interpreter = inter;
		this.interpreter.addExecutionEventHandler(listener);
		this.test = false;
		this.counter = 0;
	}
}
{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.002707581227436823, 'mean_word_length': 5.167903525046382, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '837272', 'n_tokens_mistral': 2177, 'n_tokens_neox': 1978, 'n_words': 360}