From addbe90dcfb9ada04a41bbbc9620cda35ae1340a Mon Sep 17 00:00:00 2001 From: uogau Date: Mon, 8 Feb 2021 12:47:52 +0100 Subject: [PATCH] AbsStepDefault test --- .../model/step/AbsStepDefaultTest.java | 65 +++++++++++++++++++ .../typicalc/model/step/TestStepVisitor.java | 44 +++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 src/test/java/edu/kit/typicalc/model/step/AbsStepDefaultTest.java create mode 100644 src/test/java/edu/kit/typicalc/model/step/TestStepVisitor.java diff --git a/src/test/java/edu/kit/typicalc/model/step/AbsStepDefaultTest.java b/src/test/java/edu/kit/typicalc/model/step/AbsStepDefaultTest.java new file mode 100644 index 0000000..c8e7536 --- /dev/null +++ b/src/test/java/edu/kit/typicalc/model/step/AbsStepDefaultTest.java @@ -0,0 +1,65 @@ +package edu.kit.typicalc.model.step; + +import edu.kit.typicalc.model.Conclusion; +import edu.kit.typicalc.model.Constraint; +import edu.kit.typicalc.model.term.IntegerTerm; +import edu.kit.typicalc.model.term.VarTerm; +import edu.kit.typicalc.model.type.NamedType; +import edu.kit.typicalc.model.type.TypeAbstraction; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeAll; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; + +class AbsStepDefaultTest { + static InferenceStep premise = null; + static Conclusion conclusion = null; + static Constraint constraint = null; + static NamedType namedType = null; + static TypeAbstraction typeAbstraction = null; + @BeforeAll + static void setUp() { + Map map = new HashMap<>(); + VarTerm term = new VarTerm("test"); + namedType = new NamedType("testType"); + typeAbstraction = new TypeAbstraction(namedType); + map.put(term, typeAbstraction); + IntegerTerm integerTerm = new IntegerTerm(1); + conclusion = new Conclusion(map, integerTerm, namedType); + NamedType type1 = new NamedType("a"); + NamedType type2 = new NamedType("b"); + constraint = new Constraint(type1, type2); + premise = new ConstStepDefault(conclusion, constraint); + } + @Test + void equalsTest() { + AbsStepDefault step1 = new AbsStepDefault(premise, conclusion, constraint); + AbsStepDefault step2 = new AbsStepDefault(premise, conclusion, constraint); + AbsStepDefault step3 = new AbsStepDefault(premise, conclusion, null); + + assertEquals(step1, step1); + assertEquals(step1, step2); + assertNotEquals(null, step1); + assertNotEquals(step1, step3); + + } + @Test + void hashCodeTest() { + AbsStepDefault step1 = new AbsStepDefault(premise, conclusion, constraint); + AbsStepDefault step2 = new AbsStepDefault(premise, conclusion, constraint); + + assertEquals(step1.hashCode(), step2.hashCode()); + } + + @Test + void acceptTest() { + TestStepVisitor testStepVisitor = new TestStepVisitor(); + AbsStepDefault step = new AbsStepDefault(premise, conclusion, constraint); + step.accept(testStepVisitor); + assertEquals("AbsDef", testStepVisitor.visited); + } + +} \ No newline at end of file diff --git a/src/test/java/edu/kit/typicalc/model/step/TestStepVisitor.java b/src/test/java/edu/kit/typicalc/model/step/TestStepVisitor.java new file mode 100644 index 0000000..82604bf --- /dev/null +++ b/src/test/java/edu/kit/typicalc/model/step/TestStepVisitor.java @@ -0,0 +1,44 @@ +package edu.kit.typicalc.model.step; + +public class TestStepVisitor implements StepVisitor { + public String visited = ""; + @Override + public void visit(AbsStepDefault absD) { + visited = "AbsDef"; + } + + @Override + public void visit(AbsStepWithLet absL) { + visited = "AbsLet"; + } + + @Override + public void visit(AppStepDefault appD) { + visited = "AppDef"; + } + + @Override + public void visit(ConstStepDefault constD) { + visited = "ConstDef"; + } + + @Override + public void visit(VarStepDefault varD) { + visited = "VarDef"; + } + + @Override + public void visit(VarStepWithLet varL) { + visited = "VarLet"; + } + + @Override + public void visit(LetStepDefault letD) { + visited = "LetDef"; + } + + @Override + public void visit(EmptyStep empty) { + visited = "empty"; + } +}