Skip to content

Commit

Permalink
Merge pull request ReactiveX#364 from benjchristensen/tests
Browse files Browse the repository at this point in the history
additions to tests
  • Loading branch information
benjchristensen committed Sep 10, 2013
2 parents 9e7c9cb + 4db7143 commit a0f4b30
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,31 @@ def class ObservableTests {
verify(a, times(1)).received(true);
}


@Test
public void testZip() {
Observable o1 = Observable.from(1, 2, 3);
Observable o2 = Observable.from(4, 5, 6);
Observable o3 = Observable.from(7, 8, 9);

List values = Observable.zip(o1, o2, o3, {a, b, c -> [a, b, c] }).toList().toBlockingObservable().single();
assertEquals([1, 4, 7], values.get(0));
assertEquals([2, 5, 8], values.get(1));
assertEquals([3, 6, 9], values.get(2));
}

@Test
public void testZipWithIterable() {
Observable o1 = Observable.from(1, 2, 3);
Observable o2 = Observable.from(4, 5, 6);
Observable o3 = Observable.from(7, 8, 9);

List values = Observable.zip([o1, o2, o3], {a, b, c -> [a, b, c] }).toList().toBlockingObservable().single();
assertEquals([1, 4, 7], values.get(0));
assertEquals([2, 5, 8], values.get(1));
assertEquals([3, 6, 9], values.get(2));
}

@Test
public void testGroupBy() {
int count=0;
Expand Down
20 changes: 19 additions & 1 deletion rxjava-core/src/test/java/rx/ReduceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ public Integer call(Integer t1, Integer t2) {

@Test
public void reduceWithObjects() {
Observable<Movie> horrorMovies = Observable.<Movie> from(new HorrorMovie());

Func2<Movie, Movie, Movie> chooseSecondMovie =
new Func2<Movie, Movie, Movie>() {
public Movie call(Movie t1, Movie t2) {
return t2;
}
};

Observable<Movie> reduceResult = Observable.create(OperationScan.scan(horrorMovies, chooseSecondMovie)).takeLast(1);

Observable<Movie> reduceResult2 = horrorMovies.reduce(chooseSecondMovie);
}

@Test
public void reduceWithCovariantObjects() {
Observable<HorrorMovie> horrorMovies = Observable.from(new HorrorMovie());

Func2<Movie, Movie, Movie> chooseSecondMovie =
Expand Down Expand Up @@ -61,8 +77,10 @@ public Movie call(Movie t1, Movie t2) {
}
};

Observable<Movie> reduceResult = Observable.create(OperationScan.scan(obs, chooseSecondMovie)).takeLast(1);

//TODO this isn't compiling
// Observable<Movie> reduceResult = obs.reduce((Func2<? super Movie, ? super Movie, ? extends Movie>) chooseSecondMovie);
// Observable<Movie> reduceResult2 = obs.reduce(chooseSecondMovie);
// do something with reduceResult...
}

Expand Down

0 comments on commit a0f4b30

Please sign in to comment.