Skip to content

Commit 08bb161

Browse files
committed
Remove unsat states from invokes
1 parent 54a4f88 commit 08bb161

File tree

3 files changed

+38
-53
lines changed
  • utbot-framework/src/main/kotlin/org/utbot/engine
  • utbot-framework-test/src/test/kotlin/org/utbot/examples/collections
  • utbot-sample/src/main/java/org/utbot/examples/collections

3 files changed

+38
-53
lines changed

utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapsPart1Test.kt

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utbot.examples.collections
22

3+
import org.junit.jupiter.api.Tag
34
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
45
import org.utbot.tests.infrastructure.AtLeast
56
import org.utbot.tests.infrastructure.DoNotCalculate
@@ -10,6 +11,7 @@ import org.utbot.framework.plugin.api.MockStrategyApi
1011
import org.junit.jupiter.api.Test
1112
import org.utbot.testcheckers.eq
1213
import org.utbot.testcheckers.ge
14+
import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete
1315
import org.utbot.testcheckers.withoutMinimization
1416
import org.utbot.tests.infrastructure.CodeGeneration
1517

@@ -149,6 +151,17 @@ internal class MapsPart1Test : UtValueTestCaseChecker(
149151
)
150152
}
151153

154+
@Test
155+
@Tag("slow") // it takes about 20 minutes to execute this test
156+
fun testMapOperator() {
157+
withPushingStateFromPathSelectorForConcrete {
158+
check(
159+
Maps::mapOperator,
160+
ignoreExecutionsNumber
161+
)
162+
}
163+
}
164+
152165
@Test
153166
fun testComputeValue() {
154167
check(

utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt

+10-50
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,7 @@ import org.utbot.common.workaround
1515
import org.utbot.engine.overrides.UtArrayMock
1616
import org.utbot.engine.overrides.UtLogicMock
1717
import org.utbot.engine.overrides.UtOverrideMock
18-
import org.utbot.engine.pc.NotBoolExpression
19-
import org.utbot.engine.pc.UtAddNoOverflowExpression
20-
import org.utbot.engine.pc.UtAddrExpression
21-
import org.utbot.engine.pc.UtAndBoolExpression
22-
import org.utbot.engine.pc.UtArrayApplyForAll
23-
import org.utbot.engine.pc.UtArrayExpressionBase
24-
import org.utbot.engine.pc.UtArraySelectExpression
25-
import org.utbot.engine.pc.UtArraySetRange
26-
import org.utbot.engine.pc.UtArraySort
27-
import org.utbot.engine.pc.UtBoolExpression
28-
import org.utbot.engine.pc.UtBoolOpExpression
29-
import org.utbot.engine.pc.UtBvConst
30-
import org.utbot.engine.pc.UtBvLiteral
31-
import org.utbot.engine.pc.UtByteSort
32-
import org.utbot.engine.pc.UtCastExpression
33-
import org.utbot.engine.pc.UtCharSort
34-
import org.utbot.engine.pc.UtContextInitializer
35-
import org.utbot.engine.pc.UtExpression
36-
import org.utbot.engine.pc.UtFalse
37-
import org.utbot.engine.pc.UtInstanceOfExpression
38-
import org.utbot.engine.pc.UtIntSort
39-
import org.utbot.engine.pc.UtIsExpression
40-
import org.utbot.engine.pc.UtIteExpression
41-
import org.utbot.engine.pc.UtLongSort
42-
import org.utbot.engine.pc.UtMkTermArrayExpression
43-
import org.utbot.engine.pc.UtNegExpression
44-
import org.utbot.engine.pc.UtOrBoolExpression
45-
import org.utbot.engine.pc.UtPrimitiveSort
46-
import org.utbot.engine.pc.UtShortSort
47-
import org.utbot.engine.pc.UtSolver
48-
import org.utbot.engine.pc.UtSolverStatusSAT
49-
import org.utbot.engine.pc.UtSubNoOverflowExpression
50-
import org.utbot.engine.pc.UtTrue
51-
import org.utbot.engine.pc.addrEq
52-
import org.utbot.engine.pc.align
53-
import org.utbot.engine.pc.cast
54-
import org.utbot.engine.pc.findTheMostNestedAddr
55-
import org.utbot.engine.pc.isInteger
56-
import org.utbot.engine.pc.mkAnd
57-
import org.utbot.engine.pc.mkBVConst
58-
import org.utbot.engine.pc.mkBoolConst
59-
import org.utbot.engine.pc.mkChar
60-
import org.utbot.engine.pc.mkEq
61-
import org.utbot.engine.pc.mkFalse
62-
import org.utbot.engine.pc.mkFpConst
63-
import org.utbot.engine.pc.mkInt
64-
import org.utbot.engine.pc.mkNot
65-
import org.utbot.engine.pc.mkOr
66-
import org.utbot.engine.pc.select
67-
import org.utbot.engine.pc.store
18+
import org.utbot.engine.pc.*
6819
import org.utbot.engine.symbolic.emptyAssumption
6920
import org.utbot.engine.symbolic.emptyHardConstraint
7021
import org.utbot.engine.symbolic.emptySoftConstraint
@@ -2535,6 +2486,15 @@ class Traverser(
25352486
*/
25362487
val artificialMethodOverride = overrideInvocation(invocation, target = null)
25372488

2489+
// The problem here is that we might have an unsat current state.
2490+
// We get states with `SAT` last status only for traversing,
2491+
// but during the parameters resolving this status might be changed.
2492+
// It happens inside the `org.utbot.engine.Traverser.initStringLiteral` function.
2493+
// So, if it happens, we should just drop the state we processing now.
2494+
if (environment.state.solver.lastStatus is UtSolverStatusUNSAT) {
2495+
return mutableListOf()
2496+
}
2497+
25382498
// If so, return the result of the override
25392499
if (artificialMethodOverride.success) {
25402500
if (artificialMethodOverride.results.size > 1) {

utbot-sample/src/main/java/org/utbot/examples/collections/Maps.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package org.utbot.examples.collections;
22

3-
import java.util.HashMap;
4-
import java.util.LinkedHashMap;
5-
import java.util.Map;
3+
import java.util.*;
64

75
public class Maps {
86
Map<Integer, Integer> create(int[] keys, int[] values) {
@@ -245,4 +243,18 @@ CustomClass removeCustomObject(Map<CustomClass, CustomClass> map, int i) {
245243
return removed;
246244
}
247245
}
246+
247+
public List<String> mapOperator(Map<String, String> map) {
248+
List<String> result = new ArrayList<>();
249+
for (Map.Entry<String, String> entry : map.entrySet()) {
250+
if (entry.getValue().equals("key")) {
251+
result.add(entry.getKey());
252+
}
253+
}
254+
if (result.size() > 1) {
255+
return result;
256+
} else {
257+
return new ArrayList<>(map.values());
258+
}
259+
}
248260
}

0 commit comments

Comments
 (0)