Skip to content

Commit 79fbb8e

Browse files
committed
� This is a combination of 5 commits.
� This is the 1st commit message: Fixed copyOf, copyOfRange and asList failures � The commit message #2 will be skipped: � Added symbolic implementation for Arrays.copyOf and Arrays.copyOfRange � The commit message #3 will be skipped: � Added tests for copyOf, copyOfRange and asList � The commit message #4 will be skipped: � Fixed implementation � The commit message #5 will be skipped: � Fixed tests
1 parent 8b8d9f3 commit 79fbb8e

File tree

9 files changed

+286
-69
lines changed

9 files changed

+286
-69
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.utbot.examples.arrays
2+
3+
import org.junit.jupiter.api.Test
4+
import org.utbot.testing.AtLeast
5+
import org.utbot.testing.FullWithAssumptions
6+
import org.utbot.testing.UtValueTestCaseChecker
7+
import org.utbot.testing.ignoreExecutionsNumber
8+
import org.utbot.testing.isException
9+
10+
class CopyOfExampleTest : UtValueTestCaseChecker(testClass = CopyOfExample::class) {
11+
@Test
12+
fun testCopyOf() {
13+
checkWithException(
14+
CopyOfExample::copyOfExample,
15+
ignoreExecutionsNumber,
16+
{ _, l, r -> l < 0 && r.isException<NegativeArraySizeException>() },
17+
{ arr, l, r -> arr.copyOf(l).contentEquals(r.getOrThrow()) },
18+
coverage = FullWithAssumptions(assumeCallsNumber = 1)
19+
)
20+
}
21+
22+
@Test
23+
fun testCopyOfRange() {
24+
checkWithException(
25+
CopyOfExample::copyOfRangeExample,
26+
ignoreExecutionsNumber,
27+
{ _, from, _, r -> from < 0 && r.isException<ArrayIndexOutOfBoundsException>() },
28+
{ arr, from, _, r -> from > arr.size && r.isException<ArrayIndexOutOfBoundsException>() },
29+
{ _, from, to, r -> from > to && r.isException<IllegalArgumentException>() },
30+
{ arr, from, to, r -> arr.copyOfRange(from, to).contentEquals(r.getOrThrow()) },
31+
coverage = AtLeast(82)
32+
)
33+
}
34+
}

utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart3Test.kt

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.utbot.testcheckers.eq
77
import org.utbot.testcheckers.ge
88
import org.utbot.testing.CodeGeneration
99
import org.utbot.testing.DoNotCalculate
10+
import org.utbot.testing.FullWithAssumptions
1011
import org.utbot.testing.UtValueTestCaseChecker
1112
import org.utbot.testing.between
1213
import org.utbot.testing.isException
@@ -217,6 +218,17 @@ internal class ListsPart3Test : UtValueTestCaseChecker(
217218
)
218219
}
219220

221+
@Test
222+
fun testAsListExample() {
223+
check(
224+
Lists::asListExample,
225+
eq(2),
226+
{ arr, r -> arr.isEmpty() && r!!.isEmpty() },
227+
{ arr, r -> arr.isNotEmpty() && arr.contentEquals(r!!.toTypedArray()) },
228+
coverage = FullWithAssumptions(assumeCallsNumber = 1)
229+
)
230+
}
231+
220232
@Test
221233
@Disabled("TODO: add choosing proper type in list wrapper")
222234
fun testRemoveFromList() {

utbot-framework/src/main/java/org/utbot/engine/overrides/System.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public static void arraycopy(Object src, int srcPos, Object dest, int destPos, i
210210
}
211211

212212
UtArrayMock.arraycopy(srcArray, srcPos, destArray, destPos, length);
213-
} else {
213+
} else if (src instanceof Object[]) {
214214
if (!(dest instanceof Object[])) {
215215
throw new ArrayStoreException();
216216
}
@@ -223,6 +223,9 @@ public static void arraycopy(Object src, int srcPos, Object dest, int destPos, i
223223
}
224224

225225
UtArrayMock.arraycopy(srcArray, srcPos, destArray, destPos, length);
226+
} else {
227+
// From docs: if the src argument refers to an object that is not an array, an ArrayStoreException will be thrown
228+
throw new ArrayStoreException();
226229
}
227230
}
228231
}

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

+4-5
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
import org.utbot.engine.overrides.collections.UtArrayList;
56

67
import java.util.List;
@@ -21,7 +22,7 @@ public static <T> Stream<T> stream(T[] array, int startInclusive, int endExclusi
2122
return new UtStream<>(array, startInclusive, endExclusive);
2223
}
2324

24-
// from docs - array is assumed to be umnodified during use
25+
// from docs - array is assumed to be unmodified during use
2526
public static IntStream stream(int[] array, int startInclusive, int endExclusive) {
2627
int size = array.length;
2728

@@ -37,7 +38,7 @@ public static IntStream stream(int[] array, int startInclusive, int endExclusive
3738
return new UtIntStream(data, startInclusive, endExclusive);
3839
}
3940

40-
// from docs - array is assumed to be umnodified during use
41+
// from docs - array is assumed to be unmodified during use
4142
public static LongStream stream(long[] array, int startInclusive, int endExclusive) {
4243
int size = array.length;
4344

@@ -53,7 +54,7 @@ public static LongStream stream(long[] array, int startInclusive, int endExclusi
5354
return new UtLongStream(data, startInclusive, endExclusive);
5455
}
5556

56-
// from docs - array is assumed to be umnodified during use
57+
// from docs - array is assumed to be unmodified during use
5758
public static DoubleStream stream(double[] array, int startInclusive, int endExclusive) {
5859
int size = array.length;
5960

@@ -75,6 +76,4 @@ public static <T> List<T> asList(T... a) {
7576
// TODO immutable collection https://github.com/UnitTestBot/UTBotJava/issues/398
7677
return new UtArrayList<>(a);
7778
}
78-
79-
// TODO primitive arrays https://github.com/UnitTestBot/UTBotJava/issues/146
8079
}

0 commit comments

Comments
 (0)