@Test
  public void shouldCorrectlyDiscoverIfElementIsInSET() {
    cut.insert(new Point2D(.1, .1));

    assertFalse(cut.contains(new Point2D(.0, .0)));
    assertTrue(cut.contains(new Point2D(.1, .1)));
  }
 @Test
 public void shouldReturnTheCorrectSize() {
   assertEquals(0, cut.size());
   cut.insert(new Point2D(.0, .0));
   assertEquals(1, cut.size());
   cut.insert(new Point2D(.1, .1));
   assertEquals(2, cut.size());
 }
  @Test
  public void shouldGiveTheCorrectNearestPoint() {
    cut.insert(new Point2D(.0, .0));
    cut.insert(new Point2D(.0, .1));
    cut.insert(new Point2D(.0, .2));
    cut.insert(new Point2D(.0, .3));
    cut.insert(new Point2D(.0, .4));

    Point2D nearest = cut.nearest(new Point2D(.2, .2));

    assertEquals(new Point2D(.0, .2), nearest);
  }
  @Test
  public void shouldGiveTheCorrectRange() {
    cut.insert(new Point2D(.0, .0));
    cut.insert(new Point2D(.1, .1));
    cut.insert(new Point2D(.2, .2));
    cut.insert(new Point2D(.3, .3));
    cut.insert(new Point2D(.4, .4));
    cut.insert(new Point2D(.5, .5));

    List<Point2D> range = (List<Point2D>) cut.range(new RectHV(.1, .1, .4, .4));
    assertEquals(4, range.size());
    assertTrue(range.contains(new Point2D(.1, .1)));
    assertTrue(range.contains(new Point2D(.2, .2)));
    assertTrue(range.contains(new Point2D(.3, .3)));
    assertTrue(range.contains(new Point2D(.4, .4)));
  }
  public static KdTree createTreeDuplicates() {

    KdTree tree = new KdTree(2);

    tree.root = new KdTree.Node(new double[] {1, 2}, null);
    tree.root.split = 1;
    tree.root.left = new KdTree.Node(new double[] {1, 2}, null);
    tree.root.left.split = 0;
    tree.root.left.left = new KdTree.Node(new double[] {1, 2}, null);
    tree.root.left.left.split = -1;
    tree.root.left.right = null;
    tree.root.right = new KdTree.Node(new double[] {1, 2}, null);
    tree.root.right.split = -1;

    return tree;
  }
  /** See if max distance is being respected */
  @Test
  public void findClosest_maxDistance() {
    KdTree tree = new KdTree(2);
    tree.root = new KdTree.Node(new double[] {1, 2}, null);

    KdTreeSearchN alg = createAlg();
    alg.setTree(tree);
    alg.setMaxDistance(2);

    found.reset();
    alg.findNeighbor(new double[] {11, 8}, 1, found);
    assertEquals(0, found.size);
    found.reset();
    alg.findNeighbor(new double[] {1, 1.5}, 1, found);
    assertEquals(1, found.size);
    assertTrue(found.data[0].node == tree.root);
  }
 @Test(expected = NullPointerException.class)
 public void shouldThrowNullPointerExceptionWhenCheckingNearestToNull() {
   cut.nearest(null);
 }
 @Test(expected = NullPointerException.class)
 public void shouldThrowNullPointerExceptionWhenCheckingRangeWithinNull() {
   cut.range(null);
 }
 @Test(expected = NullPointerException.class)
 public void shouldThrowNullPointerExceptionWhenCheckingIfSETContainsNull() {
   cut.contains(null);
 }
 @Test(expected = NullPointerException.class)
 public void shouldThrowNullPointerExceptionWhenInsertingNull() {
   cut.insert(null);
 }
 @Test
 public void shouldReturnFalseIfSetIsNotEmpty() {
   cut.insert(new Point2D(.0, .0));
   assertFalse(cut.isEmpty());
 }
 @Test
 public void shouldReturnTrueIfSetIsEmpty() {
   assertTrue(cut.isEmpty());
 }