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
More fixes for review issues
  • Loading branch information
Damtev committed Sep 28, 2022
commit 78c9c4f3317d54abd4adfb337619ba0898ca4fe3
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
}

@Test
@Disabled("TODO UtArrayApplyForAll translation error https://github.com/UnitTestBot/UTBotJava/issues/630")
@Tag("slow")
fun testDistinctExample() {
check(
BaseStreamExample::distinctExample,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker(
}
}

@Test
fun testUseParameterStream() {
withoutConcrete {
check(
DoubleStreamExample::useParameterStream,
eq(2),
{ s, r -> s.toArray().isEmpty() && r == 0 },
{ s, r -> s.toArray().let {
it.isNotEmpty() && r == it.size }
},
)
}
}

@Test
fun testFilterExample() {
check(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,17 @@ public void set(int index, E value) {
public E get(int i) {
return null;
}

/**
* Returns the element of this array on specified index without check for ClassCastException.
*
* @param i - index in list with element, that needs to be returned
*/
@SuppressWarnings({"unchecked", "CastCanBeRemovedNarrowingVariableType"})
public E getWithoutClassCastExceptionCheck(int i) {
final Object object = get(i);
UtMock.disableClassCastExceptionCheck(object);

return (E) object;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public DoubleStream skip(long n) {
return new UtDoubleStream();
}

// n is 0...(Integer.MAX_VALUE - 1) here
// n is 1...(Integer.MAX_VALUE - 1) here
int newSize = (int) (curSize - n);
Comment thread
CaelmBleidd marked this conversation as resolved.

Double[] elements = elementData.toCastedArray((int) n, newSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public IntStream skip(long n) {
return new UtIntStream();
}

// n is 0...(Integer.MAX_VALUE - 1) here
// n is 1...(Integer.MAX_VALUE - 1) here
int newSize = (int) (curSize - n);

Integer[] newData = elementData.toCastedArray((int) n, newSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public LongStream skip(long n) {
return new UtLongStream();
}

// n is 0...(Integer.MAX_VALUE - 1) here
// n is 1...(Integer.MAX_VALUE - 1) here
int newSize = (int) (curSize - n);

Long[] elements = elementData.toCastedArray((int) n, newSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public IntStream mapToInt(ToIntFunction<? super E> mapper) {
int size = elementData.end;
Integer[] data = new Integer[size];
for (int i = 0; i < size; i++) {
data[i] = mapper.applyAsInt(elementData.get(i));
data[i] = mapper.applyAsInt(elementData.getWithoutClassCastExceptionCheck(i));
}

return new UtIntStream(data, size);
Expand All @@ -162,7 +162,7 @@ public LongStream mapToLong(ToLongFunction<? super E> mapper) {
int size = elementData.end;
Long[] data = new Long[size];
for (int i = 0; i < size; i++) {
data[i] = mapper.applyAsLong(elementData.get(i));
data[i] = mapper.applyAsLong(elementData.getWithoutClassCastExceptionCheck(i));
}

return new UtLongStream(data, size);
Expand All @@ -175,7 +175,7 @@ public DoubleStream mapToDouble(ToDoubleFunction<? super E> mapper) {
int size = elementData.end;
Double[] data = new Double[size];
for (int i = 0; i < size; i++) {
data[i] = mapper.applyAsDouble(elementData.get(i));
data[i] = mapper.applyAsDouble(elementData.getWithoutClassCastExceptionCheck(i));
}

return new UtDoubleStream(data, size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ typealias MethodSymbolicImplementation = (Traverser, ObjectValue, SootMethod, Li

interface WrapperInterface {
/**
* Checks is there a symbolic implementation for [method].
* Checks whether a symbolic implementation exists for the [method].
*/
fun isWrappedMethod(method: SootMethod): Boolean = method.name in wrappedMethods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,23 @@ abstract class PrimitiveStreamWrapper(
* Transforms a model for an array of wrappers (Integer, Long, etc) to an array of corresponding primitives.
*/
override fun UtArrayModel.transformElementsModel(): UtArrayModel {
val primitiveConstModel = if (constModel is UtNullModel) {
// UtNullModel is not allowed for primitive arrays
elementsClassId.elementClassId!!.defaultValueModel()
} else {
constModel.wrapperModelToPrimitiveModel()
}

return copy(
classId = elementsClassId,
constModel = constModel.wrapperModelToPrimitiveModel(),
constModel = primitiveConstModel,
stores = stores.mapValuesTo(mutableMapOf()) { it.value.wrapperModelToPrimitiveModel() }
)
}

/**
* Transforms [this] to [UtPrimitiveModel] if it is an [UtAssembleModel] for the corresponding wrapper
* (int to Integer, etc.), and throws an error otherwise.
* (primitive int and wrapper Integer, etc.), and throws an error otherwise.
*/
private fun UtModel.wrapperModelToPrimitiveModel(): UtModel {
Comment thread
CaelmBleidd marked this conversation as resolved.
require(this !is UtNullModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ DoubleStream returningStreamAsParameterExample(DoubleStream s) {
return s;
}

int useParameterStream(DoubleStream s) {
UtMock.assume(s != null);

final double[] values = s.toArray();

if (values.length == 0) {
return 0;
} else {
return values.length;
}
}

boolean filterExample(List<Short> list) {
UtMock.assume(list != null && !list.isEmpty());

Expand Down