Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

additions to tests #364

Merged
merged 1 commit into from
Sep 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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