Skip to content

Commit e4607e6

Browse files
committed
Used coverage calculation instead of matchers for flaky executions number in some Map tests
1 parent 3a0199c commit e4607e6

File tree

3 files changed

+33
-51
lines changed

3 files changed

+33
-51
lines changed

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

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import org.utbot.tests.infrastructure.isException
77
import org.utbot.framework.plugin.api.CodegenLanguage
88
import org.junit.jupiter.api.Disabled
99
import org.junit.jupiter.api.Test
10-
import org.utbot.testcheckers.ge
1110
import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete
11+
import org.utbot.tests.infrastructure.AtLeast
1212
import org.utbot.tests.infrastructure.CodeGeneration
1313
import org.utbot.tests.infrastructure.ignoreExecutionsNumber
1414

@@ -45,42 +45,41 @@ class MapEntrySetTest : UtValueTestCaseChecker(
4545
fun testAddToEntrySet() {
4646
checkWithException(
4747
MapEntrySet::addToEntrySet,
48-
between(2..4),
48+
ignoreExecutionsNumber,
4949
{ map, result -> map == null && result.isException<NullPointerException>() },
5050
{ map, result -> map != null && result.isException<UnsupportedOperationException>() },
51-
coverage = DoNotCalculate
51+
coverage = AtLeast(75)
5252
)
5353
}
5454

5555
@Test
5656
fun testGetFromEntrySet() {
5757
check(
5858
MapEntrySet::getFromEntrySet,
59-
between(3..7),
59+
ignoreExecutionsNumber,
6060
{ map, _, _, _ -> map == null },
6161
{ map, i, j, result -> map.none { it.key == i && it.value == j } && result == 1 },
6262
{ map, i, j, result -> map.any { it.key == i && it.value == j } && result == 1 },
63-
coverage = DoNotCalculate
63+
coverage = AtLeast(94) // unreachable branch
6464
)
6565
}
6666

6767
@Test
6868
fun testIteratorHasNext() {
6969
check(
7070
MapEntrySet::iteratorHasNext,
71-
between(3..4),
71+
ignoreExecutionsNumber,
7272
{ map, _ -> map == null },
7373
{ map, result -> map.entries.isEmpty() && result == 0 },
7474
{ map, result -> map.entries.isNotEmpty() && result == map.entries.size },
75-
coverage = DoNotCalculate
7675
)
7776
}
7877

7978
@Test
8079
fun testIteratorNext() {
8180
checkWithException(
8281
MapEntrySet::iteratorNext,
83-
between(3..5),
82+
ignoreExecutionsNumber,
8483
{ map, result -> map == null && result.isException<NullPointerException>() },
8584
{ map, result -> map.entries.isEmpty() && result.isException<NoSuchElementException>() },
8685
// test should work as long as default class for map is LinkedHashMap
@@ -90,15 +89,14 @@ class MapEntrySetTest : UtValueTestCaseChecker(
9089
val (resultKey, resultValue) = resultEntry
9190
map.entries.isNotEmpty() && entryKey == resultKey && entryValue == resultValue
9291
},
93-
coverage = DoNotCalculate
9492
)
9593
}
9694

9795
@Test
9896
fun testIteratorRemove() {
9997
checkWithException(
10098
MapEntrySet::iteratorRemove,
101-
between(3..4),
99+
ignoreExecutionsNumber,
102100
{ map, result -> map == null && result.isException<NullPointerException>() },
103101
{ map, result -> map.entries.isEmpty() && result.isException<NoSuchElementException>() },
104102
// test should work as long as default class for map is LinkedHashMap
@@ -109,15 +107,14 @@ class MapEntrySetTest : UtValueTestCaseChecker(
109107
resultMap.entries.size == map.entries.size - 1 && map.entries.first() !in resultMap.entries
110108
map.entries.isNotEmpty() && mapContainsAllEntriesInResult && resultDoesntContainFirstEntry
111109
},
112-
coverage = DoNotCalculate
113110
)
114111
}
115112

116113
@Test
117114
fun testIteratorRemoveOnIndex() {
118115
checkWithException(
119116
MapEntrySet::iteratorRemoveOnIndex,
120-
ge(5),
117+
ignoreExecutionsNumber,
121118
{ _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null },
122119
{ map, _, result -> map == null && result.isException<NullPointerException>() },
123120
{ map, i, result -> map != null && i < 0 && result.isException<IllegalStateException>() },
@@ -130,19 +127,17 @@ class MapEntrySetTest : UtValueTestCaseChecker(
130127
val resultDoesntContainIthEntry = map.entries.toList()[i - 1] !in resultMap.entries
131128
iInIndexRange && mapContainsAllEntriesInResult && resultDoesntContainIthEntry
132129
},
133-
coverage = DoNotCalculate
134130
)
135131
}
136132

137133
@Test
138134
fun testIterateForEach() {
139135
check(
140136
MapEntrySet::iterateForEach,
141-
between(3..5),
137+
ignoreExecutionsNumber,
142138
{ map, _ -> map == null },
143139
{ map, _ -> null in map.values },
144140
{ map, result -> result!![0] == map.keys.sum() && result[1] == map.values.sum() },
145-
coverage = DoNotCalculate
146141
)
147142
}
148143

@@ -168,8 +163,8 @@ class MapEntrySetTest : UtValueTestCaseChecker(
168163
{ map, result ->
169164
val mapIsNotEmptyAndSizeIsEven = map != null && map.isNotEmpty() && map.size % 2 == 0
170165
val arrayResult = result.getOrThrow()
171-
val evenKeysSum = map.keys.withIndex().filter { it.index % 2 == 0 }.sumBy { it.value }
172-
val oddValuesSum = map.values.withIndex().filter { it.index % 2 == 0 }.sumBy { it.value }
166+
val evenKeysSum = map.keys.withIndex().filter { it.index % 2 == 0 }.sumOf { it.value }
167+
val oddValuesSum = map.values.withIndex().filter { it.index % 2 == 0 }.sumOf { it.value }
173168
mapIsNotEmptyAndSizeIsEven && arrayResult[0] == evenKeysSum && arrayResult[1] == oddValuesSum
174169
},
175170
)

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

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
package org.utbot.examples.collections
22

3-
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
4-
import org.utbot.tests.infrastructure.AtLeast
5-
import org.utbot.tests.infrastructure.DoNotCalculate
6-
import org.utbot.tests.infrastructure.between
7-
import org.utbot.tests.infrastructure.ignoreExecutionsNumber
8-
import org.utbot.tests.infrastructure.isException
9-
import org.utbot.framework.plugin.api.CodegenLanguage
103
import org.junit.jupiter.api.Test
11-
import org.utbot.testcheckers.eq
12-
import org.utbot.testcheckers.ge
4+
import org.utbot.framework.plugin.api.CodegenLanguage
135
import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete
146
import org.utbot.testcheckers.withoutMinimization
7+
import org.utbot.tests.infrastructure.AtLeast
158
import org.utbot.tests.infrastructure.CodeGeneration
9+
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
10+
import org.utbot.tests.infrastructure.ignoreExecutionsNumber
11+
import org.utbot.tests.infrastructure.isException
1612

1713
// TODO failed Kotlin compilation SAT-1332
1814
class MapKeySetTest : UtValueTestCaseChecker(
@@ -46,10 +42,10 @@ class MapKeySetTest : UtValueTestCaseChecker(
4642
fun testAddToKeySet() {
4743
checkWithException(
4844
MapKeySet::addToKeySet,
49-
between(2..4),
45+
ignoreExecutionsNumber,
5046
{ map, result -> map == null && result.isException<NullPointerException>() },
5147
{ map, result -> map != null && result.isException<UnsupportedOperationException>() },
52-
coverage = DoNotCalculate
48+
coverage = AtLeast(70) // unreachable return
5349
)
5450
}
5551

@@ -62,7 +58,7 @@ class MapKeySetTest : UtValueTestCaseChecker(
6258
{ map, _, _ -> map == null },
6359
{ map, i, result -> i !in map && result == 1 }, // one of these will be minimized
6460
{ map, i, result -> i in map && result == 1 }, // one of these will be minimized
65-
coverage = AtLeast(90) // 18/20 instructions
61+
coverage = AtLeast(90) // 18/20 instructions, unreachable branch
6662
)
6763
}
6864
}
@@ -71,11 +67,10 @@ class MapKeySetTest : UtValueTestCaseChecker(
7167
fun testIteratorHasNext() {
7268
check(
7369
MapKeySet::iteratorHasNext,
74-
between(3..4),
70+
ignoreExecutionsNumber,
7571
{ map, _ -> map == null },
7672
{ map, result -> map.keys.isEmpty() && result == 0 },
7773
{ map, result -> map.keys.isNotEmpty() && result == map.keys.size },
78-
coverage = DoNotCalculate
7974
)
8075
}
8176

@@ -84,12 +79,11 @@ class MapKeySetTest : UtValueTestCaseChecker(
8479
withPushingStateFromPathSelectorForConcrete {
8580
checkWithException(
8681
MapKeySet::iteratorNext,
87-
between(3..4),
82+
ignoreExecutionsNumber,
8883
{ map, result -> map == null && result.isException<NullPointerException>() },
8984
{ map, result -> map.keys.isEmpty() && result.isException<NoSuchElementException>() },
9085
// test should work as long as default class for map is LinkedHashMap
9186
{ map, result -> map.keys.isNotEmpty() && result.getOrNull() == map.keys.first() },
92-
coverage = DoNotCalculate
9387
)
9488
}
9589
}
@@ -98,7 +92,7 @@ class MapKeySetTest : UtValueTestCaseChecker(
9892
fun testIteratorRemove() {
9993
checkWithException(
10094
MapKeySet::iteratorRemove,
101-
between(3..4),
95+
ignoreExecutionsNumber,
10296
{ map, result -> map == null && result.isException<NullPointerException>() },
10397
{ map, result -> map.keys.isEmpty() && result.isException<NoSuchElementException>() },
10498
// test should work as long as default class for map is LinkedHashMap
@@ -108,15 +102,14 @@ class MapKeySetTest : UtValueTestCaseChecker(
108102
val resultDoesntContainFirstKey = resultMap.keys.size == map.keys.size - 1 && map.keys.first() !in resultMap.keys
109103
mapContainsAllKeysInResult && resultDoesntContainFirstKey
110104
},
111-
coverage = DoNotCalculate
112105
)
113106
}
114107

115108
@Test
116109
fun testIteratorRemoveOnIndex() {
117110
checkWithException(
118111
MapKeySet::iteratorRemoveOnIndex,
119-
ge(5),
112+
ignoreExecutionsNumber,
120113
{ _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null },
121114
{ map, _, result -> map == null && result.isException<NullPointerException>() },
122115
{ map, i, result -> map != null && i < 0 && result.isException<IllegalStateException>() },
@@ -129,7 +122,6 @@ class MapKeySetTest : UtValueTestCaseChecker(
129122
val resultDoesntContainIthKey = map.keys.toList()[i - 1] !in resultMap.keys
130123
iInIndexRange && mapContainsAllKeysInResult && resultDoesntContainIthKey
131124
},
132-
coverage = DoNotCalculate
133125
)
134126
}
135127

@@ -159,7 +151,7 @@ class MapKeySetTest : UtValueTestCaseChecker(
159151
fun testNullKey() {
160152
check(
161153
MapKeySet::nullKey,
162-
eq(3),
154+
ignoreExecutionsNumber,
163155
{ map, _ -> map == null },
164156
{ map, result -> map != null && null in map.keys && map[null] == result },
165157
{ map, _ -> map != null && null !in map.keys }

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ class MapValuesTest : UtValueTestCaseChecker(
5454
fun testAddToValues() {
5555
checkWithException(
5656
MapValues::addToValues,
57-
between(2..4),
57+
ignoreExecutionsNumber,
5858
{ map, result -> map == null && result.isException<NullPointerException>() },
5959
{ map, result -> map != null && result.isException<UnsupportedOperationException>() },
60-
coverage = DoNotCalculate
60+
coverage = AtLeast(70) // unreachable return
6161
)
6262
}
6363

@@ -79,19 +79,18 @@ class MapValuesTest : UtValueTestCaseChecker(
7979
fun testIteratorHasNext() {
8080
check(
8181
MapValues::iteratorHasNext,
82-
between(3..4),
82+
ignoreExecutionsNumber,
8383
{ map, _ -> map == null },
8484
{ map, result -> map.values.isEmpty() && result == 0 },
8585
{ map, result -> map.values.isNotEmpty() && result == map.values.size },
86-
coverage = DoNotCalculate
8786
)
8887
}
8988

9089
@Test
9190
fun testIteratorNext() {
9291
checkWithException(
9392
MapValues::iteratorNext,
94-
between(3..4),
93+
ignoreExecutionsNumber,
9594
{ map, result -> map == null && result.isException<NullPointerException>() },
9695
// We might lose this branch depending on the order of the exploration since
9796
// we do not register wrappers, and, therefore, do not try to cover all of their branches
@@ -106,7 +105,7 @@ class MapValuesTest : UtValueTestCaseChecker(
106105
fun testIteratorRemove() {
107106
checkWithException(
108107
MapValues::iteratorRemove,
109-
between(3..4),
108+
ignoreExecutionsNumber,
110109
{ map, result -> map == null && result.isException<NullPointerException>() },
111110
{ map, result -> map.values.isEmpty() && result.isException<NoSuchElementException>() },
112111
// test should work as long as default class for map is LinkedHashMap
@@ -127,15 +126,14 @@ class MapValuesTest : UtValueTestCaseChecker(
127126

128127
mapContainsAllValuesFromResult && firstValueWasDeleted && keyAssociatedWithFirstValueWasDeleted
129128
},
130-
coverage = DoNotCalculate
131129
)
132130
}
133131

134132
@Test
135133
fun testIteratorRemoveOnIndex() {
136134
checkWithException(
137135
MapValues::iteratorRemoveOnIndex,
138-
ge(5),
136+
ignoreExecutionsNumber,
139137
{ _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null },
140138
{ map, _, result -> map == null && result.isException<NullPointerException>() },
141139
{ map, i, result -> map != null && i < 0 && result.isException<IllegalStateException>() },
@@ -156,31 +154,28 @@ class MapValuesTest : UtValueTestCaseChecker(
156154

157155
iInIndexRange && mapContainsAllValuesFromResult && ithValueWasDeleted && keyAssociatedWIthIthValueWasDeleted
158156
},
159-
coverage = DoNotCalculate
160157
)
161158
}
162159

163160
@Test
164161
fun testIterateForEach() {
165162
check(
166163
MapValues::iterateForEach,
167-
between(3..5),
164+
ignoreExecutionsNumber,
168165
{ map, _ -> map == null },
169166
{ map, _ -> null in map.values },
170167
{ map, result -> map != null && result == map.values.sum() },
171-
coverage = DoNotCalculate
172168
)
173169
}
174170

175171
@Test
176172
fun testIterateWithIterator() {
177173
check(
178174
MapValues::iterateWithIterator,
179-
between(3..5),
175+
ignoreExecutionsNumber,
180176
{ map, _ -> map == null },
181177
{ map, _ -> null in map.values },
182178
{ map, result -> map != null && result == map.values.sum() },
183-
coverage = DoNotCalculate
184179
)
185180
}
186181
}

0 commit comments

Comments
 (0)