KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > output2 > SparseIntListTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core.output2;
21
22 import junit.framework.TestCase;
23
24 /**
25  * Test for org.netbeans.core.output2.SparseIntList.
26  *
27  * @author Tim Boudreau
28  */

29 public class SparseIntListTest extends TestCase {
30
31     public SparseIntListTest(String JavaDoc testName) {
32         super(testName);
33     }
34
35     private SparseIntList l = null;
36     protected void setUp() throws Exception JavaDoc {
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 JavaDoc e = null;
94         try {
95             l.add (19, 13);
96         } catch (Exception JavaDoc ex) {
97             e = ex;
98         }
99         assertNotNull(e);
100         
101         try {
102             l.add (21, 10);
103         } catch (Exception JavaDoc 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