Skip to content

Commit f0a7c10

Browse files
committed
Fixed failed tests
1 parent 2d3c64d commit f0a7c10

File tree

11 files changed

+80
-74
lines changed

11 files changed

+80
-74
lines changed

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.utbot.examples.stream
22

3-
import org.junit.jupiter.api.Disabled
43
import org.junit.jupiter.api.Tag
54
import org.junit.jupiter.api.Test
65
import org.utbot.framework.plugin.api.CodegenLanguage
@@ -175,7 +174,6 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker(
175174
}
176175

177176
@Test
178-
@Disabled("TODO wrong returned value")
179177
fun testPeekExample() {
180178
checkThisAndStaticsAfter(
181179
DoubleStreamExample::peekExample,
@@ -190,8 +188,8 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker(
190188
check(
191189
DoubleStreamExample::limitExample,
192190
ignoreExecutionsNumber,
193-
{ c, r -> c.size <= 5 && c.doubles().contentEquals(r) },
194-
{ c, r -> c.size > 5 && c.take(5).doubles().contentEquals(r) },
191+
{ c, r -> c.size <= 2 && c.doubles().contentEquals(r) },
192+
{ c, r -> c.size > 2 && c.take(2).doubles().contentEquals(r) },
195193
coverage = FullWithAssumptions(assumeCallsNumber = 1)
196194
)
197195
}
@@ -201,8 +199,8 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker(
201199
check(
202200
DoubleStreamExample::skipExample,
203201
ignoreExecutionsNumber,
204-
{ c, r -> c.size > 5 && c.drop(5).doubles().contentEquals(r) },
205-
{ c, r -> c.size <= 5 && r!!.isEmpty() },
202+
{ c, r -> c.size > 2 && c.drop(2).doubles().contentEquals(r) },
203+
{ c, r -> c.size <= 2 && r!!.isEmpty() },
206204
coverage = FullWithAssumptions(assumeCallsNumber = 1)
207205
)
208206
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package org.utbot.examples.stream
22

33
import org.junit.jupiter.api.Tag
44
import org.junit.jupiter.api.Test
5+
import org.utbot.framework.plugin.api.CodegenLanguage
56
import org.utbot.testcheckers.eq
67
import org.utbot.testcheckers.withPathSelectorStepsLimit
78
import org.utbot.testcheckers.withoutConcrete
89
import org.utbot.tests.infrastructure.*
9-
import org.utbot.framework.plugin.api.CodegenLanguage
1010
import java.util.OptionalDouble
1111
import java.util.OptionalInt
1212
import java.util.stream.IntStream
@@ -187,8 +187,8 @@ class IntStreamExampleTest : UtValueTestCaseChecker(
187187
check(
188188
IntStreamExample::limitExample,
189189
ignoreExecutionsNumber,
190-
{ c, r -> c.size <= 5 && c.ints().contentEquals(r) },
191-
{ c, r -> c.size > 5 && c.take(5).ints().contentEquals(r) },
190+
{ c, r -> c.size <= 2 && c.ints().contentEquals(r) },
191+
{ c, r -> c.size > 2 && c.take(2).ints().contentEquals(r) },
192192
coverage = FullWithAssumptions(assumeCallsNumber = 1)
193193
)
194194
}
@@ -198,8 +198,8 @@ class IntStreamExampleTest : UtValueTestCaseChecker(
198198
check(
199199
IntStreamExample::skipExample,
200200
ignoreExecutionsNumber,
201-
{ c, r -> c.size > 5 && c.drop(5).ints().contentEquals(r) },
202-
{ c, r -> c.size <= 5 && r!!.isEmpty() },
201+
{ c, r -> c.size > 2 && c.drop(2).ints().contentEquals(r) },
202+
{ c, r -> c.size <= 2 && r!!.isEmpty() },
203203
coverage = FullWithAssumptions(assumeCallsNumber = 1)
204204
)
205205
}

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

+11-7
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
131131
LongStreamExample::flatMapExample,
132132
ignoreExecutionsNumber,
133133
{ c, r ->
134-
val intLists = c.mapNotNull {
135-
it.toLong().let { i -> listOf(i, i) }
134+
val intLists = c.map {
135+
(it?.toLong() ?: 0L).let { i -> listOf(i, i) }
136136
}
137137

138138
r!!.contentEquals(intLists.flatten().toLongArray())
@@ -187,8 +187,8 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
187187
check(
188188
LongStreamExample::limitExample,
189189
ignoreExecutionsNumber,
190-
{ c, r -> c.size <= 5 && c.longs().contentEquals(r) },
191-
{ c, r -> c.size > 5 && c.take(5).longs().contentEquals(r) },
190+
{ c, r -> c.size <= 2 && c.longs().contentEquals(r) },
191+
{ c, r -> c.size > 2 && c.take(2).longs().contentEquals(r) },
192192
coverage = FullWithAssumptions(assumeCallsNumber = 1)
193193
)
194194
}
@@ -198,8 +198,8 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
198198
check(
199199
LongStreamExample::skipExample,
200200
ignoreExecutionsNumber,
201-
{ c, r -> c.size > 5 && c.drop(5).longs().contentEquals(r) },
202-
{ c, r -> c.size <= 5 && r!!.isEmpty() },
201+
{ c, r -> c.size > 2 && c.drop(2).longs().contentEquals(r) },
202+
{ c, r -> c.size <= 2 && r!!.isEmpty() },
203203
coverage = FullWithAssumptions(assumeCallsNumber = 1)
204204
)
205205
}
@@ -241,7 +241,11 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
241241
LongStreamExample::optionalReduceExample,
242242
ignoreExecutionsNumber,
243243
{ c, r -> c.isEmpty() && r.getOrThrow() == OptionalLong.empty() },
244-
{ c: List<Short?>, r -> c.isNotEmpty() && r.getOrThrow() == OptionalLong.of(c.filterNotNull().sum().toLong()) },
244+
{ c: List<Short?>, r ->
245+
c.isNotEmpty() && r.getOrThrow() == OptionalLong.of(
246+
c.filterNotNull().sum().toLong()
247+
)
248+
},
245249
coverage = FullWithAssumptions(assumeCallsNumber = 1)
246250
)
247251
}

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

+6-11
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ public DoubleStream limit(long maxSize) {
277277
}
278278

279279
Double[] elements = elementData.toCastedArray(0, newSize);
280+
280281
return new UtDoubleStream(elements, newSize);
281282
}
282283

@@ -300,10 +301,7 @@ public DoubleStream skip(long n) {
300301
return new UtDoubleStream();
301302
}
302303

303-
Double[] elements = new Double[newSize];
304-
for (int i = (int) n; i < newSize; i++) {
305-
elements[i] = elementData.get(i);
306-
}
304+
Double[] elements = elementData.toCastedArray((int) n, newSize);
307305

308306
return new UtDoubleStream(elements, newSize);
309307
}
@@ -487,16 +485,13 @@ public boolean anyMatch(DoublePredicate predicate) {
487485
preconditionCheckWithClosingStream();
488486

489487
int size = elementData.end;
490-
boolean matches = false;
491488
for (int i = 0; i < size; i++) {
492-
matches |= predicate.test(elementData.get(i));
493-
// if (predicate.test(elementData.get(i))) {
494-
// return true;
495-
// }
489+
if (predicate.test(elementData.get(i))) {
490+
return true;
491+
}
496492
}
497493

498-
// return false;
499-
return matches;
494+
return false;
500495
}
501496

502497
@Override

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

+2-8
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,7 @@ public IntStream limit(long maxSize) {
277277
newSize = curSize;
278278
}
279279

280-
Integer[] newData = new Integer[newSize];
281-
for (int i = 0; i < newSize; i++) {
282-
newData[i] = elementData.get(i);
283-
}
280+
Integer[] newData = elementData.toCastedArray(0, newSize);
284281

285282
return new UtIntStream(newData, newSize);
286283
}
@@ -305,10 +302,7 @@ public IntStream skip(long n) {
305302
return new UtIntStream();
306303
}
307304

308-
Integer[] newData = new Integer[newSize];
309-
for (int i = (int) n; i < newSize; i++) {
310-
newData[i] = elementData.get(i);
311-
}
305+
Integer[] newData = elementData.toCastedArray((int) n, newSize);
312306

313307
return new UtIntStream(newData, newSize);
314308
}

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

+2-8
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,7 @@ public LongStream limit(long maxSize) {
277277
newSize = curSize;
278278
}
279279

280-
Long[] elements = new Long[newSize];
281-
for (int i = 0; i < newSize; i++) {
282-
elements[i] = elementData.get(i);
283-
}
280+
Long[] elements = elementData.toCastedArray(0, newSize);
284281

285282
return new UtLongStream(elements, newSize);
286283
}
@@ -305,10 +302,7 @@ public LongStream skip(long n) {
305302
return new UtLongStream();
306303
}
307304

308-
Long[] elements = new Long[newSize];
309-
for (int i = (int) n; i < newSize; i++) {
310-
elements[i] = elementData.get(i);
311-
}
305+
Long[] elements = elementData.toCastedArray((int) n, newSize);
312306

313307
return new UtLongStream(elements, newSize);
314308
}

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,15 @@ public DoubleStream flatMapToDouble(Function<? super E, ? extends DoubleStream>
224224
return null;
225225
}
226226

227-
@SuppressWarnings("unchecked")
228227
@Override
229228
public Stream<E> distinct() {
230229
preconditionCheckWithClosingStream();
231230

232-
int size = elementData.end;
231+
// commented code is too difficult to analyze, so we have to use concrete execution here
232+
executeConcretely();
233+
return null;
234+
235+
/*int size = elementData.end;
233236
Object[] distinctElements = new Object[size];
234237
int distinctSize = 0;
235238
for (int i = 0; i < size; i++) {
@@ -259,7 +262,7 @@ public Stream<E> distinct() {
259262
}
260263
}
261264
262-
return new UtStream<>((E[]) distinctElements, distinctSize);
265+
return new UtStream<>((E[]) distinctElements, distinctSize);*/
263266
}
264267

265268
// TODO choose the best sorting https://github.com/UnitTestBot/UTBotJava/issues/188

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,18 @@ int peekExample(List<Integer> list) {
173173
int beforeStaticValue = x;
174174

175175
final Consumer<Integer> action = value -> x += value;
176+
final Stream<Integer> stream = list.stream();
177+
178+
Stream<Integer> afterPeek;
176179
if (list.contains(null)) {
177-
list.stream().peek(action);
180+
afterPeek = stream.peek(action);
178181
} else {
179-
list.stream().peek(action);
182+
afterPeek = stream.peek(action);
180183
}
181184

185+
// use terminal operation to force peek action
186+
afterPeek.count();
187+
182188
return beforeStaticValue;
183189
}
184190

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

+12-8
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,16 @@ int peekExample(List<Short> list) {
152152
final ToDoubleFunction<Short> shortToDoubleFunction = value -> value == null ? 0 : value.doubleValue();
153153
final DoubleStream doubles = list.stream().mapToDouble(shortToDoubleFunction);
154154

155+
DoubleStream afterPeek;
155156
if (list.contains(null)) {
156-
doubles.peek(action);
157+
afterPeek = doubles.peek(action);
157158
} else {
158-
doubles.peek(action);
159+
afterPeek = doubles.peek(action);
159160
}
160161

162+
// use terminal operation to force peek action
163+
afterPeek.count();
164+
161165
return beforeStaticValue;
162166
}
163167

@@ -167,10 +171,10 @@ int peekExample(List<Short> list) {
167171
final ToDoubleFunction<Short> shortToDoubleFunction = value -> value == null ? 0 : value.doubleValue();
168172
final DoubleStream doubles = list.stream().mapToDouble(shortToDoubleFunction);
169173

170-
if (list.size() <= 5) {
171-
return doubles.limit(5).toArray();
174+
if (list.size() <= 2) {
175+
return doubles.limit(2).toArray();
172176
} else {
173-
return doubles.limit(5).toArray();
177+
return doubles.limit(2).toArray();
174178
}
175179
}
176180

@@ -180,10 +184,10 @@ int peekExample(List<Short> list) {
180184
final ToDoubleFunction<Short> shortToDoubleFunction = value -> value == null ? 0 : value.doubleValue();
181185
final DoubleStream doubles = list.stream().mapToDouble(shortToDoubleFunction);
182186

183-
if (list.size() <= 5) {
184-
return doubles.skip(5).toArray();
187+
if (list.size() <= 2) {
188+
return doubles.skip(2).toArray();
185189
} else {
186-
return doubles.skip(5).toArray();
190+
return doubles.skip(2).toArray();
187191
}
188192
}
189193

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

+12-8
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,16 @@ int peekExample(List<Short> list) {
155155
final ToIntFunction<Short> shortToIntFunction = value -> value == null ? 0 : value.intValue();
156156
final IntStream ints = list.stream().mapToInt(shortToIntFunction);
157157

158+
IntStream afterPeek;
158159
if (list.contains(null)) {
159-
ints.peek(action);
160+
afterPeek = ints.peek(action);
160161
} else {
161-
ints.peek(action);
162+
afterPeek = ints.peek(action);
162163
}
163164

165+
// use terminal operation to force peek action
166+
afterPeek.count();
167+
164168
return beforeStaticValue;
165169
}
166170

@@ -170,10 +174,10 @@ int[] limitExample(List<Short> list) {
170174
final ToIntFunction<Short> shortToIntFunction = value -> value == null ? 0 : value.intValue();
171175
final IntStream ints = list.stream().mapToInt(shortToIntFunction);
172176

173-
if (list.size() <= 5) {
174-
return ints.limit(5).toArray();
177+
if (list.size() <= 2) {
178+
return ints.limit(2).toArray();
175179
} else {
176-
return ints.limit(5).toArray();
180+
return ints.limit(2).toArray();
177181
}
178182
}
179183

@@ -183,10 +187,10 @@ int[] skipExample(List<Short> list) {
183187
final ToIntFunction<Short> shortToIntFunction = value -> value == null ? 0 : value.intValue();
184188
final IntStream ints = list.stream().mapToInt(shortToIntFunction);
185189

186-
if (list.size() <= 5) {
187-
return ints.skip(5).toArray();
190+
if (list.size() <= 2) {
191+
return ints.skip(2).toArray();
188192
} else {
189-
return ints.skip(5).toArray();
193+
return ints.skip(2).toArray();
190194
}
191195
}
192196

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

+12-8
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,16 @@ int peekExample(List<Short> list) {
154154
final ToLongFunction<Short> shortToLongFunction = value -> value == null ? 0 : value.longValue();
155155
final LongStream longs = list.stream().mapToLong(shortToLongFunction);
156156

157+
LongStream afterPeek;
157158
if (list.contains(null)) {
158-
longs.peek(action);
159+
afterPeek = longs.peek(action);
159160
} else {
160-
longs.peek(action);
161+
afterPeek = longs.peek(action);
161162
}
162163

164+
// use terminal operation to force peek action
165+
afterPeek.count();
166+
163167
return beforeStaticValue;
164168
}
165169

@@ -169,10 +173,10 @@ long[] limitExample(List<Short> list) {
169173
final ToLongFunction<Short> shortToLongFunction = value -> value == null ? 0 : value.longValue();
170174
final LongStream longs = list.stream().mapToLong(shortToLongFunction);
171175

172-
if (list.size() <= 5) {
173-
return longs.limit(5).toArray();
176+
if (list.size() <= 2) {
177+
return longs.limit(2).toArray();
174178
} else {
175-
return longs.limit(5).toArray();
179+
return longs.limit(2).toArray();
176180
}
177181
}
178182

@@ -182,10 +186,10 @@ long[] skipExample(List<Short> list) {
182186
final ToLongFunction<Short> shortToLongFunction = value -> value == null ? 0 : value.longValue();
183187
final LongStream longs = list.stream().mapToLong(shortToLongFunction);
184188

185-
if (list.size() <= 5) {
186-
return longs.skip(5).toArray();
189+
if (list.size() <= 2) {
190+
return longs.skip(2).toArray();
187191
} else {
188-
return longs.skip(5).toArray();
192+
return longs.skip(2).toArray();
189193
}
190194
}
191195

0 commit comments

Comments
 (0)