KickJava   Java API By Example, From Geeks To Geeks.

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


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  *
26  * @author tim
27  */

28 public class IntListTest extends TestCase {
29
30     public IntListTest(String JavaDoc testName) {
31         super(testName);
32     }
33
34     /**
35      * Test of add method, of class org.netbeans.core.output2.IntList.
36      */

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     /**
55      * Test of get method, of class org.netbeans.core.output2.IntList.
56      */

57     public void testGet() {
58         System.out.println("testGet");
59         
60     }
61     
62     /**
63      * Test of findNearest method, of class org.netbeans.core.output2.IntList.
64      */

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     /**
110      * Test of indexOf method, of class org.netbeans.core.output2.IntList.
111      */

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     /**
134      * Test of size method, of class org.netbeans.core.output2.IntList.
135      */

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     /**
152      * Test of toString method, of class org.netbeans.core.output2.IntList.
153      */

154     public void testToString() {
155         System.out.println("testToString");
156         //Nothing to test here
157

158     }
159     
160     // TODO add test methods here, they have to start with 'test' name.
161
// for example:
162
// public void testHello() {}
163

164     
165 }
166
Popular Tags