private void check(Range rng, int a, int b) { rng.set(a, b); eq(rng, a, b); eq(rng.limit(), rng.start + rng.length); long backup = rng.backup(); rng.set(rnd(), rnd()); rng.restore(backup); eq(rng, a, b); }
@Test public void shouldBackupAndRestore() { Range range = new Range(10, 3); eq(range, 10, 3); long backup = range.backup(); range.set(7, 17); eq(range, 7, 17); range.restore(backup); eq(range, 10, 3); }
@Test public void statisticalTest() { Range rng = new Range(); isTrue(rng.isEmpty()); int[] borders = {Integer.MIN_VALUE, -1111, -1, 0, 1, 1111, Integer.MAX_VALUE}; for (int i = 0; i < borders.length; i++) { for (int j = 0; j < borders.length; j++) { check(rng, borders[i], borders[j]); } } for (int i = 0; i < 1000000; i++) { check(rng, rnd(), rnd()); } }
protected void eq(String whole, Range range, String expected) { eq(range.get(whole), expected); }