Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4888ffe

Browse files
committedSep 27, 2022
More fixes for review issues
1 parent d4b3023 commit 4888ffe

File tree

10 files changed

+56
-10
lines changed

10 files changed

+56
-10
lines changed
 

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
152152
}
153153

154154
@Test
155-
@Disabled("TODO UtArrayApplyForAll translation error https://github.com/UnitTestBot/UTBotJava/issues/630")
155+
@Tag("slow")
156156
fun testDistinctExample() {
157157
check(
158158
BaseStreamExample::distinctExample,

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker(
4545
}
4646
}
4747

48+
@Test
49+
fun testUseParameterStream() {
50+
withoutConcrete {
51+
check(
52+
DoubleStreamExample::useParameterStream,
53+
eq(2),
54+
{ s, r -> s.toArray().isEmpty() && r == 0 },
55+
{ s, r -> s.toArray().let {
56+
it.isNotEmpty() && r == it.size }
57+
},
58+
)
59+
}
60+
}
61+
4862
@Test
4963
fun testFilterExample() {
5064
check(

‎utbot-framework/src/main/java/org/utbot/engine/overrides/collections/RangeModifiableUnlimitedArray.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,17 @@ public void set(int index, E value) {
151151
public E get(int i) {
152152
return null;
153153
}
154+
155+
/**
156+
* Returns the element of this array on specified index without check for ClassCastException.
157+
*
158+
* @param i - index in list with element, that needs to be returned
159+
*/
160+
@SuppressWarnings({"unchecked", "CastCanBeRemovedNarrowingVariableType"})
161+
public E getWithoutClassCastExceptionCheck(int i) {
162+
final Object object = get(i);
163+
UtMock.disableClassCastExceptionCheck(object);
164+
165+
return (E) object;
166+
}
154167
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public DoubleStream skip(long n) {
299299
return new UtDoubleStream();
300300
}
301301

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

305305
Double[] elements = elementData.toCastedArray((int) n, newSize);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public IntStream skip(long n) {
300300
return new UtIntStream();
301301
}
302302

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

306306
Integer[] newData = elementData.toCastedArray((int) n, newSize);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public LongStream skip(long n) {
300300
return new UtLongStream();
301301
}
302302

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

306306
Long[] elements = elementData.toCastedArray((int) n, newSize);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public IntStream mapToInt(ToIntFunction<? super E> mapper) {
149149
int size = elementData.end;
150150
Integer[] data = new Integer[size];
151151
for (int i = 0; i < size; i++) {
152-
data[i] = mapper.applyAsInt(elementData.get(i));
152+
data[i] = mapper.applyAsInt(elementData.getWithoutClassCastExceptionCheck(i));
153153
}
154154

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

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

181181
return new UtDoubleStream(data, size);

‎utbot-framework/src/main/kotlin/org/utbot/engine/ObjectWrappers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ typealias MethodSymbolicImplementation = (Traverser, ObjectValue, SootMethod, Li
223223

224224
interface WrapperInterface {
225225
/**
226-
* Checks is there a symbolic implementation for [method].
226+
* Checks whether a symbolic implementation exists for the [method].
227227
*/
228228
fun isWrappedMethod(method: SootMethod): Boolean = method.name in wrappedMethods
229229

‎utbot-framework/src/main/kotlin/org/utbot/engine/StreamWrappers.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,23 @@ abstract class PrimitiveStreamWrapper(
137137
* Transforms a model for an array of wrappers (Integer, Long, etc) to an array of corresponding primitives.
138138
*/
139139
override fun UtArrayModel.transformElementsModel(): UtArrayModel {
140+
val primitiveConstModel = if (constModel is UtNullModel) {
141+
// UtNullModel is not allowed for primitive arrays
142+
elementsClassId.elementClassId!!.defaultValueModel()
143+
} else {
144+
constModel.wrapperModelToPrimitiveModel()
145+
}
146+
140147
return copy(
141148
classId = elementsClassId,
142-
constModel = constModel.wrapperModelToPrimitiveModel(),
149+
constModel = primitiveConstModel,
143150
stores = stores.mapValuesTo(mutableMapOf()) { it.value.wrapperModelToPrimitiveModel() }
144151
)
145152
}
146153

147154
/**
148155
* Transforms [this] to [UtPrimitiveModel] if it is an [UtAssembleModel] for the corresponding wrapper
149-
* (int to Integer, etc.), and throws an error otherwise.
156+
* (primitive int and wrapper Integer, etc.), and throws an error otherwise.
150157
*/
151158
private fun UtModel.wrapperModelToPrimitiveModel(): UtModel {
152159
require(this !is UtNullModel) {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ DoubleStream returningStreamAsParameterExample(DoubleStream s) {
3737
return s;
3838
}
3939

40+
int useParameterStream(DoubleStream s) {
41+
UtMock.assume(s != null);
42+
43+
final double[] values = s.toArray();
44+
45+
if (values.length == 0) {
46+
return 0;
47+
} else {
48+
return values.length;
49+
}
50+
}
51+
4052
boolean filterExample(List<Short> list) {
4153
UtMock.assume(list != null && !list.isEmpty());
4254

0 commit comments

Comments
 (0)
Please sign in to comment.