Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed failed tests
  • Loading branch information
Damtev committed Sep 28, 2022
commit 01ad8e51eb4e668d0d6a37aad878921dff43d291
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.utbot.examples.stream

import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import org.utbot.framework.plugin.api.CodegenLanguage
Expand Down Expand Up @@ -175,7 +174,6 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker(
}

@Test
@Disabled("TODO wrong returned value")
fun testPeekExample() {
checkThisAndStaticsAfter(
DoubleStreamExample::peekExample,
Expand All @@ -190,8 +188,8 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker(
check(
DoubleStreamExample::limitExample,
ignoreExecutionsNumber,
{ c, r -> c.size <= 5 && c.doubles().contentEquals(r) },
{ c, r -> c.size > 5 && c.take(5).doubles().contentEquals(r) },
{ c, r -> c.size <= 2 && c.doubles().contentEquals(r) },
{ c, r -> c.size > 2 && c.take(2).doubles().contentEquals(r) },
coverage = FullWithAssumptions(assumeCallsNumber = 1)
)
}
Expand All @@ -201,8 +199,8 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker(
check(
DoubleStreamExample::skipExample,
ignoreExecutionsNumber,
{ c, r -> c.size > 5 && c.drop(5).doubles().contentEquals(r) },
{ c, r -> c.size <= 5 && r!!.isEmpty() },
{ c, r -> c.size > 2 && c.drop(2).doubles().contentEquals(r) },
{ c, r -> c.size <= 2 && r!!.isEmpty() },
coverage = FullWithAssumptions(assumeCallsNumber = 1)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package org.utbot.examples.stream

import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.testcheckers.eq
import org.utbot.testcheckers.withPathSelectorStepsLimit
import org.utbot.testcheckers.withoutConcrete
import org.utbot.tests.infrastructure.*
import org.utbot.framework.plugin.api.CodegenLanguage
import java.util.OptionalDouble
import java.util.OptionalInt
import java.util.stream.IntStream
Expand Down Expand Up @@ -187,8 +187,8 @@ class IntStreamExampleTest : UtValueTestCaseChecker(
check(
IntStreamExample::limitExample,
ignoreExecutionsNumber,
{ c, r -> c.size <= 5 && c.ints().contentEquals(r) },
{ c, r -> c.size > 5 && c.take(5).ints().contentEquals(r) },
{ c, r -> c.size <= 2 && c.ints().contentEquals(r) },
{ c, r -> c.size > 2 && c.take(2).ints().contentEquals(r) },
coverage = FullWithAssumptions(assumeCallsNumber = 1)
)
}
Expand All @@ -198,8 +198,8 @@ class IntStreamExampleTest : UtValueTestCaseChecker(
check(
IntStreamExample::skipExample,
ignoreExecutionsNumber,
{ c, r -> c.size > 5 && c.drop(5).ints().contentEquals(r) },
{ c, r -> c.size <= 5 && r!!.isEmpty() },
{ c, r -> c.size > 2 && c.drop(2).ints().contentEquals(r) },
{ c, r -> c.size <= 2 && r!!.isEmpty() },
coverage = FullWithAssumptions(assumeCallsNumber = 1)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
LongStreamExample::flatMapExample,
ignoreExecutionsNumber,
{ c, r ->
val intLists = c.mapNotNull {
it.toLong().let { i -> listOf(i, i) }
val intLists = c.map {
(it?.toLong() ?: 0L).let { i -> listOf(i, i) }
}

r!!.contentEquals(intLists.flatten().toLongArray())
Expand Down Expand Up @@ -187,8 +187,8 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
check(
LongStreamExample::limitExample,
ignoreExecutionsNumber,
{ c, r -> c.size <= 5 && c.longs().contentEquals(r) },
{ c, r -> c.size > 5 && c.take(5).longs().contentEquals(r) },
{ c, r -> c.size <= 2 && c.longs().contentEquals(r) },
{ c, r -> c.size > 2 && c.take(2).longs().contentEquals(r) },
coverage = FullWithAssumptions(assumeCallsNumber = 1)
)
}
Expand All @@ -198,8 +198,8 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
check(
LongStreamExample::skipExample,
ignoreExecutionsNumber,
{ c, r -> c.size > 5 && c.drop(5).longs().contentEquals(r) },
{ c, r -> c.size <= 5 && r!!.isEmpty() },
{ c, r -> c.size > 2 && c.drop(2).longs().contentEquals(r) },
{ c, r -> c.size <= 2 && r!!.isEmpty() },
coverage = FullWithAssumptions(assumeCallsNumber = 1)
)
}
Expand Down Expand Up @@ -241,7 +241,11 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
LongStreamExample::optionalReduceExample,
ignoreExecutionsNumber,
{ c, r -> c.isEmpty() && r.getOrThrow() == OptionalLong.empty() },
{ c: List<Short?>, r -> c.isNotEmpty() && r.getOrThrow() == OptionalLong.of(c.filterNotNull().sum().toLong()) },
{ c: List<Short?>, r ->
c.isNotEmpty() && r.getOrThrow() == OptionalLong.of(
c.filterNotNull().sum().toLong()
)
},
coverage = FullWithAssumptions(assumeCallsNumber = 1)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ public DoubleStream limit(long maxSize) {
}

Double[] elements = elementData.toCastedArray(0, newSize);

return new UtDoubleStream(elements, newSize);
}

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

Double[] elements = new Double[newSize];
for (int i = (int) n; i < newSize; i++) {
elements[i] = elementData.get(i);
}
Double[] elements = elementData.toCastedArray((int) n, newSize);

return new UtDoubleStream(elements, newSize);
}
Expand Down Expand Up @@ -487,16 +485,13 @@ public boolean anyMatch(DoublePredicate predicate) {
preconditionCheckWithClosingStream();

int size = elementData.end;
boolean matches = false;
for (int i = 0; i < size; i++) {
matches |= predicate.test(elementData.get(i));
// if (predicate.test(elementData.get(i))) {
// return true;
// }
if (predicate.test(elementData.get(i))) {
return true;
}
}

// return false;
return matches;
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,7 @@ public IntStream limit(long maxSize) {
newSize = curSize;
}

Integer[] newData = new Integer[newSize];
for (int i = 0; i < newSize; i++) {
newData[i] = elementData.get(i);
}
Integer[] newData = elementData.toCastedArray(0, newSize);

return new UtIntStream(newData, newSize);
}
Expand All @@ -305,10 +302,7 @@ public IntStream skip(long n) {
return new UtIntStream();
}

Integer[] newData = new Integer[newSize];
for (int i = (int) n; i < newSize; i++) {
newData[i] = elementData.get(i);
}
Integer[] newData = elementData.toCastedArray((int) n, newSize);

return new UtIntStream(newData, newSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,7 @@ public LongStream limit(long maxSize) {
newSize = curSize;
}

Long[] elements = new Long[newSize];
for (int i = 0; i < newSize; i++) {
elements[i] = elementData.get(i);
}
Long[] elements = elementData.toCastedArray(0, newSize);

return new UtLongStream(elements, newSize);
}
Expand All @@ -305,10 +302,7 @@ public LongStream skip(long n) {
return new UtLongStream();
}

Long[] elements = new Long[newSize];
for (int i = (int) n; i < newSize; i++) {
elements[i] = elementData.get(i);
}
Long[] elements = elementData.toCastedArray((int) n, newSize);

return new UtLongStream(elements, newSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,15 @@ public DoubleStream flatMapToDouble(Function<? super E, ? extends DoubleStream>
return null;
}

@SuppressWarnings("unchecked")
@Override
public Stream<E> distinct() {
preconditionCheckWithClosingStream();

int size = elementData.end;
// commented code is too difficult to analyze, so we have to use concrete execution here
executeConcretely();
return null;

/*int size = elementData.end;
Object[] distinctElements = new Object[size];
int distinctSize = 0;
for (int i = 0; i < size; i++) {
Expand Down Expand Up @@ -259,7 +262,7 @@ public Stream<E> distinct() {
}
}
return new UtStream<>((E[]) distinctElements, distinctSize);
return new UtStream<>((E[]) distinctElements, distinctSize);*/
}

// TODO choose the best sorting https://github.com/UnitTestBot/UTBotJava/issues/188
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,18 @@ int peekExample(List<Integer> list) {
int beforeStaticValue = x;

final Consumer<Integer> action = value -> x += value;
final Stream<Integer> stream = list.stream();

Stream<Integer> afterPeek;
if (list.contains(null)) {
list.stream().peek(action);
afterPeek = stream.peek(action);
} else {
list.stream().peek(action);
afterPeek = stream.peek(action);
}

// use terminal operation to force peek action
afterPeek.count();

return beforeStaticValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,16 @@ int peekExample(List<Short> list) {
final ToDoubleFunction<Short> shortToDoubleFunction = value -> value == null ? 0 : value.doubleValue();
final DoubleStream doubles = list.stream().mapToDouble(shortToDoubleFunction);

DoubleStream afterPeek;
if (list.contains(null)) {
doubles.peek(action);
afterPeek = doubles.peek(action);
} else {
doubles.peek(action);
afterPeek = doubles.peek(action);
}

// use terminal operation to force peek action
afterPeek.count();

return beforeStaticValue;
}

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

if (list.size() <= 5) {
return doubles.limit(5).toArray();
if (list.size() <= 2) {
return doubles.limit(2).toArray();
} else {
return doubles.limit(5).toArray();
return doubles.limit(2).toArray();
}
}

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

if (list.size() <= 5) {
return doubles.skip(5).toArray();
if (list.size() <= 2) {
return doubles.skip(2).toArray();
} else {
return doubles.skip(5).toArray();
return doubles.skip(2).toArray();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,16 @@ int peekExample(List<Short> list) {
final ToIntFunction<Short> shortToIntFunction = value -> value == null ? 0 : value.intValue();
final IntStream ints = list.stream().mapToInt(shortToIntFunction);

IntStream afterPeek;
if (list.contains(null)) {
ints.peek(action);
afterPeek = ints.peek(action);
} else {
ints.peek(action);
afterPeek = ints.peek(action);
}

// use terminal operation to force peek action
afterPeek.count();

return beforeStaticValue;
}

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

if (list.size() <= 5) {
return ints.limit(5).toArray();
if (list.size() <= 2) {
return ints.limit(2).toArray();
} else {
return ints.limit(5).toArray();
return ints.limit(2).toArray();
}
}

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

if (list.size() <= 5) {
return ints.skip(5).toArray();
if (list.size() <= 2) {
return ints.skip(2).toArray();
} else {
return ints.skip(5).toArray();
return ints.skip(2).toArray();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,16 @@ int peekExample(List<Short> list) {
final ToLongFunction<Short> shortToLongFunction = value -> value == null ? 0 : value.longValue();
final LongStream longs = list.stream().mapToLong(shortToLongFunction);

LongStream afterPeek;
if (list.contains(null)) {
longs.peek(action);
afterPeek = longs.peek(action);
} else {
longs.peek(action);
afterPeek = longs.peek(action);
}

// use terminal operation to force peek action
afterPeek.count();

return beforeStaticValue;
}

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

if (list.size() <= 5) {
return longs.limit(5).toArray();
if (list.size() <= 2) {
return longs.limit(2).toArray();
} else {
return longs.limit(5).toArray();
return longs.limit(2).toArray();
}
}

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

if (list.size() <= 5) {
return longs.skip(5).toArray();
if (list.size() <= 2) {
return longs.skip(2).toArray();
} else {
return longs.skip(5).toArray();
return longs.skip(2).toArray();
}
}

Expand Down