Skip to content

Commit 5d2b858

Browse files
committed
Fixed failed tests
1 parent ff46fd4 commit 5d2b858

File tree

10 files changed

+145
-57
lines changed

10 files changed

+145
-57
lines changed

utbot-framework/src/main/java/org/utbot/engine/overrides/stream/DoubleStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static java.util.stream.DoubleStream generate(DoubleSupplier s) {
3838
}
3939

4040
@SuppressWarnings("unused")
41-
static java.util.stream.DoubleStream iterate(final int seed, final DoubleUnaryOperator f) {
41+
static java.util.stream.DoubleStream iterate(final double seed, final DoubleUnaryOperator f) {
4242
// as "iterate" method produces an infinite stream, we cannot analyze it symbolically
4343
executeConcretely();
4444
return null;

utbot-framework/src/main/java/org/utbot/engine/overrides/stream/LongStream.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.utbot.engine.overrides.stream;
22

33
import org.utbot.api.annotation.UtClassMock;
4+
import org.utbot.api.mock.UtMock;
45

56
import java.util.function.LongSupplier;
67
import java.util.function.LongUnaryOperator;
@@ -37,29 +38,45 @@ static java.util.stream.LongStream generate(LongSupplier s) {
3738
return null;
3839
}
3940

40-
static java.util.stream.LongStream range(int startInclusive, int endExclusive) {
41-
int size = endExclusive - startInclusive;
41+
static java.util.stream.LongStream range(long startInclusive, long endExclusive) {
42+
int start = (int) startInclusive;
43+
int end = (int) endExclusive;
44+
45+
// check that borders fit in int range
46+
UtMock.assumeOrExecuteConcretely(start == startInclusive);
47+
UtMock.assumeOrExecuteConcretely(end == endExclusive);
48+
49+
int size = end - start;
50+
4251
Long[] data = new Long[size];
43-
for (int i = startInclusive; i < endExclusive; i++) {
44-
data[i - startInclusive] = (long) i;
52+
for (int i = start; i < end; i++) {
53+
data[i - start] = (long) i;
4554
}
4655

4756
return new UtLongStream(data, size);
4857
}
4958

5059
@SuppressWarnings("unused")
51-
static java.util.stream.LongStream rangeClosed(int startInclusive, int endInclusive) {
52-
int size = endInclusive - startInclusive + 1;
60+
static java.util.stream.LongStream rangeClosed(long startInclusive, long endInclusive) {
61+
int start = (int) startInclusive;
62+
int end = (int) endInclusive;
63+
64+
// check that borders fit in int range
65+
UtMock.assumeOrExecuteConcretely(start == startInclusive);
66+
UtMock.assumeOrExecuteConcretely(end == endInclusive);
67+
68+
int size = end - start + 1;
69+
5370
Long[] data = new Long[size];
54-
for (int i = startInclusive; i <= endInclusive; i++) {
55-
data[i - startInclusive] = (long) i;
71+
for (int i = start; i <= end; i++) {
72+
data[i - start] = (long) i;
5673
}
5774

5875
return new UtLongStream(data, size);
5976
}
6077

6178
@SuppressWarnings("unused")
62-
static java.util.stream.LongStream iterate(final int seed, final LongUnaryOperator f) {
79+
static java.util.stream.LongStream iterate(final long seed, final LongUnaryOperator f) {
6380
// as "iterate" method produces an infinite stream, we cannot analyze it symbolically
6481
executeConcretely();
6582
return null;

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

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.utbot.examples.stream
33
import org.junit.jupiter.api.Disabled
44
import org.junit.jupiter.api.Tag
55
import org.junit.jupiter.api.Test
6+
import org.utbot.examples.AtLeast
67
import org.utbot.examples.UtValueTestCaseChecker
78
import org.utbot.examples.DoNotCalculate
89
import org.utbot.examples.Full
@@ -69,10 +70,43 @@ 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+
fun testMapToIntExample() {
82+
checkWithException(
83+
BaseStreamExample::mapToIntExample,
84+
ignoreExecutionsNumber,
85+
{ c, r -> null in c && r.isException<NullPointerException>() },
86+
{ c, r -> r.getOrThrow().contentEquals(c.map { it.toInt() }.toIntArray()) },
87+
coverage = AtLeast(90)
88+
)
89+
}
90+
91+
@Test
92+
fun testMapToLongExample() {
93+
checkWithException(
94+
BaseStreamExample::mapToLongExample,
95+
ignoreExecutionsNumber,
96+
{ c, r -> null in c && r.isException<NullPointerException>() },
97+
{ c, r -> r.getOrThrow().contentEquals(c.map { it.toLong() }.toLongArray()) },
98+
coverage = AtLeast(90)
99+
)
100+
}
101+
102+
@Test
103+
fun testMapToDoubleExample() {
104+
checkWithException(
105+
BaseStreamExample::mapToDoubleExample,
106+
ignoreExecutionsNumber,
107+
{ c, r -> null in c && r.isException<NullPointerException>() },
108+
{ c, r -> r.getOrThrow().contentEquals(c.map { it.toDouble() }.toDoubleArray()) },
109+
coverage = AtLeast(90)
76110
)
77111
}
78112

@@ -86,6 +120,36 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
86120
)
87121
}
88122

123+
@Test
124+
fun testFlatMapToIntExample() {
125+
check(
126+
BaseStreamExample::flatMapToIntExample,
127+
ignoreExecutionsNumber,
128+
{ c, r -> r.contentEquals(c.flatMap { listOf(it.toInt(), it.toInt()) }.toIntArray()) },
129+
coverage = FullWithAssumptions(assumeCallsNumber = 1)
130+
)
131+
}
132+
133+
@Test
134+
fun testFlatMapToLongExample() {
135+
check(
136+
BaseStreamExample::flatMapToLongExample,
137+
ignoreExecutionsNumber,
138+
{ c, r -> r.contentEquals(c.flatMap { listOf(it.toLong(), it.toLong()) }.toLongArray()) },
139+
coverage = FullWithAssumptions(assumeCallsNumber = 1)
140+
)
141+
}
142+
143+
@Test
144+
fun testFlatMapToDoubleExample() {
145+
check(
146+
BaseStreamExample::flatMapToDoubleExample,
147+
ignoreExecutionsNumber,
148+
{ c, r -> r.contentEquals(c.flatMap { listOf(it.toDouble(), it.toDouble()) }.toDoubleArray()) },
149+
coverage = FullWithAssumptions(assumeCallsNumber = 1)
150+
)
151+
}
152+
89153
@Test
90154
fun testDistinctExample() {
91155
check(
@@ -145,9 +209,9 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
145209
fun testForEachExample() {
146210
checkThisAndStaticsAfter(
147211
BaseStreamExample::forEachExample,
148-
eq(2),
212+
ignoreExecutionsNumber,
149213
*streamConsumerStaticsMatchers,
150-
coverage = DoNotCalculate
214+
coverage = AtLeast(92)
151215
)
152216
}
153217

@@ -310,10 +374,11 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
310374
fun testIteratorExample() {
311375
checkWithException(
312376
BaseStreamExample::iteratorSumExample,
313-
eq(2),
377+
ignoreExecutionsNumber,
378+
{ c, r -> c.isEmpty() && r.getOrThrow() == 0 },
314379
{ c, r -> null in c && r.isException<NullPointerException>() },
315-
{ c, r -> null !in c && r.getOrThrow() == c.sum() },
316-
coverage = DoNotCalculate
380+
{ c, r -> c.isNotEmpty() && null !in c && r.getOrThrow() == c.sum() },
381+
coverage = AtLeast(75)
317382
)
318383
}
319384

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.utbot.examples.stream
22

33
import org.junit.jupiter.api.Tag
44
import org.junit.jupiter.api.Test
5+
import org.utbot.examples.AtLeast
56
import org.utbot.examples.UtValueTestCaseChecker
67
import org.utbot.examples.Full
78
import org.utbot.examples.FullWithAssumptions
@@ -454,12 +455,12 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker(
454455

455456
@Test
456457
fun testIteratorExample() {
457-
checkWithException(
458+
check(
458459
DoubleStreamExample::iteratorSumExample,
459460
ignoreExecutionsNumber,
460-
{ c, r -> null in c && r.isException<NullPointerException>() },
461-
{ c: List<Short?>, r -> null !in c && r.getOrThrow() == c.filterNotNull().sum() },
462-
coverage = FullWithAssumptions(assumeCallsNumber = 1)
461+
{ c, r -> c.isEmpty() && r == 0.0 },
462+
{ c: List<Short?>, r -> c.isNotEmpty() && c.doubles().sum() == r },
463+
coverage = AtLeast(76)
463464
)
464465
}
465466

@@ -481,9 +482,9 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker(
481482
fun testClosedStreamExample() {
482483
checkWithException(
483484
DoubleStreamExample::closedStreamExample,
484-
eq(1),
485+
ignoreExecutionsNumber,
485486
{ _, r -> r.isException<IllegalStateException>() },
486-
coverage = FullWithAssumptions(assumeCallsNumber = 1)
487+
coverage = AtLeast(88)
487488
)
488489
}
489490

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.utbot.examples.stream
22

33
import org.junit.jupiter.api.Tag
44
import org.junit.jupiter.api.Test
5+
import org.utbot.examples.AtLeast
56
import org.utbot.examples.UtValueTestCaseChecker
67
import org.utbot.examples.Full
78
import org.utbot.examples.FullWithAssumptions
@@ -465,12 +466,12 @@ class IntStreamExampleTest : UtValueTestCaseChecker(
465466

466467
@Test
467468
fun testIteratorExample() {
468-
checkWithException(
469+
check(
469470
IntStreamExample::iteratorSumExample,
470471
ignoreExecutionsNumber,
471-
{ c, r -> null in c && r.isException<NullPointerException>() },
472-
{ c: List<Short?>, r -> null !in c && r.getOrThrow() == c.filterNotNull().sum() },
473-
coverage = FullWithAssumptions(assumeCallsNumber = 1)
472+
{ c, r -> c.isEmpty() && r == 0 },
473+
{ c: List<Short?>, r -> c.isNotEmpty() && c.ints().sum() == r },
474+
coverage = AtLeast(76)
474475
)
475476
}
476477

@@ -492,9 +493,9 @@ class IntStreamExampleTest : UtValueTestCaseChecker(
492493
fun testClosedStreamExample() {
493494
checkWithException(
494495
IntStreamExample::closedStreamExample,
495-
eq(1),
496+
ignoreExecutionsNumber,
496497
{ _, r -> r.isException<IllegalStateException>() },
497-
coverage = FullWithAssumptions(assumeCallsNumber = 1)
498+
coverage = AtLeast(88)
498499
)
499500
}
500501

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.utbot.examples.stream
22

33
import org.junit.jupiter.api.Tag
44
import org.junit.jupiter.api.Test
5+
import org.utbot.examples.AtLeast
56
import org.utbot.examples.UtValueTestCaseChecker
67
import org.utbot.examples.Full
78
import org.utbot.examples.FullWithAssumptions
@@ -332,7 +333,7 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
332333

333334
val longs = c.longs()
334335

335-
val allStatisticsAreCorrect = sum == longs.sum().toLong() &&
336+
val allStatisticsAreCorrect = sum == longs.sum() &&
336337
count == longs.size.toLong() &&
337338
min == longs.minOrNull() &&
338339
max == longs.maxOrNull()
@@ -455,12 +456,12 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
455456

456457
@Test
457458
fun testIteratorExample() {
458-
checkWithException(
459+
check(
459460
LongStreamExample::iteratorSumExample,
460461
ignoreExecutionsNumber,
461-
{ c, r -> null in c && r.isException<NullPointerException>() },
462-
{ c: List<Short?>, r -> null !in c && r.getOrThrow() == c.filterNotNull().sum() },
463-
coverage = FullWithAssumptions(assumeCallsNumber = 1)
462+
{ c, r -> c.isEmpty() && r == 0L },
463+
{ c: List<Short?>, r -> c.isNotEmpty() && c.longs().sum() == r },
464+
coverage = AtLeast(76)
464465
)
465466
}
466467

@@ -482,9 +483,9 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
482483
fun testClosedStreamExample() {
483484
checkWithException(
484485
LongStreamExample::closedStreamExample,
485-
eq(1),
486+
ignoreExecutionsNumber,
486487
{ _, r -> r.isException<IllegalStateException>() },
487-
coverage = FullWithAssumptions(assumeCallsNumber = 1)
488+
coverage = AtLeast(88)
488489
)
489490
}
490491

utbot-sample/src/main/java/org/utbot/examples/stream/BaseStreamExample.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,16 @@ Optional<Integer> findFirstExample(List<Integer> list) {
414414
}
415415
}
416416

417+
@SuppressWarnings("DuplicatedCode")
417418
Integer iteratorSumExample(List<Integer> list) {
418-
UtMock.assume(list != null && !list.isEmpty());
419+
UtMock.assume(list != null);
419420

420421
int sum = 0;
421422
Iterator<Integer> streamIterator = list.stream().iterator();
422423

423424
if (list.isEmpty()) {
424425
while (streamIterator.hasNext()) {
426+
// unreachable
425427
Integer value = streamIterator.next();
426428
sum += value;
427429
}
@@ -570,7 +572,7 @@ public Iterator<E> iterator() {
570572
@SuppressWarnings({"ManualArrayCopy", "unchecked"})
571573
@NotNull
572574
@Override
573-
public Object[] toArray() {
575+
public Object @NotNull [] toArray() {
574576
final int size = size();
575577
E[] arr = (E[]) new Object[size];
576578
for (int i = 0; i < size; i++) {

utbot-sample/src/main/java/org/utbot/examples/stream/DoubleStreamExample.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.function.DoubleToLongFunction;
1515
import java.util.function.DoubleUnaryOperator;
1616
import java.util.function.ToDoubleFunction;
17-
import java.util.stream.Collectors;
1817
import java.util.stream.DoubleStream;
1918

2019
@SuppressWarnings("IfStatementWithIdenticalBranches")
@@ -440,20 +439,21 @@ OptionalDouble findFirstExample(List<Short> list) {
440439
}
441440
}
442441

443-
List<Double> boxedExample(List<Short> list) {
442+
Object[] boxedExample(List<Short> list) {
444443
UtMock.assume(list != null);
445444

446-
return list.stream().mapToDouble(value -> value == null ? 0 : value.doubleValue()).boxed().collect(Collectors.toList());
445+
return list.stream().mapToDouble(value -> value == null ? 0 : value.doubleValue()).boxed().toArray();
447446
}
448447

449-
int iteratorSumExample(List<Short> list) {
450-
UtMock.assume(list != null && !list.isEmpty());
448+
double iteratorSumExample(List<Short> list) {
449+
UtMock.assume(list != null);
451450

452-
int sum = 0;
451+
double sum = 0;
453452
PrimitiveIterator.OfDouble streamIterator = list.stream().mapToDouble(value -> value == null ? 0 : value.doubleValue()).iterator();
454453

455454
if (list.isEmpty()) {
456455
while (streamIterator.hasNext()) {
456+
// unreachable
457457
Double value = streamIterator.next();
458458
sum += value;
459459
}
@@ -481,10 +481,10 @@ DoubleStream streamOfExample(double[] values) {
481481
long closedStreamExample(List<Short> values) {
482482
UtMock.assume(values != null);
483483

484-
DoubleStream intStream = values.stream().mapToDouble(value -> value == null ? 0 : value.doubleValue());
485-
intStream.count();
484+
DoubleStream doubleStream = values.stream().mapToDouble(value -> value == null ? 0 : value.doubleValue());
485+
doubleStream.count();
486486

487-
return intStream.count();
487+
return doubleStream.count();
488488
}
489489

490490
double[] generateExample() {

0 commit comments

Comments
 (0)