예제 #1
0
  @Test
  public void test_find_children() {
    int[] child = new int[8];
    for (int i = 0; i < child.length; i++) {
      child[i] = new Random().nextInt(1000) + 1;
    }

    BTreeMap.BNode n1 =
        new BTreeMap.DirNode(
            new Integer[] {1, 2, 3, 4, 5, 6, 7, 8}, false, false, false, mkchild(child));
    assertEquals(8, BTreeKeySerializer.BASIC.findChildren(n1, 11));
    assertEquals(0, BTreeKeySerializer.BASIC.findChildren(n1, 1));
    assertEquals(0, BTreeKeySerializer.BASIC.findChildren(n1, 0));
    assertEquals(7, BTreeKeySerializer.BASIC.findChildren(n1, 8));

    child = new int[5];
    for (int i = 0; i < child.length; i++) {
      child[i] = new Random().nextInt(1000) + 1;
    }

    BTreeMap.BNode n2 =
        new BTreeMap.DirNode(
            new Integer[] {10, 20, 30, 40, 50}, false, false, false, mkchild(child));
    assertEquals(4, BTreeKeySerializer.BASIC.findChildren(n2, 49));
    assertEquals(4, BTreeKeySerializer.BASIC.findChildren(n2, 50));
    assertEquals(3, BTreeKeySerializer.BASIC.findChildren(n2, 40));
    assertEquals(3, BTreeKeySerializer.BASIC.findChildren(n2, 39));
  }
예제 #2
0
  @Test
  public void test_find_children_2() {
    for (boolean left : new boolean[] {true, false}) {
      for (boolean right : new boolean[] {true, false}) {
        List keys = new ArrayList();
        for (int i = 0; i < 100; i += 10) {
          keys.add(i);
        }

        int[] child = new int[keys.size() + (right ? 1 : 0) + (left ? 1 : 0)];
        Arrays.fill(child, 11);
        if (right) child[child.length - 1] = 0;

        BTreeMap.BNode n = new BTreeMap.DirNode(keys.toArray(), left, right, false, mkchild(child));

        for (int i = -10; i < 110; i++) {
          int pos = BTreeKeySerializer.BASIC.findChildren(n, i);
          int expected = (i + (left ? 19 : 9)) / 10;
          expected = Math.max(left ? 1 : 0, expected);
          expected = Math.min(left ? 11 : 10, expected);
          assertEquals("i:" + i + " - l:" + left + " - r:" + right, expected, pos);
        }
      }
    }
  }