Skip to content

Commit d2d4252

Browse files
Additional unit test for reduce
1 parent f1a2114 commit d2d4252

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

rxjava-core/src/test/java/rx/ObservableTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,26 @@ public void call(Integer t1) {
236236
fail("Expected an exception to be thrown");
237237
}
238238

239+
/**
240+
* A reduce on an empty Observable and a seed should just pass the seed through.
241+
*
242+
* This is confirmed at https://github.com/Netflix/RxJava/issues/423#issuecomment-27642456
243+
*/
244+
@Test
245+
public void testReduceWithEmptyObservableAndSeed() {
246+
Observable<Integer> observable = Observable.range(1, 0);
247+
int value = observable.reduce(1, new Func2<Integer, Integer, Integer>() {
248+
249+
@Override
250+
public Integer call(Integer t1, Integer t2) {
251+
return t1 + t2;
252+
}
253+
254+
}).toBlockingObservable().last();
255+
256+
assertEquals(1, value);
257+
}
258+
239259
@Test
240260
public void testReduceWithInitialValue() {
241261
Observable<Integer> observable = Observable.from(1, 2, 3, 4);

0 commit comments

Comments
 (0)