예제 #1
0
 public void testGet() {
   for (int s = 0; s < 2; s++) {
     IntTree it = initIntTree(s);
     for (int i = 0; i < ranNums.length; i++) {
       assertEquals(ranNums[i], ((Integer) it.get(ranNums[i])).intValue());
     }
   }
 }
예제 #2
0
 public void testSize() {
   for (int s = 0; s < 1; s++) { // Don't use random ordering as may
     // contain duplicates
     IntTree it0 = new intTree();
     assertEquals("Testing the empty tree", 0, it0.size());
     IntTree it = initIntTree(s);
     assertEquals(ranNums.length, it.size());
   }
 }
예제 #3
0
 public void testRemoveAll() {
   for (int s = 0; s < 2; s++) {
     IntTree it = initIntTree(s);
     it.removeAll();
     assertEquals("Test number of entries before deleting:", 0, it.size());
     for (int i = 0; i < ranNums.length; i++) {
       assertEquals("Test elements are deleted:", null, it.get(ranNums[i]));
     }
   }
 }
예제 #4
0
 public void testGetKeyIdx() {
   for (int s = 0; s < 1; s++) { // Don't use random ordering as may
     // contain duplicates
     IntTree it = initIntTree(s);
     int[] sortRanNums = ranNums.clone();
     Arrays.sort(sortRanNums);
     for (int i = 0; i < sortRanNums.length; i++) {
       assertEquals("Key of idx " + i + " was not as expected", sortRanNums[i], it.getKeyIdx(i));
     }
   }
 }
예제 #5
0
 public void testPopFirstKey() {
   for (int s = 0; s < 1; s++) { // Don't use random ordering as may
     // contain duplicates
     IntTree it = initIntTree(s);
     int[] sortRanNums = ranNums.clone();
     Arrays.sort(sortRanNums);
     for (int i = 0; i < sortRanNums.length; i++) {
       assertEquals(sortRanNums[i], it.popFirstKey());
       assertEquals(ranNums.length - i - 1, it.size());
     }
   }
 }
예제 #6
0
 public void testRemove() {
   for (int s = 0; s < 1; s++) { // Don't use random ordering as may
     // contain duplicates
     IntTree it = initIntTree(s);
     Random rr = new Random();
     int noRemov = 0;
     for (int i = 0; i < ranNums.length; i++) {
       if (rr.nextInt(100) < 20) {
         assertEquals(ranNums[i], ((Integer) it.get(ranNums[i])).intValue());
         it.remove(ranNums[i]);
         noRemov++;
         assertEquals(ranNums.length - noRemov, it.size());
         assertEquals(null, it.get(ranNums[i]));
       }
     }
   }
 }
예제 #7
0
 private IntTree initIntTree(int ordering) {
   IntTree it = new IntTree();
   ranNums = new int[10000];
   Random r = new Random();
   ranNums[0] = r.nextInt();
   it.put(ranNums[0], new Integer(ranNums[0]));
   for (int i = 1; i < ranNums.length; i++) {
     switch (ordering) {
       case 0:
         ranNums[i] = ranNums[i - 1] + r.nextInt(10000) + 1;
         break;
       case 1:
         ranNums[i] = ranNums[i - 1] - r.nextInt(10000) - 1;
         break;
       case 2:
         ranNums[i] = r.nextInt(10000);
         break;
     }
     it.put(ranNums[i], new Integer(ranNums[i]));
   }
   return it;
 }
예제 #8
0
  public void testClone() {
    for (int s = 0; s < 2; s++) {
      IntTree it = initIntTree(s);
      IntTree it2 = new IntTree();
      it2.clone(it);

      assertEquals(it.size(), it2.size());
      for (int i = 0; i < it.size(); i++) {
        assertEquals(
            ((Integer) it.get(ranNums[i])).intValue(), ((Integer) it2.get(ranNums[i])).intValue());
      }
      for (int i = 0; i < it.size(); i++) {
        assertEquals(it.getKeyIdx(i), it2.getKeyIdx(i));
      }
      for (int i = 0; i < it.size(); i++) {
        assertEquals(it.getValueIdx(i), it2.getValueIdx(i));
      }
    }
  }