1 19 20 package org.netbeans.core.output2; 21 22 import junit.framework.TestCase; 23 24 29 public class SparseIntListTest extends TestCase { 30 31 public SparseIntListTest(String testName) { 32 super(testName); 33 } 34 35 private SparseIntList l = null; 36 protected void setUp() throws Exception { 37 l = new SparseIntList(20); 38 } 39 40 public void testGetLessThanZeroReturnsZero() { 41 System.out.println("testGetLessThanZeroReturnsZero"); 42 assertTrue (l.get(Integer.MIN_VALUE) == 0); 43 } 44 45 public void testGetFromEmptyListReturnsRequestedIndex() { 46 System.out.println("testGetFromEmptyListReturnsRequestedIndex"); 47 assertTrue (l.get(20) == 20); 48 assertTrue (l.get(Integer.MAX_VALUE) == Integer.MAX_VALUE); 49 assertTrue (l.get(1) == 1); 50 assertTrue (l.get(0) == 0); 51 } 52 53 public void testGetBelowFirstEntryReturnsIndex() { 54 System.out.println("testGetBelowFirstEntryReturnsIndex"); 55 l.add (20, 11); 56 for (int i=0; i < 11; i++) { 57 assertTrue (l.get(i) == i); 58 } 59 } 60 61 public void testAdd() { 62 System.out.println("testAdd"); 63 l.add (20, 11); 64 int val = l.get(11); 65 assertTrue ("After add(20, 11), value at 11 should still be 11, not " + val, val == 11); 66 val = l.get(12); 67 assertTrue ("After add(20, 11), value at 12 should be 21, not " + val, val == 21); 68 69 l.add (30, 12); 70 val = l.get(12); 71 assertTrue ("After add(30, 12), value at 12 should still be 21, not " + val, val == 21); 72 val = l.get(13); 73 assertTrue ("After add(30, 12), value at 13 should be 31, not " + val, val == 31); 74 75 l.add (80, 30); 76 val = l.get(12); 77 assertTrue ("After add(80, 30), value at 12 should still be 21, not " + val + " adding an entry above should not change it", val == 21); 78 val = l.get(13); 79 assertTrue ("After add(80, 30), value at 13 should be 31, not " + val + " adding an entry above should not change it", val == 31); 80 val = l.get(31); 81 assertTrue ("After add(80, 30), value at 31 should be 81, not " + val, val == 81); 82 83 for (int i=0; i < 10; i++) { 84 val = l.get(i); 85 assertTrue ("In a populated map, get() on an index below the first added entry should return the index, but get(" + i + ") returns " + val, val == i); 86 } 87 88 } 89 90 public void testBadValuesThrowExceptions() { 91 System.out.println("testBadValuesThrowExceptions"); 92 l.add (20, 11); 93 Exception e = null; 94 try { 95 l.add (19, 13); 96 } catch (Exception ex) { 97 e = ex; 98 } 99 assertNotNull(e); 100 101 try { 102 l.add (21, 10); 103 } catch (Exception ex2) { 104 e = ex2; 105 } 106 assertNotNull(e); 107 108 } 109 110 public void testGetAboveFirstEntryReturnsEntryPlusIndexDiff() { 111 System.out.println("testGetAboveFirstEntryReturnsEntryPlusIndexDiff"); 112 l.add (20, 11); 113 int x = 21; 114 for (int i=12; i < 40; i++){ 115 assertTrue ("Entry at " + i + " should be " + x + ", not " + l.get(i), l.get(i) == x); 116 x++; 117 } 118 } 119 120 121 122 } 123 | Popular Tags |