Skip to content

Commit 908b6fe

Browse files
committed
Fixed tests
1 parent 49a5852 commit 908b6fe

File tree

9 files changed

+93
-154
lines changed

9 files changed

+93
-154
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
8484
checkWithException(
8585
BaseStreamExample::mapToIntExample,
8686
ignoreExecutionsNumber,
87-
{ c, r -> null in c && r.isException<NullPointerException>() },
88-
{ c, r -> r.getOrThrow().contentEquals(c.map { it.toInt() }.toIntArray()) },
87+
{ c, r ->
88+
(null in c && r.isException<NullPointerException>()) ||
89+
r.getOrThrow().contentEquals(c.map { it.toInt() }.toIntArray())
90+
},
8991
coverage = AtLeast(90)
9092
)
9193
}
@@ -95,8 +97,10 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
9597
checkWithException(
9698
BaseStreamExample::mapToLongExample,
9799
ignoreExecutionsNumber,
98-
{ c, r -> null in c && r.isException<NullPointerException>() },
99-
{ c, r -> r.getOrThrow().contentEquals(c.map { it.toLong() }.toLongArray()) },
100+
{ c, r ->
101+
(null in c && r.isException<NullPointerException>()) ||
102+
r.getOrThrow().contentEquals(c.map { it.toLong() }.toLongArray())
103+
},
100104
coverage = AtLeast(90)
101105
)
102106
}
@@ -106,8 +110,10 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
106110
checkWithException(
107111
BaseStreamExample::mapToDoubleExample,
108112
ignoreExecutionsNumber,
109-
{ c, r -> null in c && r.isException<NullPointerException>() },
110-
{ c, r -> r.getOrThrow().contentEquals(c.map { it.toDouble() }.toDoubleArray()) },
113+
{ c, r ->
114+
(null in c && r.isException<NullPointerException>()) ||
115+
r.getOrThrow().contentEquals(c.map { it.toDouble() }.toDoubleArray())
116+
},
111117
coverage = AtLeast(90)
112118
)
113119
}

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker(
6868
check(
6969
DoubleStreamExample::mapExample,
7070
ignoreExecutionsNumber,
71-
{ c, r -> null in c && r.contentEquals(c.doubles { it?.toDouble()?.times(2) ?: 0.0 }) },
72-
{ c: List<Short?>, r -> null !in c && r.contentEquals(c.doubles { it?.toDouble()?.times(2) ?: 0.0 }) },
71+
{ c, r ->
72+
(null in c && r.contentEquals(c.doubles { it?.toDouble()?.times(2) ?: 0.0 })) ||
73+
(null !in c && r.contentEquals(c.doubles { it?.toDouble()?.times(2) ?: 0.0 }))
74+
},
7375
coverage = FullWithAssumptions(assumeCallsNumber = 1)
7476
)
7577
}
@@ -82,14 +84,11 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker(
8284
{ c, r ->
8385
val intArrays = c.doubles().map { it.let { i -> doubleArrayOf(i, i) } }.toTypedArray()
8486

85-
null in c && intArrays.zip(r as Array<out Any>)
86-
.all { it.first.contentEquals(it.second as DoubleArray?) }
87-
},
88-
{ c: List<Short?>, r ->
89-
val intArrays = c.doubles().map { it.let { i -> doubleArrayOf(i, i) } }.toTypedArray()
90-
91-
null !in c && intArrays.zip(r as Array<out Any>)
92-
.all { it.first.contentEquals(it.second as DoubleArray?) }
87+
intArrays
88+
.zip(r as Array<out Any>)
89+
.all {
90+
it.first.contentEquals(it.second as DoubleArray?)
91+
}
9392
},
9493
coverage = FullWithAssumptions(assumeCallsNumber = 1)
9594
)
@@ -103,12 +102,7 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker(
103102
{ c, r ->
104103
val ints = c.doubles().map { it.toInt() }.toIntArray()
105104

106-
null in c && ints.contentEquals(r)
107-
},
108-
{ c: List<Short?>, r ->
109-
val ints = c.doubles().map { it.toInt() }.toIntArray()
110-
111-
null !in c && ints.contentEquals(r)
105+
ints.contentEquals(r)
112106
},
113107
coverage = FullWithAssumptions(assumeCallsNumber = 1)
114108
)
@@ -122,12 +116,7 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker(
122116
{ c, r ->
123117
val longs = c.doubles().map { it.toLong() }.toLongArray()
124118

125-
null in c && longs.contentEquals(r)
126-
},
127-
{ c: List<Short?>, r ->
128-
val longs = c.doubles().map { it.toLong() }.toLongArray()
129-
130-
null !in c && longs.contentEquals(r)
119+
longs.contentEquals(r)
131120
},
132121
coverage = FullWithAssumptions(assumeCallsNumber = 1)
133122
)

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

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ class IntStreamExampleTest : UtValueTestCaseChecker(
6969
check(
7070
IntStreamExample::mapExample,
7171
ignoreExecutionsNumber,
72-
{ c, r -> null in c && r.contentEquals(c.ints { it?.toInt()?.times(2) ?: 0 }) },
73-
{ c: List<Short?>, r -> null !in c && r.contentEquals(c.ints { it?.toInt()?.times(2) ?: 0 }) },
72+
{ c, r -> r.contentEquals(c.ints { it?.toInt()?.times(2) ?: 0 }) },
7473
coverage = FullWithAssumptions(assumeCallsNumber = 1)
7574
)
7675
}
@@ -83,12 +82,11 @@ class IntStreamExampleTest : UtValueTestCaseChecker(
8382
{ c, r ->
8483
val intArrays = c.ints().map { it.let { i -> intArrayOf(i, i) } }.toTypedArray()
8584

86-
null in c && intArrays.zip(r as Array<out Any>).all { it.first.contentEquals(it.second as IntArray?) }
87-
},
88-
{ c: List<Short?>, r ->
89-
val intArrays = c.ints().map { it.let { i -> intArrayOf(i, i) } }.toTypedArray()
90-
91-
null !in c && intArrays.zip(r as Array<out Any>).all { it.first.contentEquals(it.second as IntArray?) }
85+
intArrays
86+
.zip(r as Array<out Any>)
87+
.all {
88+
it.first.contentEquals(it.second as IntArray?)
89+
}
9290
},
9391
coverage = FullWithAssumptions(assumeCallsNumber = 1)
9492
)
@@ -102,12 +100,7 @@ class IntStreamExampleTest : UtValueTestCaseChecker(
102100
{ c, r ->
103101
val longs = c.ints().map { it.toLong() * 2 }.toLongArray()
104102

105-
null in c && longs.contentEquals(r)
106-
},
107-
{ c: List<Short?>, r ->
108-
val longs = c.ints().map { it.toLong() * 2 }.toLongArray()
109-
110-
null !in c && longs.contentEquals(r)
103+
longs.contentEquals(r)
111104
},
112105
coverage = FullWithAssumptions(assumeCallsNumber = 1)
113106
)
@@ -121,12 +114,7 @@ class IntStreamExampleTest : UtValueTestCaseChecker(
121114
{ c, r ->
122115
val doubles = c.ints().map { it.toDouble() / 2 }.toDoubleArray()
123116

124-
null in c && doubles.contentEquals(r)
125-
},
126-
{ c: List<Short?>, r ->
127-
val doubles = c.filterNotNull().map { it.toDouble() / 2 }.toDoubleArray()
128-
129-
null !in c && doubles.contentEquals(r)
117+
doubles.contentEquals(r)
130118
},
131119
coverage = FullWithAssumptions(assumeCallsNumber = 1)
132120
)

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

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
6969
check(
7070
LongStreamExample::mapExample,
7171
ignoreExecutionsNumber,
72-
{ c, r -> null in c && r.contentEquals(c.longs { it?.toLong()?.times(2) ?: 0L }) },
73-
{ c: List<Short?>, r -> null !in c && r.contentEquals(c.longs { it?.toLong()?.times(2) ?: 0L }) },
72+
{ c, r -> r.contentEquals(c.longs { it?.toLong()?.times(2) ?: 0L }) },
7473
coverage = FullWithAssumptions(assumeCallsNumber = 1)
7574
)
7675
}
@@ -83,12 +82,11 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
8382
{ c, r ->
8483
val intArrays = c.longs().map { it.let { i -> longArrayOf(i, i) } }.toTypedArray()
8584

86-
null in c && intArrays.zip(r as Array<out Any>).all { it.first.contentEquals(it.second as LongArray?) }
87-
},
88-
{ c: List<Short?>, r ->
89-
val intArrays = c.longs().map { it.let { i -> longArrayOf(i, i) } }.toTypedArray()
90-
91-
null !in c && intArrays.zip(r as Array<out Any>).all { it.first.contentEquals(it.second as LongArray?) }
85+
intArrays
86+
.zip(r as Array<out Any>)
87+
.all {
88+
it.first.contentEquals(it.second as LongArray?)
89+
}
9290
},
9391
coverage = FullWithAssumptions(assumeCallsNumber = 1)
9492
)
@@ -102,12 +100,7 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
102100
{ c, r ->
103101
val ints = c.longs().map { it.toInt() }.toIntArray()
104102

105-
null in c && ints.contentEquals(r)
106-
},
107-
{ c: List<Short?>, r ->
108-
val ints = c.longs().map { it.toInt() }.toIntArray()
109-
110-
null !in c && ints.contentEquals(r)
103+
ints.contentEquals(r)
111104
},
112105
coverage = FullWithAssumptions(assumeCallsNumber = 1)
113106
)
@@ -121,12 +114,7 @@ class LongStreamExampleTest : UtValueTestCaseChecker(
121114
{ c, r ->
122115
val doubles = c.longs().map { it.toDouble() / 2 }.toDoubleArray()
123116

124-
null in c && doubles.contentEquals(r)
125-
},
126-
{ c: List<Short?>, r ->
127-
val doubles = c.filterNotNull().map { it.toDouble() / 2 }.toDoubleArray()
128-
129-
null !in c && doubles.contentEquals(r)
117+
doubles.contentEquals(r)
130118
},
131119
coverage = FullWithAssumptions(assumeCallsNumber = 1)
132120
)

utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,10 @@ import org.utbot.engine.overrides.stream.UtIntStream
4545
import org.utbot.engine.overrides.stream.UtLongStream
4646
import org.utbot.engine.overrides.stream.UtStream
4747
import org.utbot.engine.overrides.stream.actions.*
48-
import org.utbot.engine.overrides.stream.actions.objects.ConsumerAction
49-
import org.utbot.engine.overrides.stream.actions.DistinctAction
50-
import org.utbot.engine.overrides.stream.actions.objects.FilterAction
51-
import org.utbot.engine.overrides.stream.actions.LimitAction
52-
import org.utbot.engine.overrides.stream.actions.objects.MapAction
53-
import org.utbot.engine.overrides.stream.actions.NaturalSortingAction
54-
import org.utbot.engine.overrides.stream.actions.SkipAction
55-
import org.utbot.engine.overrides.stream.actions.objects.SortingAction
48+
import org.utbot.engine.overrides.stream.actions.objects.*
49+
import org.utbot.engine.overrides.stream.actions.primitives.doubles.*
50+
import org.utbot.engine.overrides.stream.actions.primitives.ints.*
51+
import org.utbot.engine.overrides.stream.actions.primitives.longs.*
5652
import org.utbot.engine.pureJavaSignature
5753
import org.utbot.framework.plugin.api.UtMethod
5854
import org.utbot.framework.plugin.api.util.signature
@@ -208,13 +204,45 @@ private val classesToLoad = arrayOf(
208204
IntStream::class,
209205
LongStream::class,
210206
DoubleStream::class,
207+
208+
// abstract stream action
211209
StreamAction::class,
212-
ConsumerAction::class,
210+
211+
// common stream actions
213212
DistinctAction::class,
214-
FilterAction::class,
215213
LimitAction::class,
216-
MapAction::class,
217214
NaturalSortingAction::class,
218215
SkipAction::class,
216+
217+
// objects specific stream actions
218+
ConsumerAction::class,
219+
FilterAction::class,
220+
MapAction::class,
219221
SortingAction::class,
222+
ToDoubleMapAction::class,
223+
ToIntMapAction::class,
224+
225+
// doubles specific stream actions
226+
DoubleConsumerAction::class,
227+
DoubleFilterAction::class,
228+
DoubleMapAction::class,
229+
DoubleToIntMapAction::class,
230+
DoubleToLongMapAction::class,
231+
DoubleToObjMapAction::class,
232+
233+
// ints specific stream actions
234+
IntConsumerAction::class,
235+
IntFilterAction::class,
236+
IntMapAction::class,
237+
IntToDoubleMapAction::class,
238+
IntToLongMapAction::class,
239+
IntToObjMapAction::class,
240+
241+
// longs specific stream actions
242+
LongConsumerAction::class,
243+
LongFilterAction::class,
244+
LongMapAction::class,
245+
LongToIntMapAction::class,
246+
LongToDoubleMapAction::class,
247+
LongToObjMapAction::class,
220248
)

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,31 +65,19 @@ Integer[] mapExample(List<Integer> list) {
6565
int[] mapToIntExample(List<Short> list) {
6666
UtMock.assume(list != null && !list.isEmpty());
6767

68-
if (list.contains(null)) {
69-
return list.stream().mapToInt(Short::intValue).toArray();
70-
} else {
71-
return list.stream().mapToInt(Short::intValue).toArray();
72-
}
68+
return list.stream().mapToInt(Short::intValue).toArray();
7369
}
7470

7571
long[] mapToLongExample(List<Short> list) {
7672
UtMock.assume(list != null && !list.isEmpty());
7773

78-
if (list.contains(null)) {
79-
return list.stream().mapToLong(Short::longValue).toArray();
80-
} else {
81-
return list.stream().mapToLong(Short::longValue).toArray();
82-
}
74+
return list.stream().mapToLong(Short::longValue).toArray();
8375
}
8476

8577
double[] mapToDoubleExample(List<Short> list) {
8678
UtMock.assume(list != null && !list.isEmpty());
8779

88-
if (list.contains(null)) {
89-
return list.stream().mapToDouble(Short::doubleValue).toArray();
90-
} else {
91-
return list.stream().mapToDouble(Short::doubleValue).toArray();
92-
}
80+
return list.stream().mapToDouble(Short::doubleValue).toArray();
9381
}
9482

9583
Object[] flatMapExample(List<Integer> list) {

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ boolean filterExample(List<Short> list) {
5555
final ToDoubleFunction<Short> shortToDoubleFunction = value -> value == null ? 0 : value.doubleValue();
5656
final DoubleStream doubles = list.stream().mapToDouble(shortToDoubleFunction);
5757

58-
if (list.contains(null)) {
59-
return doubles.map(mapper).toArray();
60-
} else {
61-
return doubles.map(mapper).toArray();
62-
}
58+
return doubles.map(mapper).toArray();
6359
}
6460

6561
Object[] mapToObjExample(List<Short> list) {
@@ -69,11 +65,7 @@ Object[] mapToObjExample(List<Short> list) {
6965
final ToDoubleFunction<Short> shortToDoubleFunction = value -> value == null ? 0 : value.doubleValue();
7066
final DoubleStream doubles = list.stream().mapToDouble(shortToDoubleFunction);
7167

72-
if (list.contains(null)) {
73-
return doubles.mapToObj(mapper).toArray();
74-
} else {
75-
return doubles.mapToObj(mapper).toArray();
76-
}
68+
return doubles.mapToObj(mapper).toArray();
7769
}
7870

7971
int[] mapToIntExample(List<Short> list) {
@@ -83,11 +75,7 @@ int[] mapToIntExample(List<Short> list) {
8375
final ToDoubleFunction<Short> shortToDoubleFunction = value -> value == null ? 0 : value.doubleValue();
8476
final DoubleStream doubles = list.stream().mapToDouble(shortToDoubleFunction);
8577

86-
if (list.contains(null)) {
87-
return doubles.mapToInt(mapper).toArray();
88-
} else {
89-
return doubles.mapToInt(mapper).toArray();
90-
}
78+
return doubles.mapToInt(mapper).toArray();
9179
}
9280

9381
long[] mapToLongExample(List<Short> list) {
@@ -97,11 +85,7 @@ long[] mapToLongExample(List<Short> list) {
9785
final ToDoubleFunction<Short> shortToDoubleFunction = value -> value == null ? 0 : value.doubleValue();
9886
final DoubleStream doubles = list.stream().mapToDouble(shortToDoubleFunction);
9987

100-
if (list.contains(null)) {
101-
return doubles.mapToLong(mapper).toArray();
102-
} else {
103-
return doubles.mapToLong(mapper).toArray();
104-
}
88+
return doubles.mapToLong(mapper).toArray();
10589
}
10690

10791
double[] flatMapExample(List<Short> list) {

0 commit comments

Comments
 (0)