1 19 20 package org.netbeans.core.output2; 21 22 import junit.framework.TestCase; 23 24 28 public class IntListTest extends TestCase { 29 30 public IntListTest(String testName) { 31 super(testName); 32 } 33 34 37 public void testAdd() { 38 System.out.println("testAdd"); 39 40 IntList il = new IntList (100); 41 il.add (0); 42 il.add (1); 43 il.add (2); 44 il.add (23); 45 il.add (Integer.MAX_VALUE); 46 47 assertTrue (il.get(0) == 0); 48 assertTrue (il.get(1) == 1); 49 assertTrue (il.get(2) == 2); 50 assertTrue (il.get(3) == 23); 51 assertTrue (il.get(4) == Integer.MAX_VALUE); 52 } 53 54 57 public void testGet() { 58 System.out.println("testGet"); 59 60 } 61 62 65 public void testFindNearest() { 66 System.out.println("testFindNearest"); 67 68 IntList il = new IntList (1000); 69 70 for (int i=0; i < 100; i++) { 71 il.add (i * 10); 72 } 73 74 int near475 = il.findNearest (475); 75 assertTrue ("Nearest entry to 475 should be 470, not " + near475, 76 near475 == 47); 77 78 int near470 = il.findNearest (470); 79 assertTrue ("List contains an entry 470 at index 47, but returned " 80 + near470 + " as the index with the value closest to 470", 81 near470 == 47); 82 83 int near505 = il.findNearest (505); 84 assertTrue ("Nearest entry to 505 should be 500, not " + near505, 85 near505 == 50); 86 87 int near515 = il.findNearest (515); 88 assertTrue ("Nearest entry to 515 should be 510, not " + near515, 89 near515 == 51); 90 91 int near5 = il.findNearest (5); 92 assertTrue ("Nearest entry to 5 should be 0, not " + near5, 93 near5 == 0); 94 95 int near995 = il.findNearest (995); 96 assertTrue ("Nearest entry to 995 should be 990, not " + near995, 97 near995 == 99); 98 99 int near21000 = il.findNearest (21000); 100 assertTrue ("Nearest entry to 21000 should be 990, not " + near21000, 101 near21000 == 99); 102 103 int nearNeg475 = il.findNearest (-475); 104 assertTrue ("Nearest entry to -475 should be 0 not " + nearNeg475, 105 nearNeg475 == 0); 106 107 } 108 109 112 public void testIndexOf() { 113 System.out.println("testIndexOf"); 114 115 IntList il = new IntList (1000); 116 117 int[] vals = new int[] { 118 1, 4, 23, 31, 47, 2350, 5727, 32323 119 }; 120 121 for (int i=0; i < vals.length; i++) { 122 il.add (vals[i]); 123 } 124 125 for (int i=0; i < vals.length; i++) { 126 assertTrue (vals[i] + " was added at index " + i + " but found it" + 127 "(or didn't find it) at index " + il.indexOf(vals[i]), 128 il.indexOf(vals[i]) == i); 129 } 130 131 } 132 133 136 public void testSize() { 137 System.out.println("testSize"); 138 IntList il = new IntList (1000); 139 140 int[] vals = new int[] { 141 1, 4, 23, 31, 47, 2350, 5727, 32323 142 }; 143 144 for (int i=0; i < vals.length; i++) { 145 il.add (vals[i]); 146 } 147 148 assertTrue (il.size() == vals.length); 149 } 150 151 154 public void testToString() { 155 System.out.println("testToString"); 156 158 } 159 160 164 165 } 166 | Popular Tags |