Skip to content

Commit 1411a8c

Browse files
authored
Primitive Stream wrappers (no laziness and source mutations support) (#871)
* Fixed repeated `hashCode` calculation for `Edge` * Added `toArray` without ClassCastException check API * Fixed UNSAT core debug logging
1 parent c35eb03 commit 1411a8c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+6794
-479
lines changed

utbot-api/src/main/java/org/utbot/api/mock/UtMock.java

+3
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ public static void assumeOrExecuteConcretely(boolean predicate) {
2323
// In oppose to assume, we don't have predicate check here
2424
// to avoid RuntimeException during concrete execution
2525
}
26+
27+
@SuppressWarnings("unused")
28+
public static void disableClassCastExceptionCheck(Object object) {}
2629
}

utbot-framework-api/src/main/kotlin/org/utbot/testcheckers/SettingsModificators.kt

+10
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,13 @@ inline fun <reified T> withoutSandbox(block: () -> T): T {
121121
UtSettings.useSandbox = prev
122122
}
123123
}
124+
125+
inline fun <reified T> withPathSelectorStepsLimit(stepsLimit: Int, block: () -> T): T {
126+
val prev = UtSettings.pathSelectorStepsLimit
127+
UtSettings.pathSelectorStepsLimit = stepsLimit
128+
try {
129+
return block()
130+
} finally {
131+
UtSettings.pathSelectorStepsLimit = prev
132+
}
133+
}

utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt

+86-17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.utbot.tests.infrastructure.isException
1313
import org.utbot.framework.plugin.api.CodegenLanguage
1414
import org.utbot.testcheckers.eq
1515
import org.utbot.testcheckers.withoutConcrete
16+
import org.utbot.tests.infrastructure.AtLeast
1617
import org.utbot.tests.infrastructure.CodeGeneration
1718
import java.util.Optional
1819
import java.util.stream.Stream
@@ -69,10 +70,46 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
6970
fun testMapExample() {
7071
checkWithException(
7172
BaseStreamExample::mapExample,
72-
eq(2),
73+
ignoreExecutionsNumber,
7374
{ c, r -> null in c && r.isException<NullPointerException>() },
7475
{ c, r -> r.getOrThrow().contentEquals(c.map { it * 2 }.toTypedArray()) },
75-
coverage = DoNotCalculate
76+
coverage = AtLeast(90)
77+
)
78+
}
79+
80+
@Test
81+
@Tag("slow")
82+
fun testMapToIntExample() {
83+
checkWithException(
84+
BaseStreamExample::mapToIntExample,
85+
ignoreExecutionsNumber,
86+
{ c, r -> null in c && r.isException<NullPointerException>() },
87+
{ c, r -> r.getOrThrow().contentEquals(c.map { it.toInt() }.toIntArray()) },
88+
coverage = AtLeast(90)
89+
)
90+
}
91+
92+
@Test
93+
@Tag("slow")
94+
fun testMapToLongExample() {
95+
checkWithException(
96+
BaseStreamExample::mapToLongExample,
97+
ignoreExecutionsNumber,
98+
{ c, r -> null in c && r.isException<NullPointerException>() },
99+
{ c, r -> r.getOrThrow().contentEquals(c.map { it.toLong() }.toLongArray()) },
100+
coverage = AtLeast(90)
101+
)
102+
}
103+
104+
@Test
105+
@Tag("slow")
106+
fun testMapToDoubleExample() {
107+
checkWithException(
108+
BaseStreamExample::mapToDoubleExample,
109+
ignoreExecutionsNumber,
110+
{ c, r -> null in c && r.isException<NullPointerException>() },
111+
{ c, r -> r.getOrThrow().contentEquals(c.map { it.toDouble() }.toDoubleArray()) },
112+
coverage = AtLeast(90)
76113
)
77114
}
78115

@@ -86,6 +123,37 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
86123
)
87124
}
88125

126+
@Test
127+
@Tag("slow")
128+
fun testFlatMapToIntExample() {
129+
check(
130+
BaseStreamExample::flatMapToIntExample,
131+
ignoreExecutionsNumber,
132+
{ c, r -> r.contentEquals(c.flatMap { listOf(it?.toInt() ?: 0, it?.toInt() ?: 0) }.toIntArray()) },
133+
coverage = FullWithAssumptions(assumeCallsNumber = 1)
134+
)
135+
}
136+
137+
@Test
138+
fun testFlatMapToLongExample() {
139+
check(
140+
BaseStreamExample::flatMapToLongExample,
141+
ignoreExecutionsNumber,
142+
{ c, r -> r.contentEquals(c.flatMap { listOf(it?.toLong() ?: 0L, it?.toLong() ?: 0L) }.toLongArray()) },
143+
coverage = FullWithAssumptions(assumeCallsNumber = 1)
144+
)
145+
}
146+
147+
@Test
148+
fun testFlatMapToDoubleExample() {
149+
check(
150+
BaseStreamExample::flatMapToDoubleExample,
151+
ignoreExecutionsNumber,
152+
{ c, r -> r.contentEquals(c.flatMap { listOf(it?.toDouble() ?: 0.0, it?.toDouble() ?: 0.0) }.toDoubleArray()) },
153+
coverage = FullWithAssumptions(assumeCallsNumber = 1)
154+
)
155+
}
156+
89157
@Test
90158
@Tag("slow")
91159
fun testDistinctExample() {
@@ -146,17 +214,17 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
146214
fun testForEachExample() {
147215
checkThisAndStaticsAfter(
148216
BaseStreamExample::forEachExample,
149-
eq(2),
217+
ignoreExecutionsNumber,
150218
*streamConsumerStaticsMatchers,
151-
coverage = DoNotCalculate
219+
coverage = AtLeast(92)
152220
)
153221
}
154222

155223
@Test
156224
fun testToArrayExample() {
157225
check(
158226
BaseStreamExample::toArrayExample,
159-
ignoreExecutionsNumber,
227+
eq(2),
160228
{ c, r -> c.toTypedArray().contentEquals(r) },
161229
coverage = FullWithAssumptions(assumeCallsNumber = 1)
162230
)
@@ -311,10 +379,11 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
311379
fun testIteratorExample() {
312380
checkWithException(
313381
BaseStreamExample::iteratorSumExample,
314-
eq(2),
382+
ignoreExecutionsNumber,
383+
{ c, r -> c.isEmpty() && r.getOrThrow() == 0 },
315384
{ c, r -> null in c && r.isException<NullPointerException>() },
316-
{ c, r -> null !in c && r.getOrThrow() == c.sum() },
317-
coverage = DoNotCalculate
385+
{ c, r -> c.isNotEmpty() && null !in c && r.getOrThrow() == c.sum() },
386+
coverage = AtLeast(75)
318387
)
319388
}
320389

@@ -393,15 +462,15 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
393462
coverage = Full
394463
)
395464
}
465+
}
396466

397-
private val streamConsumerStaticsMatchers = arrayOf(
398-
{ _: BaseStreamExample, c: List<Int?>, _: StaticsType, _: Int? -> null in c },
399-
{ _: BaseStreamExample, c: List<Int?>, statics: StaticsType, r: Int? ->
400-
val x = statics.values.single().value as Int
467+
internal val streamConsumerStaticsMatchers = arrayOf(
468+
{ _: Any, c: List<Int?>, _: StaticsType, _: Int? -> null in c },
469+
{ _: Any, c: List<Int?>, statics: StaticsType, r: Int? ->
470+
val x = statics.values.single().value as Int
401471

402-
r!! + c.sumOf { it ?: 0 } == x
403-
}
404-
)
405-
}
472+
r!! + c.sumOf { it ?: 0 } == x
473+
}
474+
)
406475

407-
private fun <E : Comparable<E>> Sequence<E>.isSorted(): Boolean = zipWithNext { a, b -> a <= b }.all { it }
476+
internal fun <E : Comparable<E>> Sequence<E>.isSorted(): Boolean = zipWithNext { a, b -> a <= b }.all { it }

0 commit comments

Comments
 (0)