source: trunk/java-utils-test/src/test/java/de/ugoe/cs/util/ArrayToolsTest.java @ 479

Last change on this file since 479 was 479, checked in by sherbold, 12 years ago
  • converted java-utils-test to Maven project
  • Property svn:mime-type set to text/plain
File size: 4.1 KB
Line 
1package de.ugoe.cs.util;
2
3import org.junit.*;
4import static org.junit.Assert.*;
5
6/**
7 * The class <code>ArrayToolsTest</code> contains tests for the class
8 * <code>{@link ArrayTools}</code>.
9 *
10 * @author Steffen Herbold
11 * @version 1.0
12 */
13public class ArrayToolsTest {
14
15        Integer array[];
16
17        @Test
18        public void testFindIndex_1() throws Exception {
19                Integer target = 3;
20                int expected = 3;
21
22                int result = ArrayTools.findIndex(array, target);
23
24                assertEquals(expected, result);
25        }
26
27        @Test
28        public void testFindIndex_2() throws Exception {
29                Integer target = 4;
30                int expected = 4;
31
32                int result = ArrayTools.findIndex(array, target);
33
34                assertEquals(expected, result);
35        }
36
37        @Test
38        public void testFindIndex_3() throws Exception {
39                Integer target = 7;
40
41                int result = ArrayTools.findIndex(array, target);
42                int expected = -1;
43               
44                assertEquals(expected, result);
45        }
46
47        @Test
48        public void testFindIndex_4() throws Exception {
49                Integer target = null;
50                int result = ArrayTools.findIndex(array, target);
51                int expected = 7;
52                assertEquals(expected, result);
53        }
54
55        @Test
56        public void testFindIndex_5() throws Exception {
57                Object[] array = new Object[0];
58                Object other = new Object();
59
60                int result = ArrayTools.findIndex(array, other);
61
62                assertEquals(-1, result);
63        }
64       
65        @Test
66        public void testFindMax_1() throws Exception {
67                int expected = 8;
68               
69                int result = ArrayTools.findMax(array);
70               
71                assertEquals(expected, result);
72        }
73       
74        @Test
75        public void testFindMax_2() throws Exception {
76                Integer[] arrayUnsorted = new Integer[]{2,3,6,1,8,9,1,1,3,15,4,0,-1};
77                int expected = 9;
78               
79                int result = ArrayTools.findMax(arrayUnsorted);
80               
81                assertEquals(expected, result);
82        }
83       
84        @Test
85        public void testFindMax_3() throws Exception {
86                Integer[] arrayUnsorted = new Integer[]{2,3,6,1,8,9,1,1,3,15,4,15,-1};
87                int expected = 9;
88               
89                int result = ArrayTools.findMax(arrayUnsorted);
90               
91                assertEquals(expected, result);
92        }
93       
94        @Test
95        public void testFindMax_4() throws Exception {
96                Integer[] arrayNoLenght = new Integer[]{};
97                int expected = -1;
98               
99                int result = ArrayTools.findMax(arrayNoLenght);
100               
101                assertEquals(expected, result);
102        }
103       
104        @Test
105        public void testFindMax_5() throws Exception {
106                Integer[] arrayNulls = new Integer[]{null, null};
107                int expected = -1;
108               
109                int result = ArrayTools.findMax(arrayNulls);
110               
111                assertEquals(expected, result);
112        }
113       
114        @Test
115        public void testFindMax_6() throws Exception {
116                int expected = -1;
117               
118                int result = ArrayTools.findMax(null);
119               
120                assertEquals(expected, result);
121        }
122       
123        @Test
124        public void testFindMin_1() throws Exception {
125                int expected = 0;
126               
127                int result = ArrayTools.findMin(array);
128               
129                assertEquals(expected, result);
130        }
131       
132        @Test
133        public void testFindMin_2() throws Exception {
134                Integer[] arrayUnsorted = new Integer[]{2,3,6,1,8,9,1,1,-3,15,4,0,-1};
135                int expected = 8;
136               
137                int result = ArrayTools.findMin(arrayUnsorted);
138               
139                assertEquals(expected, result);
140        }
141       
142        @Test
143        public void testFindMin_3() throws Exception {
144                Integer[] arrayUnsorted = new Integer[]{2,3,6,1,8,9,1,-1,3,15,4,15,-1};
145                int expected = 7;
146               
147                int result = ArrayTools.findMin(arrayUnsorted);
148               
149                assertEquals(expected, result);
150        }
151       
152        @Test
153        public void testFindMin_4() throws Exception {
154                Integer[] arrayNoLenght = new Integer[]{};
155                int expected = -1;
156               
157                int result = ArrayTools.findMin(arrayNoLenght);
158               
159                assertEquals(expected, result);
160        }
161       
162        @Test
163        public void testFindMin_5() throws Exception {
164                Integer[] arrayNulls = new Integer[]{null, null};
165                int expected = -1;
166               
167                int result = ArrayTools.findMin(arrayNulls);
168               
169                assertEquals(expected, result);
170        }
171       
172        @Test
173        public void testFindMin_6() throws Exception {
174                int expected = -1;
175               
176                int result = ArrayTools.findMin(null);
177               
178                assertEquals(expected, result);
179        }
180
181        @Before
182        public void setUp() throws Exception {
183                array = new Integer[] { 0, 1, 2, 3, 4, 4, 5, null, 6 };
184        }
185
186        public static void main(String[] args) {
187                new org.junit.runner.JUnitCore().run(ArrayToolsTest.class);
188        }
189}
Note: See TracBrowser for help on using the repository browser.