package com.github.davidmoten.rx;

import junit.framework.TestCase;
import junit.framework.TestSuite;
import rx.Observable;
import rx.functions.Func1;

import com.github.davidmoten.rx.testing.TestingHelper;

public class TestingHelperCountTest extends TestCase {

    public static TestSuite suite() {

        return TestingHelper.function(COUNT)
                // test empty
                .name("testCountOfEmptyReturnsEmpty").fromEmpty().expect(0)
                // test error
                .name("testCountErrorReturnsError").fromError().expectError()
                // test error after some emission
                .name("testCountErrorAfterTwoEmissionsReturnsError").fromErrorAfter(5, 6)
                .expectError()
                // test non-empty count
                .name("testCountOfTwoReturnsTwo").from(5, 6).expect(2)
                // test single input
                .name("testCountOfOneReturnsOne").from(5).expect(1)
                // unsub before completions
                .name("testCountofTwoReturnsOneWhenUnsubscribedAfterOne").from(5, 6, 7).expect(3)
                // get test suites
                .testSuite(TestingHelperCountTest.class);
    }

    public void testDummy() {
        // just here to fool eclipse
    }

    private static final Func1<Observable<Integer>, Observable<Integer>> COUNT = new Func1<Observable<Integer>, Observable<Integer>>() {
        @Override
        public Observable<Integer> call(Observable<Integer> o) {
            return o.count();
        }
    };

}

@@ -324,16 +324,33 @@
 ngHelper
+%0A                
 .functio
@@ -453,16 +453,33 @@
 mEmpty()
+%0A                
 .expect(
@@ -574,16 +574,33 @@
 mError()
+%0A                
 .expectE
@@ -1135,16 +1135,179 @@
 pect(3)%0A
+                // count many%0A                .name(%22testCountOfManyDoesNotGiveStackOverflow%22).from(Observable.range(1, 1000000))%0A                .expect(1000000)%0A
         

add count test