Skip to content

Commit 9453e11

Browse files
authored
Remove z3 string theory from String wrapper (#1050)
* Remove Z3 string theory support * Removed `UtNativeString`, `NativeStringWrapper`, string-related `UtExpression` subclasses * Implemented `toString` methods for numeric wrappers in Java * Restored temporarily disabled `testByteToString` test * Complex `GenericExamples` string tests are disabled until symbolic part of the wrapper is enabled. * Additional logging for `checkAllCombinations` * Fixed array offset in UtString.concat() * Updated compilation stage in (disabled) strings/GenericExamplesTest + updated string tests w.r.t. running without concrete execution
1 parent c41cd89 commit 9453e11

File tree

26 files changed

+402
-1476
lines changed

26 files changed

+402
-1476
lines changed

utbot-analytics/src/main/kotlin/org/utbot/features/UtExpressionStructureCounter.kt

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,6 @@ val featureIndex = listOf(
3434
UtBoolOpExpression::class.simpleName,
3535
UtIsExpression::class.simpleName,
3636
UtIteExpression::class.simpleName,
37-
UtStringConst::class.simpleName,
38-
UtConcatExpression::class.simpleName,
39-
UtConvertToString::class.simpleName,
40-
UtStringLength::class.simpleName,
41-
UtStringPositiveLength::class.simpleName,
42-
UtStringCharAt::class.simpleName,
43-
UtStringEq::class.simpleName,
44-
UtSubstringExpression::class.simpleName,
45-
UtReplaceExpression::class.simpleName,
46-
UtStartsWithExpression::class.simpleName,
47-
UtEndsWithExpression::class.simpleName,
48-
UtIndexOfExpression::class.simpleName,
49-
UtContainsExpression::class.simpleName,
50-
UtToStringExpression::class.simpleName,
51-
UtSeqLiteral::class.simpleName,
5237
TREES,
5338
MAX_NODES,
5439
MIN_NODES,
@@ -216,59 +201,6 @@ class UtExpressionStructureCounter(private val input: Iterable<UtExpression>) :
216201
)
217202
}
218203

219-
//const string value
220-
override fun visit(expr: UtStringConst) = NestStat()
221-
222-
override fun visit(expr: UtConcatExpression) = multipleExpression(expr.parts)
223-
224-
override fun visit(expr: UtConvertToString): NestStat {
225-
val stat = buildState(expr.expression)
226-
stat.level++
227-
stat.nodes++
228-
return stat
229-
}
230-
231-
override fun visit(expr: UtStringToInt): NestStat {
232-
val stat = buildState(expr.expression)
233-
stat.level++
234-
stat.nodes++
235-
return stat
236-
}
237-
238-
override fun visit(expr: UtStringLength): NestStat {
239-
val stat = buildState(expr.string)
240-
stat.level++
241-
stat.nodes++
242-
return stat
243-
}
244-
245-
override fun visit(expr: UtStringPositiveLength): NestStat {
246-
val stat = buildState(expr.string)
247-
stat.level++
248-
stat.nodes++
249-
return stat
250-
}
251-
252-
override fun visit(expr: UtStringCharAt) = multipleExpressions(expr.string, expr.index)
253-
254-
override fun visit(expr: UtStringEq) = multipleExpressions(expr.left, expr.right)
255-
256-
override fun visit(expr: UtSubstringExpression) = multipleExpressions(expr.string, expr.beginIndex, expr.length)
257-
258-
override fun visit(expr: UtReplaceExpression) = multipleExpressions(expr.string, expr.regex, expr.replacement)
259-
260-
override fun visit(expr: UtStartsWithExpression) = multipleExpressions(expr.string, expr.prefix)
261-
262-
override fun visit(expr: UtEndsWithExpression) = multipleExpressions(expr.string, expr.suffix)
263-
264-
override fun visit(expr: UtIndexOfExpression) = multipleExpressions(expr.string, expr.substring)
265-
266-
override fun visit(expr: UtContainsExpression) = multipleExpressions(expr.string, expr.substring)
267-
268-
override fun visit(expr: UtToStringExpression) = multipleExpressions(expr.notNullExpr, expr.isNull)
269-
270-
override fun visit(expr: UtSeqLiteral) = NestStat()
271-
272204
private fun multipleExpressions(vararg expressions: UtExpression) = multipleExpression(expressions.toList())
273205

274206
private fun multipleExpression(expressions: List<UtExpression>): NestStat {
@@ -311,14 +243,6 @@ class UtExpressionStructureCounter(private val input: Iterable<UtExpression>) :
311243
override fun visit(expr: UtArrayApplyForAll): NestStat {
312244
return NestStat()
313245
}
314-
315-
override fun visit(expr: UtStringToArray): NestStat {
316-
return NestStat()
317-
}
318-
319-
override fun visit(expr: UtArrayToString): NestStat {
320-
return NestStat()
321-
}
322246
}
323247

324248
data class NestStat(var nodes: Int = 1, var level: Int = 1)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.utbot.examples.strings
2+
3+
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
4+
import org.utbot.tests.infrastructure.isException
5+
import org.utbot.tests.infrastructure.CodeGeneration
6+
import org.utbot.framework.plugin.api.CodegenLanguage
7+
import org.junit.jupiter.api.Disabled
8+
import org.junit.jupiter.api.Test
9+
import org.utbot.testcheckers.eq
10+
11+
@Disabled("TODO: Fails and takes too long")
12+
internal class GenericExamplesTest : UtValueTestCaseChecker(
13+
testClass = GenericExamples::class,
14+
testCodeGeneration = true,
15+
pipelines = listOf(
16+
TestLastStage(CodegenLanguage.JAVA),
17+
TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration)
18+
)
19+
) {
20+
@Test
21+
fun testContainsOkWithIntegerType() {
22+
checkWithException(
23+
GenericExamples<Int>::containsOk,
24+
eq(2),
25+
{ obj, result -> obj == null && result.isException<NullPointerException>() },
26+
{ obj, result -> obj != null && result.isSuccess && result.getOrNull() == false }
27+
)
28+
}
29+
30+
@Test
31+
fun testContainsOkExampleTest() {
32+
check(
33+
GenericExamples<String>::containsOkExample,
34+
eq(1),
35+
{ result -> result == true }
36+
)
37+
}
38+
}

utbot-framework-test/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt

Lines changed: 110 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,32 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
2626
)
2727
) {
2828
@Test
29-
@Disabled("Flaky test: https://github.com/UnitTestBot/UTBotJava/issues/131 (will be enabled in new strings PR)")
3029
fun testByteToString() {
31-
// TODO related to the https://github.com/UnitTestBot/UTBotJava/issues/131
32-
withSolverTimeoutInMillis(5000) {
33-
check(
34-
StringExamples::byteToString,
35-
eq(2),
36-
{ a, b, r -> a > b && r == a.toString() },
37-
{ a, b, r -> a <= b && r == b.toString() },
38-
)
39-
}
30+
check(
31+
StringExamples::byteToString,
32+
eq(2),
33+
{ a, b, r -> a > b && r == a.toString() },
34+
{ a, b, r -> a <= b && r == b.toString() },
35+
)
36+
}
37+
38+
@Test
39+
fun testByteToStringWithConstants() {
40+
val values: Array<Byte> = arrayOf(
41+
Byte.MIN_VALUE,
42+
(Byte.MIN_VALUE + 100).toByte(),
43+
0.toByte(),
44+
(Byte.MAX_VALUE - 100).toByte(),
45+
Byte.MAX_VALUE
46+
)
47+
48+
val expected = values.map { it.toString() }
49+
50+
check(
51+
StringExamples::byteToStringWithConstants,
52+
eq(1),
53+
{ r -> r != null && r.indices.all { r[it] == expected[it] } }
54+
)
4055
}
4156

4257
@Test
@@ -53,45 +68,91 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
5368

5469
@Test
5570
fun testShortToString() {
56-
// TODO related to the https://github.com/UnitTestBot/UTBotJava/issues/131
57-
withSolverTimeoutInMillis(5000) {
58-
check(
59-
StringExamples::shortToString,
60-
eq(2),
61-
{ a, b, r -> a > b && r == a.toString() },
62-
{ a, b, r -> a <= b && r == b.toString() },
63-
)
64-
}
71+
check(
72+
StringExamples::shortToString,
73+
ignoreExecutionsNumber,
74+
{ a, b, r -> a > b && r == a.toString() },
75+
{ a, b, r -> a <= b && r == b.toString() },
76+
)
6577
}
6678

79+
@Test
80+
fun testShortToStringWithConstants() {
81+
val values: Array<Short> = arrayOf(
82+
Short.MIN_VALUE,
83+
(Short.MIN_VALUE + 100).toShort(),
84+
0.toShort(),
85+
(Short.MAX_VALUE - 100).toShort(),
86+
Short.MAX_VALUE
87+
)
88+
89+
val expected = values.map { it.toString() }
90+
91+
check(
92+
StringExamples::shortToStringWithConstants,
93+
eq(1),
94+
{ r -> r != null && r.indices.all { r[it] == expected[it] } }
95+
)
96+
}
6797

6898
@Test
6999
fun testIntToString() {
70-
// TODO related to the https://github.com/UnitTestBot/UTBotJava/issues/131
71-
withSolverTimeoutInMillis(5000) {
72-
check(
73-
StringExamples::intToString,
74-
ignoreExecutionsNumber,
75-
{ a, b, r -> a > b && r == a.toString() },
76-
{ a, b, r -> a <= b && r == b.toString() },
77-
)
78-
}
100+
check(
101+
StringExamples::intToString,
102+
ignoreExecutionsNumber,
103+
{ a, b, r -> a > b && r == a.toString() },
104+
{ a, b, r -> a <= b && r == b.toString() },
105+
)
79106
}
80107

108+
@Test
109+
fun testIntToStringWithConstants() {
110+
val values: Array<Int> = arrayOf(
111+
Integer.MIN_VALUE,
112+
Integer.MIN_VALUE + 100,
113+
0,
114+
Integer.MAX_VALUE - 100,
115+
Integer.MAX_VALUE
116+
)
117+
118+
val expected = values.map { it.toString() }
119+
120+
check(
121+
StringExamples::intToStringWithConstants,
122+
eq(1),
123+
{ r -> r != null && r.indices.all { r[it] == expected[it] } }
124+
)
125+
}
81126

82127
@Test
83128
fun testLongToString() {
84-
// TODO related to the https://github.com/UnitTestBot/UTBotJava/issues/131
85-
withSolverTimeoutInMillis(5000) {
86-
check(
87-
StringExamples::longToString,
88-
ignoreExecutionsNumber,
89-
{ a, b, r -> a > b && r == a.toString() },
90-
{ a, b, r -> a <= b && r == b.toString() },
91-
)
92-
}
129+
check(
130+
StringExamples::longToString,
131+
ignoreExecutionsNumber,
132+
{ a, b, r -> a > b && r == a.toString() },
133+
{ a, b, r -> a <= b && r == b.toString() },
134+
)
93135
}
94136

137+
@Test
138+
fun testLongToStringWithConstants() {
139+
val values: Array<Long> = arrayOf(
140+
Long.MIN_VALUE,
141+
Long.MIN_VALUE + 100L,
142+
0L,
143+
Long.MAX_VALUE - 100L,
144+
Long.MAX_VALUE
145+
)
146+
147+
val expected = values.map { it.toString() }
148+
149+
check(
150+
StringExamples::longToStringWithConstants,
151+
eq(1),
152+
{ r -> r != null && r.indices.all { r[it] == expected[it] } }
153+
)
154+
}
155+
95156
@Test
96157
fun testStartsWithLiteral() {
97158
check(
@@ -250,6 +311,15 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
250311
)
251312
}
252313

314+
@Test
315+
fun testIsStringBuilderEmpty() {
316+
check(
317+
StringExamples::isStringBuilderEmpty,
318+
eq(2),
319+
{ stringBuilder, result -> result == stringBuilder.isEmpty() }
320+
)
321+
}
322+
253323
@Test
254324
@Disabled("Flaky on GitHub: https://github.com/UnitTestBot/UTBotJava/issues/1004")
255325
fun testIsValidUuid() {
@@ -332,7 +402,7 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
332402
fun testSubstring() {
333403
checkWithException(
334404
StringExamples::substring,
335-
between(5..7),
405+
between(5..8),
336406
{ s, _, r -> s == null && r.isException<NullPointerException>() },
337407
{ s, i, r -> s != null && i < 0 || i > s.length && r.isException<StringIndexOutOfBoundsException>() },
338408
{ s, i, r -> s != null && i in 0..s.length && r.getOrThrow() == s.substring(i) && s.substring(i) != "password" },
@@ -585,13 +655,14 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
585655
withPushingStateFromPathSelectorForConcrete {
586656
check(
587657
StringExamples::equalsIgnoreCase,
588-
eq(2),
658+
ignoreExecutionsNumber,
589659
{ s, r -> "SUCCESS".equals(s, ignoreCase = true) && r == "success" },
590660
{ s, r -> !"SUCCESS".equals(s, ignoreCase = true) && r == "failure" },
591661
)
592662
}
593663
}
594664

665+
// TODO: This test fails without concrete execution as it uses a symbolic variable
595666
@Test
596667
fun testListToString() {
597668
check(

0 commit comments

Comments
 (0)