### Question:
Downsample implements Transformer<T, T> { public static <T extends HasFix> Downsample<T> minTimeStep(long duration, TimeUnit unit) { return new Downsample<T>(unit.toMillis(duration), Functions.<T> alwaysFalse()); } Downsample(long minTimeBetweenFixesMs, Func1<T, Boolean> selector); static Downsample<T> minTimeStep(long duration, TimeUnit unit); static Downsample<T> minTimeStep(long duration, TimeUnit unit,
            Func1<T, Boolean> selector); @Override Observable<T> call(Observable<T> fixes); static Observable<Integer> downsample(final File input, final File output,
            Pattern pattern, final long duration, final TimeUnit unit);  }### Answer:
@Test public void testDownSampleOfEmptyReturnsEmpty() { int count = Observable.<Fix> empty().compose(minTimeStep(100, TimeUnit.MILLISECONDS)) .count().toBlocking().single(); assertEquals(0, count); }
@Test public void testDownSampleOfOneReturnsOne() { FixImpl f = createFix(0); HasFix fix = Observable.just(f).compose(minTimeStep(100, TimeUnit.MILLISECONDS)) .toBlocking().single(); assertEquals(f, fix); }
@Test public void testDownSampleOfTwoWithSmallGapReturnsFirst() { FixImpl f = createFix(0); FixImpl f2 = createFix(50); HasFix fix = Observable.just(f, f2).compose(minTimeStep(100, TimeUnit.MILLISECONDS)) .toBlocking().single(); assertEquals(f, fix); }
@Test public void testDownSampleOfTwoWithBigGapReturnsTwo() { FixImpl f = createFix(0); FixImpl f2 = createFix(150); List<HasFix> fixes = Observable.<HasFix> just(f, f2) .compose(minTimeStep(100, TimeUnit.MILLISECONDS)).toList().toBlocking().single(); assertEquals(Arrays.asList(f, f2), fixes); }
@Test public void testDownSampleOfThreeWithSmallGapThenBigGapReturnsOuterTwo() { FixImpl f = createFix(0); FixImpl f2 = createFix(50); FixImpl f3 = createFix(150); List<HasFix> fixes = Observable.<HasFix> just(f, f2, f3) .compose(minTimeStep(100, TimeUnit.MILLISECONDS)).toList().toBlocking().single(); assertEquals(Arrays.asList(f, f3), fixes); }
@Test public void testDownSampleOfNonZeroGapWithItemsWithSameTimeReturnsFirst() { FixImpl f = createFix(50); FixImpl f2 = createFix(50); FixImpl f3 = createFix(50); List<HasFix> fixes = Observable.<HasFix> just(f, f2, f3) .compose(minTimeStep(100, TimeUnit.MILLISECONDS)).toList().toBlocking().single(); assertEquals(Arrays.asList(f), fixes); }
@Test public void testDownSampleOf0ForItemsWithSameTimeReturnsAll() { FixImpl f = createFix(50); FixImpl f2 = createFix(50); FixImpl f3 = createFix(50); List<HasFix> fixes = Observable.<HasFix> just(f, f2, f3) .compose(minTimeStep(0, TimeUnit.MILLISECONDS)).toList().toBlocking().single(); assertEquals(Arrays.asList(f, f2, f3), fixes); }