示例#1
0
  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);
  }
示例#2
0
  @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);
  }
示例#3
0
  @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());
    }
  }
示例#4
0
 protected void eq(String whole, Range range, String expected) {
   eq(range.get(whole), expected);
 }