Skip to content

Commit 42dca41

Browse files
author
Kamenev Yury
committed
Fixed failed test
1 parent 8907139 commit 42dca41

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class BaseStreamExampleTest : AbstractTestCaseGeneratorTest(
162162
BaseStreamExample::complexReduceExample,
163163
ignoreExecutionsNumber,
164164
{ c, r -> c.isEmpty() && c.sumOf { it.toDouble() } + 42.0 == r },
165-
{ c, r -> c.isNotEmpty() && c.sumOf { it.toDouble() } + 42.0 == r },
165+
{ c: List<Int?>, r -> c.isNotEmpty() && c.sumOf { it?.toDouble() ?: 0.0 } + 42.0 == r },
166166
coverage = DoNotCalculate
167167
)
168168
}

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

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java.util.stream.Stream;
1212

1313
@SuppressWarnings({"IfStatementWithIdenticalBranches", "RedundantOperationOnEmptyContainer"})
14-
public class BaseStreamExample {
14+
public class BaseStreamExample {
1515
Stream<Integer> returningStreamExample(List<Integer> list) {
1616
UtMock.assume(list != null);
1717

@@ -23,7 +23,7 @@ Stream<Integer> returningStreamExample(List<Integer> list) {
2323
}
2424

2525
@SuppressWarnings("Convert2MethodRef")
26-
boolean filterExample(List<Integer> list) {
26+
boolean filterExample(List<Integer> list) {
2727
UtMock.assume(list != null && !list.isEmpty());
2828

2929
int prevSize = list.size();
@@ -33,7 +33,7 @@ boolean filterExample(List<Integer> list) {
3333
return prevSize != newSize;
3434
}
3535

36-
Integer[] mapExample(List<Integer> list) {
36+
Integer[] mapExample(List<Integer> list) {
3737
UtMock.assume(list != null && !list.isEmpty());
3838

3939
return list.stream().map(value -> value * 2).toArray(Integer[]::new);
@@ -43,7 +43,7 @@ Integer[] mapExample(List<Integer> list) {
4343

4444
// TODO flatMap
4545

46-
boolean distinctExample(List<Integer> list) {
46+
boolean distinctExample(List<Integer> list) {
4747
UtMock.assume(list != null && !list.isEmpty());
4848

4949
int prevSize = list.size();
@@ -53,7 +53,7 @@ boolean distinctExample(List<Integer> list) {
5353
return prevSize != newSize;
5454
}
5555

56-
Integer[] sortedExample(List<Integer> list) {
56+
Integer[] sortedExample(List<Integer> list) {
5757
UtMock.assume(list != null && list.size() >= 2);
5858

5959
Integer first = list.get(0);
@@ -71,7 +71,7 @@ Integer[] sortedExample(List<Integer> list) {
7171
static int x = 0;
7272

7373
@SuppressWarnings("ResultOfMethodCallIgnored")
74-
int peekExample(List<Integer> list) {
74+
int peekExample(List<Integer> list) {
7575
UtMock.assume(list != null && !list.isEmpty());
7676

7777
int beforeStaticValue = x;
@@ -82,7 +82,7 @@ int peekExample(List<Integer> list) {
8282
}
8383

8484
@SuppressWarnings("IfStatementWithIdenticalBranches")
85-
Integer[] limitExample(List<Integer> list) {
85+
Integer[] limitExample(List<Integer> list) {
8686
UtMock.assume(list != null && !list.isEmpty());
8787

8888
if (list.size() <= 5) {
@@ -93,7 +93,7 @@ Integer[] limitExample(List<Integer> list) {
9393
}
9494

9595
@SuppressWarnings("IfStatementWithIdenticalBranches")
96-
Integer[] skipExample(List<Integer> list) {
96+
Integer[] skipExample(List<Integer> list) {
9797
UtMock.assume(list != null && !list.isEmpty());
9898

9999
if (list.size() > 5) {
@@ -104,7 +104,7 @@ Integer[] skipExample(List<Integer> list) {
104104
}
105105

106106
@SuppressWarnings("SimplifyStreamApiCallChains")
107-
int forEachExample(List<Integer> list) {
107+
int forEachExample(List<Integer> list) {
108108
UtMock.assume(list != null && !list.isEmpty());
109109

110110
int beforeStaticValue = x;
@@ -115,7 +115,7 @@ int forEachExample(List<Integer> list) {
115115
}
116116

117117
@SuppressWarnings("SimplifyStreamApiCallChains")
118-
Object[] toArrayExample(List<Integer> list) {
118+
Object[] toArrayExample(List<Integer> list) {
119119
UtMock.assume(list != null);
120120

121121
int size = list.size();
@@ -126,13 +126,13 @@ Object[] toArrayExample(List<Integer> list) {
126126
}
127127
}
128128

129-
Integer reduceExample(List<Integer> list) {
129+
Integer reduceExample(List<Integer> list) {
130130
UtMock.assume(list != null);
131131

132132
return list.stream().reduce(42, this::nullableSum);
133133
}
134134

135-
Optional<Integer> optionalReduceExample(List<Integer> list) {
135+
Optional<Integer> optionalReduceExample(List<Integer> list) {
136136
UtMock.assume(list != null);
137137

138138
int size = list.size();
@@ -148,27 +148,35 @@ Optional<Integer> optionalReduceExample(List<Integer> list) {
148148
return list.stream().reduce(this::nullableSum);
149149
}
150150

151-
Double complexReduceExample(List<Integer> list) {
151+
Double complexReduceExample(List<Integer> list) {
152152
UtMock.assume(list != null);
153153

154-
return list.stream().reduce(42.0, (Double a, Integer b) -> a + b.doubleValue(), Double::sum);
154+
if (list.isEmpty()) {
155+
return list.stream().reduce(42.0, (Double a, Integer b) -> a + b.doubleValue(), Double::sum);
156+
}
157+
158+
return list.stream().reduce(
159+
42.0,
160+
(Double a, Integer b) -> a + (b != null ? b.doubleValue() : 0.0),
161+
Double::sum
162+
);
155163
}
156164

157-
Integer collectExample(List<Integer> list) {
165+
Integer collectExample(List<Integer> list) {
158166
UtMock.assume(list != null);
159167

160168
return list.stream().collect(IntWrapper::new, IntWrapper::plus, IntWrapper::plus).value;
161169
}
162170

163171
@SuppressWarnings("SimplifyStreamApiCallChains")
164-
Set<Integer> collectorExample(List<Integer> list) {
172+
Set<Integer> collectorExample(List<Integer> list) {
165173
UtMock.assume(list != null);
166174

167175
return list.stream().collect(Collectors.toSet());
168176
}
169177

170178
@SuppressWarnings("RedundantOperationOnEmptyContainer")
171-
Optional<Integer> minExample(List<Integer> list) {
179+
Optional<Integer> minExample(List<Integer> list) {
172180
UtMock.assume(list != null);
173181

174182
int size = list.size();
@@ -185,7 +193,7 @@ Optional<Integer> minExample(List<Integer> list) {
185193
}
186194

187195
@SuppressWarnings("RedundantOperationOnEmptyContainer")
188-
Optional<Integer> maxExample(List<Integer> list) {
196+
Optional<Integer> maxExample(List<Integer> list) {
189197
UtMock.assume(list != null);
190198

191199
int size = list.size();
@@ -202,7 +210,7 @@ Optional<Integer> maxExample(List<Integer> list) {
202210
}
203211

204212
@SuppressWarnings({"ReplaceInefficientStreamCount", "ConstantConditions"})
205-
long countExample(List<Integer> list) {
213+
long countExample(List<Integer> list) {
206214
UtMock.assume(list != null);
207215

208216
if (list.isEmpty()) {
@@ -213,7 +221,7 @@ long countExample(List<Integer> list) {
213221
}
214222

215223
@SuppressWarnings({"Convert2MethodRef", "ConstantConditions", "RedundantOperationOnEmptyContainer"})
216-
boolean anyMatchExample(List<Integer> list) {
224+
boolean anyMatchExample(List<Integer> list) {
217225
UtMock.assume(list != null);
218226

219227
if (list.isEmpty()) {
@@ -241,7 +249,7 @@ boolean anyMatchExample(List<Integer> list) {
241249
}
242250

243251
@SuppressWarnings({"Convert2MethodRef", "ConstantConditions", "RedundantOperationOnEmptyContainer"})
244-
boolean allMatchExample(List<Integer> list) {
252+
boolean allMatchExample(List<Integer> list) {
245253
UtMock.assume(list != null);
246254

247255
if (list.isEmpty()) {
@@ -269,7 +277,7 @@ boolean allMatchExample(List<Integer> list) {
269277
}
270278

271279
@SuppressWarnings({"Convert2MethodRef", "ConstantConditions", "RedundantOperationOnEmptyContainer"})
272-
boolean noneMatchExample(List<Integer> list) {
280+
boolean noneMatchExample(List<Integer> list) {
273281
UtMock.assume(list != null);
274282

275283
if (list.isEmpty()) {
@@ -297,7 +305,7 @@ boolean noneMatchExample(List<Integer> list) {
297305
}
298306

299307
@SuppressWarnings("RedundantOperationOnEmptyContainer")
300-
Optional<Integer> findFirstExample(List<Integer> list) {
308+
Optional<Integer> findFirstExample(List<Integer> list) {
301309
UtMock.assume(list != null);
302310

303311
if (list.isEmpty()) {
@@ -311,7 +319,7 @@ Optional<Integer> findFirstExample(List<Integer> list) {
311319
}
312320
}
313321

314-
Integer iteratorSumExample(List<Integer> list) {
322+
Integer iteratorSumExample(List<Integer> list) {
315323
UtMock.assume(list != null && !list.isEmpty());
316324

317325
int sum = 0;

0 commit comments

Comments
 (0)