Skip to content

Commit 91617cb

Browse files
committed
Move summary tests from engine checks to separate summary tests
1 parent 1fff77c commit 91617cb

File tree

9 files changed

+266
-227
lines changed

9 files changed

+266
-227
lines changed

utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/BinarySearchTest.kt

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package org.utbot.examples.algorithms
22

3-
import org.utbot.framework.plugin.api.DocCodeStmt
4-
import org.utbot.framework.plugin.api.DocPreTagStatement
5-
import org.utbot.framework.plugin.api.DocRegularStmt
6-
import org.utbot.framework.plugin.api.DocStatement
73
import org.junit.jupiter.api.Test
84
import org.utbot.testing.UtValueTestCaseChecker
95
import org.utbot.testing.ignoreExecutionsNumber
@@ -12,60 +8,14 @@ import org.utbot.testing.isException
128
class BinarySearchTest : UtValueTestCaseChecker(testClass = BinarySearch::class,) {
139
@Test
1410
fun testLeftBinarySearch() {
15-
val fullSummary = listOf<DocStatement>(
16-
DocPreTagStatement(
17-
listOf(
18-
DocRegularStmt("Test "),
19-
DocRegularStmt("does not iterate "),
20-
DocCodeStmt("while(left < right - 1)"),
21-
DocRegularStmt(", "),
22-
DocRegularStmt("executes conditions:\n"),
23-
DocRegularStmt(" "),
24-
DocCodeStmt("(found): False"),
25-
DocRegularStmt("\n"),
26-
DocRegularStmt("returns from: "),
27-
DocCodeStmt("return -1;"),
28-
DocRegularStmt("\n")
29-
30-
)
31-
)
32-
)
3311
checkWithException(
3412
BinarySearch::leftBinSearch,
3513
ignoreExecutionsNumber,
3614
{ a, _, r -> a == null && r.isException<NullPointerException>() },
3715
{ a, _, r -> a.size >= 2 && a[0] > a[1] && r.isException<IllegalArgumentException>() },
3816
{ a, _, r -> a.isEmpty() && r.getOrNull() == -1 },
3917
{ a, key, r -> a.isNotEmpty() && key >= a[(a.size - 1) / 2] && key !in a && r.getOrNull() == -1 },
40-
{ a, key, r -> a.isNotEmpty() && key in a && r.getOrNull() == a.indexOfFirst { it == key } + 1 },
41-
// TODO enable it JIRA:1442
42-
/*
43-
summaryTextChecks = listOf(
44-
keyContain(DocCodeStmt("(found): False")),
45-
keyContain(DocCodeStmt("(found): True")),
46-
keyContain(DocRegularStmt(" BinarySearch::isUnsorted once")),
47-
keyContain(DocRegularStmt("throws NullPointerException in: isUnsorted(array)")),
48-
keyContain(DocRegularStmt("throws IllegalArgumentException after condition: isUnsorted(array)")),
49-
keyContain(DocCodeStmt("(array[middle] < key): True")),
50-
keyContain(DocCodeStmt("(array[middle] == key): True")),
51-
keyContain(DocCodeStmt("(array[middle] < key): True")),
52-
keyMatch(fullSummary)
53-
),
54-
summaryNameChecks = listOf(
55-
keyContain("testLeftBinSearch_BinarySearchIsUnsorted"),
56-
keyContain("testLeftBinSearch_ThrowIllegalArgumentException"),
57-
keyContain("testLeftBinSearch_NotFound"),
58-
keyContain("testLeftBinSearch_MiddleOfArrayLessThanKey"),
59-
keyContain("testLeftBinSearch_Found")
60-
),
61-
summaryDisplayNameChecks = listOf(
62-
keyMatch("isUnsorted(array) -> ThrowIllegalArgumentException"),
63-
keyMatch("isUnsorted(array) -> ThrowIllegalArgumentException"),
64-
keyMatch("found : False -> return -1"),
65-
keyMatch("array[middle] == key : True -> return right + 1"),
66-
keyMatch("array[middle] < key : True -> return -1")
67-
)
68-
*/
18+
{ a, key, r -> a.isNotEmpty() && key in a && r.getOrNull() == a.indexOfFirst { it == key } + 1 }
6919
)
7020
}
7121

utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package org.utbot.examples.algorithms
22

33
import org.utbot.framework.plugin.api.CodegenLanguage
4-
import org.utbot.framework.plugin.api.DocCodeStmt
5-
import org.utbot.framework.plugin.api.DocPreTagStatement
6-
import org.utbot.framework.plugin.api.DocRegularStmt
74
import org.junit.jupiter.api.Test
85
import org.utbot.examples.algorithms.CorrectBracketSequences.isBracket
96
import org.utbot.examples.algorithms.CorrectBracketSequences.isOpen
@@ -12,7 +9,6 @@ import org.utbot.testing.CodeGeneration
129
import org.utbot.testing.UtValueTestCaseChecker
1310
import org.utbot.testing.ignoreExecutionsNumber
1411
import org.utbot.testing.isException
15-
import org.utbot.testing.keyMatch
1612

1713
internal class CorrectBracketSequencesTest : UtValueTestCaseChecker(
1814
testClass = CorrectBracketSequences::class,
@@ -24,50 +20,18 @@ internal class CorrectBracketSequencesTest : UtValueTestCaseChecker(
2420
) {
2521
@Test
2622
fun testIsOpen() {
27-
val isOpenSummary = listOf(
28-
DocPreTagStatement(
29-
listOf(
30-
DocRegularStmt("Test "),
31-
DocRegularStmt("returns from: "),
32-
DocCodeStmt("return a == '(' || a == '{' || a == '[';"),
33-
DocRegularStmt("\n")
34-
)
35-
)
36-
)
37-
3823
checkStaticMethod(
3924
CorrectBracketSequences::isOpen,
4025
eq(4),
4126
{ c, r -> c == '(' && r == true },
4227
{ c, r -> c == '{' && r == true },
4328
{ c, r -> c == '[' && r == true },
44-
{ c, r -> c !in "({[".toList() && r == false },
45-
summaryNameChecks = listOf(
46-
keyMatch("testIsOpen_AEqualsCharOrAEqualsCharOrAEqualsChar"),
47-
keyMatch("testIsOpen_ANotEqualsCharOrANotEqualsCharOrANotEqualsChar")
48-
),
49-
summaryDisplayNameChecks = listOf(
50-
keyMatch("return a == '(' || a == '{' || a == '[' : False -> return a == '(' || a == '{' || a == '['"),
51-
keyMatch("return a == '(' || a == '{' || a == '[' : True -> return a == '(' || a == '{' || a == '['")
52-
),
53-
summaryTextChecks = listOf(
54-
keyMatch(isOpenSummary)
55-
)
29+
{ c, r -> c !in "({[".toList() && r == false }
5630
)
5731
}
5832

5933
@Test
6034
fun testIsBracket() {
61-
val isBracketSummary = listOf(
62-
DocPreTagStatement(
63-
listOf(
64-
DocRegularStmt("Test "),
65-
DocRegularStmt("returns from: "),
66-
DocCodeStmt("return isOpen(a) || a == ')' || a == '}' || a == ']';"),
67-
DocRegularStmt("\n")
68-
)
69-
)
70-
)
7135
checkStaticMethod(
7236
CorrectBracketSequences::isBracket,
7337
eq(7),
@@ -77,33 +41,12 @@ internal class CorrectBracketSequencesTest : UtValueTestCaseChecker(
7741
{ c, r -> c == ')' && r == true },
7842
{ c, r -> c == '}' && r == true },
7943
{ c, r -> c == ']' && r == true },
80-
{ c, r -> c !in "(){}[]".toList() && r == false },
81-
summaryNameChecks = listOf(
82-
keyMatch("testIsBracket_IsOpenOrANotEqualsCharOrANotEqualsCharOrANotEqualsChar"),
83-
keyMatch("testIsBracket_IsOpenOrAEqualsCharOrAEqualsCharOrAEqualsChar")
84-
),
85-
summaryDisplayNameChecks = listOf(
86-
keyMatch("return isOpen(a) || a == ')' || a == '}' || a == ']' : False -> return isOpen(a) || a == ')' || a == '}' || a == ']'"),
87-
keyMatch("return isOpen(a) || a == ')' || a == '}' || a == ']' : True -> return isOpen(a) || a == ')' || a == '}' || a == ']'")
88-
),
89-
summaryTextChecks = listOf(
90-
keyMatch(isBracketSummary)
91-
)
44+
{ c, r -> c !in "(){}[]".toList() && r == false }
9245
)
9346
}
9447

9548
@Test
9649
fun testIsTheSameType() {
97-
val isTheSameTypeSummary = listOf(
98-
DocPreTagStatement(
99-
listOf(
100-
DocRegularStmt("Test "),
101-
DocRegularStmt("returns from: "),
102-
DocCodeStmt("return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']';"),
103-
DocRegularStmt("\n")
104-
)
105-
)
106-
)
10750
checkStaticMethod(
10851
CorrectBracketSequences::isTheSameType,
10952
ignoreExecutionsNumber,
@@ -113,18 +56,7 @@ internal class CorrectBracketSequencesTest : UtValueTestCaseChecker(
11356
{ a, b, r -> a == '(' && b != ')' && r == false },
11457
{ a, b, r -> a == '{' && b != '}' && r == false },
11558
{ a, b, r -> a == '[' && b != ']' && r == false },
116-
{ a, b, r -> (a != '(' || b != ')') && (a != '{' || b != '}') && (a != '[' || b != ']') && r == false },
117-
summaryNameChecks = listOf(
118-
keyMatch("testIsTheSameType_ANotEqualsCharAndBNotEqualsCharOrANotEqualsCharAndBNotEqualsCharOrANotEqualsCharAndBNotEqualsChar"),
119-
keyMatch("testIsTheSameType_AEqualsCharAndBEqualsCharOrAEqualsCharAndBEqualsCharOrAEqualsCharAndBEqualsChar"),
120-
),
121-
summaryDisplayNameChecks = listOf(
122-
keyMatch("return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']' : False -> return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']'"),
123-
keyMatch("return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']' : True -> return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']'")
124-
),
125-
summaryTextChecks = listOf(
126-
keyMatch(isTheSameTypeSummary)
127-
)
59+
{ a, b, r -> (a != '(' || b != ')') && (a != '{' || b != '}') && (a != '[' || b != ']') && r == false }
12860
)
12961
}
13062

utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package org.utbot.examples.algorithms
22

3-
import org.utbot.framework.plugin.api.DocCodeStmt
4-
import org.utbot.framework.plugin.api.DocPreTagStatement
5-
import org.utbot.framework.plugin.api.DocRegularStmt
63
import org.utbot.framework.plugin.api.MockStrategyApi
74
import org.junit.jupiter.api.Test
85
import org.utbot.framework.plugin.api.CodegenLanguage
@@ -12,7 +9,6 @@ import org.utbot.testing.CodeGeneration
129
import org.utbot.testing.UtValueTestCaseChecker
1310
import org.utbot.testing.ignoreExecutionsNumber
1411
import org.utbot.testing.isException
15-
import org.utbot.testing.keyMatch
1612

1713
// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88
1814
internal class SortTest : UtValueTestCaseChecker(
@@ -111,54 +107,12 @@ internal class SortTest : UtValueTestCaseChecker(
111107
val connection = lhs.last() >= rhs.last() && r.getOrNull()?.toList() == (lhs + rhs).sorted()
112108

113109
lhsCondition && rhsCondition && connection
114-
},
110+
}
115111
)
116112
}
117113

118114
@Test
119115
fun testDefaultSort() {
120-
val defaultSortSummary1 = listOf(
121-
DocPreTagStatement(
122-
listOf(
123-
DocRegularStmt("Test "),
124-
DocRegularStmt("\n"),
125-
DocRegularStmt("throws NullPointerException in: array.length < 4"),
126-
DocRegularStmt("\n")
127-
)
128-
)
129-
)
130-
131-
val defaultSortSummary2 = listOf(
132-
DocPreTagStatement(
133-
listOf(
134-
DocRegularStmt("Test "),
135-
DocRegularStmt("executes conditions:\n"),
136-
DocRegularStmt(" "),
137-
DocCodeStmt("(array.length < 4): True"),
138-
DocRegularStmt("\n"),
139-
DocRegularStmt("\n"),
140-
DocRegularStmt("throws IllegalArgumentException after condition: array.length < 4"),
141-
DocRegularStmt("\n")
142-
)
143-
)
144-
)
145-
val defaultSortSummary3 = listOf(
146-
DocPreTagStatement(
147-
listOf(
148-
DocRegularStmt("Test "),
149-
DocRegularStmt("executes conditions:\n"),
150-
DocRegularStmt(" "),
151-
DocCodeStmt("(array.length < 4): False"),
152-
DocRegularStmt("\n"),
153-
DocRegularStmt("invokes:\n"),
154-
DocRegularStmt(" {@link java.util.Arrays#sort(int[])} once"),
155-
DocRegularStmt("\n"),
156-
DocRegularStmt("returns from: "),
157-
DocCodeStmt("return array;"),
158-
DocRegularStmt("\n")
159-
)
160-
)
161-
)
162116
checkWithException(
163117
Sort::defaultSort,
164118
eq(3),
@@ -167,22 +121,7 @@ internal class SortTest : UtValueTestCaseChecker(
167121
{ a, r ->
168122
val resultArray = intArrayOf(-100, 0, 100, 200)
169123
a != null && r.getOrNull()!!.size >= 4 && r.getOrNull() contentEquals resultArray
170-
},
171-
summaryTextChecks = listOf(
172-
keyMatch(defaultSortSummary1),
173-
keyMatch(defaultSortSummary2),
174-
keyMatch(defaultSortSummary3),
175-
),
176-
summaryNameChecks = listOf(
177-
keyMatch("testDefaultSort_ThrowNullPointerException"),
178-
keyMatch("testDefaultSort_ArrayLengthLessThan4"),
179-
keyMatch("testDefaultSort_ArrayLengthGreaterOrEqual4"),
180-
),
181-
summaryDisplayNameChecks = listOf(
182-
keyMatch("array.length < 4 -> ThrowNullPointerException"),
183-
keyMatch("array.length < 4 -> ThrowIllegalArgumentException"),
184-
keyMatch("array.length < 4 : False -> return array"),
185-
)
124+
}
186125
)
187126
}
188127
}

utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
package org.utbot.examples.objects
22

3-
import org.utbot.framework.plugin.api.DocCodeStmt
4-
import org.utbot.framework.plugin.api.DocPreTagStatement
5-
import org.utbot.framework.plugin.api.DocRegularStmt
6-
import org.utbot.framework.plugin.api.DocStatement
73
import org.junit.jupiter.api.Test
84
import org.utbot.testcheckers.eq
95
import org.utbot.testing.DoNotCalculate
106
import org.utbot.testing.UtValueTestCaseChecker
117
import org.utbot.testing.between
128
import org.utbot.testing.isException
13-
import org.utbot.testing.keyContain
14-
import org.utbot.testing.keyMatch
159

1610
internal class SimpleClassExampleTest : UtValueTestCaseChecker(testClass = SimpleClassExample::class) {
1711
@Test
@@ -66,41 +60,12 @@ internal class SimpleClassExampleTest : UtValueTestCaseChecker(testClass = Simpl
6660

6761
@Test
6862
fun immutableFieldAccessTest() {
69-
val immutableFieldAccessSummary = listOf<DocStatement>(
70-
DocPreTagStatement(
71-
listOf(
72-
DocRegularStmt("Test "),
73-
DocRegularStmt("executes conditions:\n"),
74-
DocRegularStmt(" "),
75-
DocCodeStmt("(c.b == 10): True"),
76-
DocRegularStmt("\n"),
77-
DocRegularStmt("returns from: "),
78-
DocCodeStmt("return 0;"),
79-
DocRegularStmt("\n"),
80-
)
81-
)
82-
)
8363
checkWithException(
8464
SimpleClassExample::immutableFieldAccess,
8565
eq(3),
8666
{ c, r -> c == null && r.isException<NullPointerException>() },
8767
{ c, r -> c.b == 10 && r.getOrNull() == 0 },
88-
{ c, r -> c.b != 10 && r.getOrNull() == 1 },
89-
summaryTextChecks = listOf(
90-
keyContain(DocRegularStmt("throws NullPointerException in: c.b == 10")),
91-
keyContain(DocCodeStmt("(c.b == 10): False")),
92-
keyMatch(immutableFieldAccessSummary)
93-
),
94-
summaryNameChecks = listOf(
95-
keyMatch("testImmutableFieldAccess_ThrowNullPointerException"),
96-
keyMatch("testImmutableFieldAccess_CBNotEquals10"),
97-
keyMatch("testImmutableFieldAccess_CBEquals10")
98-
),
99-
summaryDisplayNameChecks = listOf(
100-
keyContain("NullPointerException", "c.b == 10"),
101-
keyContain("c.b == 10 : False"),
102-
keyContain("c.b == 10 : True")
103-
)
68+
{ c, r -> c.b != 10 && r.getOrNull() == 1 }
10469
)
10570
}
10671
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,7 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
380380
{ cs, r -> cs == null && r == true },
381381
{ cs, r -> cs.isEmpty() && r == true },
382382
{ cs, r -> cs.isNotEmpty() && cs.isBlank() && r == true },
383-
{ cs, r -> cs.isNotEmpty() && cs.isNotBlank() && r == false },
384-
summaryNameChecks = listOf(
385-
keyMatch("testIsBlank_StrLenEqualsZero"),
386-
keyMatch("testIsBlank_NotCharacterIsWhitespace"),
387-
keyMatch("testIsBlank_CharacterIsWhitespace")
388-
)
383+
{ cs, r -> cs.isNotEmpty() && cs.isNotBlank() && r == false }
389384
)
390385
}
391386

0 commit comments

Comments
 (0)