AbsStepDefault test

This commit is contained in:
uogau 2021-02-08 12:47:52 +01:00
parent 8ffcac164a
commit addbe90dcf
2 changed files with 109 additions and 0 deletions

View File

@ -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<VarTerm, TypeAbstraction> 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);
}
}

View File

@ -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";
}
}