Skip to content

Commit 5eca3db

Browse files
committed
Fix compilation errors in integration tests
- Use setters instead of non-existent constructors for RefinedFunction - Create GhostState directly (public constructor) instead of GhostFunction (protected) - Remove AliasWrapper tests since constructor requires AliasDTO - Fix all type parameters to use proper List<CtTypeReference<?>> - All tests now use builder pattern with setters
1 parent 050ca47 commit 5eca3db

File tree

2 files changed

+109
-111
lines changed

2 files changed

+109
-111
lines changed

liquidjava-verifier/src/test/java/liquidjava/integration/ContextIntegrationTest.java

Lines changed: 52 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ void testCompleteVariableLifecycle() {
7878
void testFunctionRegistrationAndRetrieval() {
7979
// Scenario: Register functions with refinements and retrieve them
8080
CtTypeReference<Integer> intType = factory.Type().integerPrimitiveType();
81-
CtTypeReference<String> stringType = factory.Type().stringType();
8281

8382
// Create function with arguments and return refinement
84-
RefinedFunction func = new RefinedFunction("calculate", "MathUtils", intType, new Predicate());
83+
RefinedFunction func = new RefinedFunction();
84+
func.setName("calculate");
85+
func.setClass("MathUtils");
86+
func.setType(intType);
8587
func.addArgRefinements("x", intType, Predicate.createOperation(
8688
Predicate.createVar("x"), ">", Predicate.createLit("0", "int")
8789
));
@@ -100,7 +102,10 @@ void testFunctionRegistrationAndRetrieval() {
100102
assertEquals(2, retrieved.getArguments().size(), "Should have 2 arguments");
101103

102104
// Add another function with same name but different arity
103-
RefinedFunction func2 = new RefinedFunction("calculate", "MathUtils", intType, new Predicate());
105+
RefinedFunction func2 = new RefinedFunction();
106+
func2.setName("calculate");
107+
func2.setClass("MathUtils");
108+
func2.setType(intType);
104109
func2.addArgRefinements("x", intType, new Predicate());
105110
context.addFunctionToContext(func2);
106111

@@ -112,60 +117,34 @@ void testFunctionRegistrationAndRetrieval() {
112117
}
113118

114119
@Test
115-
void testGhostFunctionsAndStates() {
116-
// Scenario: Register ghost functions and states, verify hierarchy
117-
GhostFunction ghost1 = new GhostFunction("ghostPredicate", List.of(), factory.Type().booleanPrimitiveType(), "TestClass");
118-
context.addGhostFunction(ghost1);
119-
assertTrue(context.hasGhost("TestClass.ghostPredicate"), "Should find ghost by qualified name");
120-
assertTrue(context.hasGhost("ghostPredicate"), "Should find ghost by simple name");
121-
122-
// Add ghost class with states
123-
context.addGhostClass("StateManager");
124-
GhostState state1 = new GhostState("StateManager", "initialized", null, null);
125-
state1.setRefinement(Predicate.createLit("true", "boolean"));
126-
context.addToGhostClass("StateManager", state1);
127-
128-
GhostState state2 = new GhostState("StateManager", "ready", null, null);
129-
state2.setRefinement(Predicate.createVar("initialized"));
130-
context.addToGhostClass("StateManager", state2);
131-
132-
List<GhostState> states = context.getGhostState("StateManager");
133-
assertEquals(2, states.size(), "Should have 2 states");
134-
135-
// Verify state refinements
136-
assertTrue(states.get(0).getRefinement().toString().contains("true"));
137-
assertTrue(states.get(1).getRefinement().toString().contains("initialized"));
138-
}
120+
void testGhostStatesAndRefinements() {
121+
// Scenario: Register ghost states and verify refinements
122+
context.addGhostClass("Stack");
123+
124+
// Define states using GhostState
125+
List<CtTypeReference<?>> emptyList = List.of();
126+
GhostState isEmpty = new GhostState("Stack", "isEmpty", emptyList, factory.Type().booleanPrimitiveType(), "Stack");
127+
isEmpty.setRefinement(Predicate.createEquals(
128+
Predicate.createInvocation("Stack.size", Predicate.createVar("this")),
129+
Predicate.createLit("0", "int")
130+
));
139131

140-
@Test
141-
void testAliasManagement() {
142-
// Scenario: Register and use aliases for complex predicates
143-
Predicate complexPred = Predicate.createOperation(
144-
Predicate.createOperation(
145-
Predicate.createVar("x"),
146-
"*",
147-
Predicate.createVar("x")
148-
),
149-
"+",
150-
Predicate.createOperation(
151-
Predicate.createVar("y"),
152-
"*",
153-
Predicate.createVar("y")
154-
)
155-
);
132+
GhostState isNonEmpty = new GhostState("Stack", "isNonEmpty", emptyList, factory.Type().booleanPrimitiveType(), "Stack");
133+
isNonEmpty.setRefinement(Predicate.createOperation(
134+
Predicate.createInvocation("Stack.size", Predicate.createVar("this")),
135+
">",
136+
Predicate.createLit("0", "int")
137+
));
156138

157-
AliasWrapper alias = new AliasWrapper("distanceSquared", complexPred,
158-
List.of("x", "y"), List.of("int", "int"));
159-
context.addAlias(alias);
139+
context.addToGhostClass("Stack", isEmpty);
140+
context.addToGhostClass("Stack", isNonEmpty);
160141

161-
List<AliasWrapper> aliases = context.getAlias();
162-
assertEquals(1, aliases.size(), "Should have 1 alias");
163-
assertEquals("distanceSquared", aliases.get(0).getName());
142+
List<GhostState> states = context.getGhostState("Stack");
143+
assertEquals(2, states.size(), "Should have 2 states");
164144

165-
// Create new variables for substitution
166-
List<String> newVars = alias.getNewVariables(context);
167-
assertEquals(2, newVars.size(), "Should generate 2 new variable names");
168-
assertTrue(newVars.get(0).contains("alias_x"), "Generated name should contain original");
145+
// Verify state refinements
146+
assertTrue(states.get(0).getRefinement().toString().contains("0"));
147+
assertTrue(states.get(1).getRefinement().toString().contains(">"));
169148
}
170149

171150
@Test
@@ -233,17 +212,18 @@ void testIfBranchCombination() {
233212

234213
@Test
235214
void testComplexScenarioWithMultipleComponents() {
236-
// Realistic scenario: Function with refinements, variables, and ghosts
215+
// Realistic scenario: Function with refinements and variables
237216
CtTypeReference<Integer> intType = factory.Type().integerPrimitiveType();
238217

239-
// Register a ghost function for validation
240-
GhostFunction validationGhost = new GhostFunction("isValid",
241-
List.of(intType), factory.Type().booleanPrimitiveType(), "Validator");
242-
context.addGhostFunction(validationGhost);
218+
// Create function with precondition
219+
RefinedFunction processFunc = new RefinedFunction();
220+
processFunc.setName("process");
221+
processFunc.setClass("Processor");
222+
processFunc.setType(intType);
243223

244-
// Create function with precondition using ghost
245-
RefinedFunction processFunc = new RefinedFunction("process", "Processor", intType, new Predicate());
246-
Predicate precondition = Predicate.createInvocation("Validator.isValid", Predicate.createVar("input"));
224+
Predicate precondition = Predicate.createOperation(
225+
Predicate.createVar("input"), ">", Predicate.createLit("0", "int")
226+
);
247227
processFunc.addArgRefinements("input", intType, precondition);
248228

249229
Predicate postcondition = Predicate.createOperation(
@@ -258,7 +238,6 @@ void testComplexScenarioWithMultipleComponents() {
258238
context.addVarToContext("result", intType, postcondition, null);
259239

260240
// Verify everything is integrated
261-
assertTrue(context.hasGhost("Validator.isValid"), "Ghost function registered");
262241
assertNotNull(context.getFunction("process", "Processor"), "Function registered");
263242
assertTrue(context.hasVariable("input"), "Input variable exists");
264243
assertTrue(context.hasVariable("result"), "Result variable exists");
@@ -300,4 +279,15 @@ void testCounterIncrement() {
300279
assertTrue(counter3 > counter2, "Counter should continue incrementing");
301280
assertEquals(1, counter2 - counter1, "Should increment by 1");
302281
}
282+
283+
@Test
284+
void testContextToString() {
285+
// Test context string representation
286+
CtTypeReference<Integer> intType = factory.Type().integerPrimitiveType();
287+
context.addVarToContext("x", intType, new Predicate(), null);
288+
289+
String result = context.toString();
290+
assertNotNull(result, "toString should not return null");
291+
assertTrue(result.contains("Variables"), "Should contain Variables section");
292+
}
303293
}

liquidjava-verifier/src/test/java/liquidjava/integration/VerificationWorkflowIntegrationTest.java

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.junit.jupiter.api.Assertions.*;
44

55
import java.util.List;
6-
import java.util.Map;
76

87
import liquidjava.processor.context.*;
98
import liquidjava.rj_language.Predicate;
@@ -87,7 +86,10 @@ void testFunctionPreconditionPostconditionWorkflow() {
8786
CtTypeReference<Integer> intType = factory.Type().integerPrimitiveType();
8887

8988
// Create function: int divide(int x, int y) with precondition y != 0
90-
RefinedFunction divideFunc = new RefinedFunction("divide", "MathUtils", intType, new Predicate());
89+
RefinedFunction divideFunc = new RefinedFunction();
90+
divideFunc.setName("divide");
91+
divideFunc.setClass("MathUtils");
92+
divideFunc.setType(intType);
9193

9294
// Precondition: y != 0
9395
Predicate yNotZero = Predicate.createOperation(
@@ -166,54 +168,20 @@ void testCompleteVariableRefinementWorkflow() {
166168
assertTrue(allVars.stream().anyMatch(v -> v.getName().equals("x")));
167169
}
168170

169-
@Test
170-
void testAliasExpansionWorkflow() {
171-
// Define an alias and expand it in expressions
172-
Predicate aliasDef = Predicate.createOperation(
173-
Predicate.createOperation(
174-
Predicate.createVar("x"),
175-
"*",
176-
Predicate.createVar("x")
177-
),
178-
"+",
179-
Predicate.createOperation(
180-
Predicate.createVar("y"),
181-
"*",
182-
Predicate.createVar("y")
183-
)
184-
);
185-
186-
AliasWrapper distanceSquared = new AliasWrapper(
187-
"distanceSquared", aliasDef, List.of("x", "y"), List.of("int", "int")
188-
);
189-
context.addAlias(distanceSquared);
190-
191-
// Generate new variables for substitution
192-
List<String> newVars = distanceSquared.getNewVariables(context);
193-
assertEquals(2, newVars.size(), "Should generate 2 new variables");
194-
195-
// Get expanded expression with new variables
196-
liquidjava.rj_language.ast.Expression expanded = distanceSquared.getNewExpression(newVars);
197-
assertNotNull(expanded, "Expanded expression should not be null");
198-
199-
String expandedStr = expanded.toString();
200-
assertTrue(expandedStr.contains(newVars.get(0).substring(0, Math.min(10, newVars.get(0).length()))),
201-
"Should contain first new variable");
202-
}
203-
204171
@Test
205172
void testGhostStateVerificationWorkflow() {
206173
// Scenario: Define ghost states and track state transitions
207174
context.addGhostClass("Stack");
208175

209176
// Define states
210-
GhostState empty = new GhostState("Stack", "isEmpty", null, null);
177+
List<CtTypeReference<?>> emptyList = List.of();
178+
GhostState empty = new GhostState("Stack", "isEmpty", emptyList, factory.Type().booleanPrimitiveType(), "Stack");
211179
empty.setRefinement(Predicate.createEquals(
212180
Predicate.createInvocation("Stack.size", Predicate.createVar("this")),
213181
Predicate.createLit("0", "int")
214182
));
215183

216-
GhostState nonEmpty = new GhostState("Stack", "isNonEmpty", null, null);
184+
GhostState nonEmpty = new GhostState("Stack", "isNonEmpty", emptyList, factory.Type().booleanPrimitiveType(), "Stack");
217185
nonEmpty.setRefinement(Predicate.createOperation(
218186
Predicate.createInvocation("Stack.size", Predicate.createVar("this")),
219187
">",
@@ -239,16 +207,25 @@ void testMethodOverloadingResolution() {
239207
CtTypeReference<String> stringType = factory.Type().stringType();
240208

241209
// Add overloaded methods: process(int), process(int, int), process(String)
242-
RefinedFunction process1 = new RefinedFunction("process", "Processor", intType, new Predicate());
210+
RefinedFunction process1 = new RefinedFunction();
211+
process1.setName("process");
212+
process1.setClass("Processor");
213+
process1.setType(intType);
243214
process1.addArgRefinements("x", intType, new Predicate());
244215
context.addFunctionToContext(process1);
245216

246-
RefinedFunction process2 = new RefinedFunction("process", "Processor", intType, new Predicate());
217+
RefinedFunction process2 = new RefinedFunction();
218+
process2.setName("process");
219+
process2.setClass("Processor");
220+
process2.setType(intType);
247221
process2.addArgRefinements("x", intType, new Predicate());
248222
process2.addArgRefinements("y", intType, new Predicate());
249223
context.addFunctionToContext(process2);
250224

251-
RefinedFunction process3 = new RefinedFunction("process", "Processor", intType, new Predicate());
225+
RefinedFunction process3 = new RefinedFunction();
226+
process3.setName("process");
227+
process3.setClass("Processor");
228+
process3.setType(intType);
252229
process3.addArgRefinements("s", stringType, new Predicate());
253230
context.addFunctionToContext(process3);
254231

@@ -348,25 +325,56 @@ void testContextResetPreservesGlobals() {
348325
context.addGlobalVariableToContext("GLOBAL_MAX", intType,
349326
Predicate.createLit("100", "int"));
350327

351-
// Add ghost function
352-
GhostFunction ghost = new GhostFunction("validate",
353-
List.of(intType), factory.Type().booleanPrimitiveType(), "Validator");
354-
context.addGhostFunction(ghost);
355-
356328
// Add local variable
357329
context.addVarToContext("local", intType, new Predicate(), null);
358330

359331
// Add function
360-
RefinedFunction func = new RefinedFunction("test", "TestClass", intType, new Predicate());
332+
RefinedFunction func = new RefinedFunction();
333+
func.setName("test");
334+
func.setClass("TestClass");
335+
func.setType(intType);
361336
context.addFunctionToContext(func);
362337

363338
// Reinitialize (not all)
364339
context.reinitializeContext();
365340

366341
// Check what persists
367342
assertTrue(context.hasVariable("GLOBAL_MAX"), "Global variable persists");
368-
assertTrue(context.hasGhost("Validator.validate"), "Ghost persists");
369343
assertNotNull(context.getFunction("test", "TestClass"), "Function persists");
370344
assertFalse(context.hasVariable("local"), "Local variable cleared");
371345
}
346+
347+
@Test
348+
void testStringUtilityFunctions() {
349+
// Test string utility functions
350+
String stripped = Utils.stripParens("(expression)");
351+
assertEquals("expression", stripped, "Parens should be stripped");
352+
353+
String notStripped = Utils.stripParens("expression");
354+
assertEquals("expression", notStripped, "Non-paren string unchanged");
355+
356+
String emptyParens = Utils.stripParens("()");
357+
assertEquals("", emptyParens, "Empty parens result in empty string");
358+
}
359+
360+
@Test
361+
void testVariableInstanceParenting() {
362+
// Test parent-child relationship between Variable and VariableInstance
363+
CtTypeReference<Integer> intType = factory.Type().integerPrimitiveType();
364+
365+
Variable parent = new Variable("x", intType, new Predicate());
366+
context.addVarToContext(parent);
367+
368+
VariableInstance child = new VariableInstance("x_1", intType,
369+
Predicate.createEquals(Predicate.createVar("x_1"), Predicate.createLit("5", "int")));
370+
371+
parent.addInstance(child);
372+
context.addSpecificVariable(child);
373+
context.addRefinementInstanceToVariable("x", "x_1");
374+
375+
// Verify relationship
376+
Variable retrievedParent = context.getVariableFromInstance(child);
377+
assertNotNull(retrievedParent, "Should find parent");
378+
assertEquals(parent, retrievedParent, "Parent should match");
379+
}
372380
}

0 commit comments

Comments
 (0)