@Test
  public void testUnderflowRemoveEnd() {
    final LeafNode leaf = leaf(1, 2, 3, 4);

    final RemoveResult result = leaf._removed(4, 1);

    final LeafNode newLeaf = (LeafNode) result.newNode;
    assertArrayEquals(new Integer[] {1, 2, 3}, newLeaf.keys);
    assertArrayEquals(new Integer[] {100, 200, 300}, newLeaf.values);

    assertEquals(true, result.underflowed);
    assertEquals(1, result.leftSeparator);
  }
  @Test
  public void testSimpleRemoveNotFound() {
    final LeafNode leaf = leaf(1, 2, 4, 5);

    final RemoveResult result = leaf._removed(3, 1);

    final LeafNode newLeaf = (LeafNode) result.newNode;
    assertArrayEquals(new Integer[] {1, 2, 4, 5}, newLeaf.keys);
    assertArrayEquals(new Integer[] {100, 200, 400, 500}, newLeaf.values);

    assertEquals(false, result.underflowed);
    assertEquals(1, result.leftSeparator);
  }
예제 #3
0
  /**
   * Testing LeafNode methods. Because LeafNode inherits from QuadTreeNode, bounds on the node will
   * be tested with QuadTreeNode because none of those methods are overridden in LeafNode
   *
   * @author Sam Whitlock (cs61b-eo)
   * @param void
   * @return void
   */
  @Test
  leafNodeTest1() {
    LeafNode<QuadPoint> node = new LeafNode<QuadPoint>(null, null, 0, 0, 10, 10);
    QuadPoint pt1 = new QuadPoint(1, 1);
    QuadPoint pt2 = new QuadPoint(9, 9);
    Leaf<QuadPoint> lf1 = new Leaf<QuadPoint>(pt1, null, null);
    Leaf<QuadPoint> lf2 = new Leaf<QuadPoint>(pt2, null, null);

    node.insert(lf1);
    node.insert(lf2);
    assertTrue(node.kids.contains(lf1) && node.kids.contains(lf2));

    ArrayList<Leaf<QuadPoint>> boundedKids = node.boundedChildren(0, 0, 10, 10);
    assertTrue(boundedKids.contains(lf1) && boundedKids.contains(lf2));

    boundedKids.clear();

    boundedKids = node.boundedChildren(0, 0, 3, 3);
    assertTrue(boundedKids.contains(lf1) && !boundedKids.contains(lf2));

    boundedKids.clear();
    boundedKids = node.boundedChildren(7, 7, 10, 10);
    assertTrue(boundedKids.contains(lf2) && !boundedKids.contains(lf1));

    boundedKids.clear();
    boundedKids = node.boundedChildren(3, 3, 7, 7);
    assertTrue(boundedKids.isEmpty());

    node.remove(lf1);
    node.remove(lf2);
    assertTrue(node.kids.isEmpty());
  }