| 1 |
/* |
| 2 |
* Copyright (c) 2016-present, RxJava Contributors. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See |
| 11 |
* the License for the specific language governing permissions and limitations under the License. |
| 12 |
*/ |
| 13 |
|
| 14 |
package io.reactivex.rxjava3.internal.operators.observable; |
| 15 |
|
| 16 |
import static org.junit.Assert.*; |
| 17 |
|
| 18 |
import java.util.concurrent.TimeUnit; |
| 19 |
|
| 20 |
import org.junit.Test; |
| 21 |
|
| 22 |
import io.reactivex.rxjava3.core.*; |
| 23 |
import io.reactivex.rxjava3.schedulers.Schedulers; |
| 24 |
import io.reactivex.rxjava3.testsupport.TestHelper; |
| 25 |
|
| 26 |
public class ObservableIntervalRangeTest extends RxJavaTest { |
| 27 |
|
| 28 |
@Test |
| 29 |
public void simple() throws Exception { |
| 30 |
Observable.intervalRange(5, 5, 50, 50, TimeUnit.MILLISECONDS) |
| 31 |
.test() |
| 32 |
.awaitDone(5, TimeUnit.SECONDS) |
| 33 |
.assertResult(5L, 6L, 7L, 8L, 9L); |
| 34 |
} |
| 35 |
|
| 36 |
@Test |
| 37 |
public void customScheduler() { |
| 38 |
Observable.intervalRange(1, 5, 1, 1, TimeUnit.MILLISECONDS, Schedulers.single()) |
| 39 |
.test() |
| 40 |
.awaitDone(5, TimeUnit.SECONDS) |
| 41 |
.assertResult(1L, 2L, 3L, 4L, 5L); |
| 42 |
} |
| 43 |
|
| 44 |
@Test |
| 45 |
public void countZero() { |
| 46 |
Observable.intervalRange(1, 0, 1, 1, TimeUnit.MILLISECONDS) |
| 47 |
.test() |
| 48 |
.awaitDone(5, TimeUnit.SECONDS) |
| 49 |
.assertResult(); |
| 50 |
} |
| 51 |
|
| 52 |
@Test |
| 53 |
public void countNegative() { |
| 54 |
try { |
| 55 |
Observable.intervalRange(1, -1, 1, 1, TimeUnit.MILLISECONDS); |
| 56 |
fail("Should have thrown!"); |
| 57 |
} catch (IllegalArgumentException ex) { |
| 58 |
assertEquals("count >= 0 required but it was -1", ex.getMessage()); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
@Test |
| 63 |
public void longOverflow() { |
| 64 |
Observable.intervalRange(Long.MAX_VALUE - 1, 2, 1, 1, TimeUnit.MILLISECONDS); |
| 65 |
|
| 66 |
Observable.intervalRange(Long.MIN_VALUE, Long.MAX_VALUE, 1, 1, TimeUnit.MILLISECONDS); |
| 67 |
|
| 68 |
try { |
| 69 |
Observable.intervalRange(Long.MAX_VALUE - 1, 3, 1, 1, TimeUnit.MILLISECONDS); |
| 70 |
fail("Should have thrown!"); |
| 71 |
} catch (IllegalArgumentException ex) { |
| 72 |
assertEquals("Overflow! start + count is bigger than Long.MAX_VALUE", ex.getMessage()); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
@Test |
| 77 |
public void dispose() { |
| 78 |
TestHelper.checkDisposed(Observable.intervalRange(1, 2, 1, 1, TimeUnit.MILLISECONDS)); |
| 79 |
} |
| 80 |
|
| 81 |
@Test |
| 82 |
public void cancel() { |
| 83 |
Observable.intervalRange(0, 20, 1, 1, TimeUnit.MILLISECONDS, Schedulers.trampoline()) |
| 84 |
.take(10) |
| 85 |
.test() |
| 86 |
.assertResult(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L); |
| 87 |
} |
| 88 |
|
| 89 |
@Test |
| 90 |
public void takeSameAsRange() { |
| 91 |
Observable.intervalRange(0, 2, 1, 1, TimeUnit.MILLISECONDS, Schedulers.trampoline()) |
| 92 |
.take(2) |
| 93 |
.test() |
| 94 |
.assertResult(0L, 1L); |
| 95 |
} |
| 96 |
} |