1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
2 | //
|
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
4 | // you may not use this file except in compliance with the License.
|
---|
5 | // You may obtain a copy of the License at
|
---|
6 | //
|
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
8 | //
|
---|
9 | // Unless required by applicable law or agreed to in writing, software
|
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
12 | // See the License for the specific language governing permissions and
|
---|
13 | // limitations under the License.
|
---|
14 |
|
---|
15 | package de.ugoe.cs.util;
|
---|
16 |
|
---|
17 | import org.junit.*;
|
---|
18 | import static org.junit.Assert.*;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * The class <code>ArrayToolsTest</code> contains tests for the class
|
---|
22 | * <code>{@link ArrayTools}</code>.
|
---|
23 | *
|
---|
24 | * @author Steffen Herbold
|
---|
25 | * @version 1.0
|
---|
26 | */
|
---|
27 | public class ArrayToolsTest {
|
---|
28 |
|
---|
29 | Integer array[];
|
---|
30 |
|
---|
31 | @Test
|
---|
32 | public void testFindIndex_1() throws Exception {
|
---|
33 | Integer target = 3;
|
---|
34 | int expected = 3;
|
---|
35 |
|
---|
36 | int result = ArrayTools.findIndex(array, target);
|
---|
37 |
|
---|
38 | assertEquals(expected, result);
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Test
|
---|
42 | public void testFindIndex_2() throws Exception {
|
---|
43 | Integer target = 4;
|
---|
44 | int expected = 4;
|
---|
45 |
|
---|
46 | int result = ArrayTools.findIndex(array, target);
|
---|
47 |
|
---|
48 | assertEquals(expected, result);
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Test
|
---|
52 | public void testFindIndex_3() throws Exception {
|
---|
53 | Integer target = 7;
|
---|
54 |
|
---|
55 | int result = ArrayTools.findIndex(array, target);
|
---|
56 | int expected = -1;
|
---|
57 |
|
---|
58 | assertEquals(expected, result);
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Test
|
---|
62 | public void testFindIndex_4() throws Exception {
|
---|
63 | Integer target = null;
|
---|
64 | int result = ArrayTools.findIndex(array, target);
|
---|
65 | int expected = 7;
|
---|
66 | assertEquals(expected, result);
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Test
|
---|
70 | public void testFindIndex_5() throws Exception {
|
---|
71 | Object[] array = new Object[0];
|
---|
72 | Object other = new Object();
|
---|
73 |
|
---|
74 | int result = ArrayTools.findIndex(array, other);
|
---|
75 |
|
---|
76 | assertEquals(-1, result);
|
---|
77 | }
|
---|
78 |
|
---|
79 | @Test
|
---|
80 | public void testFindMax_1() throws Exception {
|
---|
81 | int expected = 8;
|
---|
82 |
|
---|
83 | int result = ArrayTools.findMax(array);
|
---|
84 |
|
---|
85 | assertEquals(expected, result);
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Test
|
---|
89 | public void testFindMax_2() throws Exception {
|
---|
90 | Integer[] arrayUnsorted = new Integer[]{2,3,6,1,8,9,1,1,3,15,4,0,-1};
|
---|
91 | int expected = 9;
|
---|
92 |
|
---|
93 | int result = ArrayTools.findMax(arrayUnsorted);
|
---|
94 |
|
---|
95 | assertEquals(expected, result);
|
---|
96 | }
|
---|
97 |
|
---|
98 | @Test
|
---|
99 | public void testFindMax_3() throws Exception {
|
---|
100 | Integer[] arrayUnsorted = new Integer[]{2,3,6,1,8,9,1,1,3,15,4,15,-1};
|
---|
101 | int expected = 9;
|
---|
102 |
|
---|
103 | int result = ArrayTools.findMax(arrayUnsorted);
|
---|
104 |
|
---|
105 | assertEquals(expected, result);
|
---|
106 | }
|
---|
107 |
|
---|
108 | @Test
|
---|
109 | public void testFindMax_4() throws Exception {
|
---|
110 | Integer[] arrayNoLenght = new Integer[]{};
|
---|
111 | int expected = -1;
|
---|
112 |
|
---|
113 | int result = ArrayTools.findMax(arrayNoLenght);
|
---|
114 |
|
---|
115 | assertEquals(expected, result);
|
---|
116 | }
|
---|
117 |
|
---|
118 | @Test
|
---|
119 | public void testFindMax_5() throws Exception {
|
---|
120 | Integer[] arrayNulls = new Integer[]{null, null};
|
---|
121 | int expected = -1;
|
---|
122 |
|
---|
123 | int result = ArrayTools.findMax(arrayNulls);
|
---|
124 |
|
---|
125 | assertEquals(expected, result);
|
---|
126 | }
|
---|
127 |
|
---|
128 | @Test
|
---|
129 | public void testFindMax_6() throws Exception {
|
---|
130 | int expected = -1;
|
---|
131 |
|
---|
132 | int result = ArrayTools.findMax(null);
|
---|
133 |
|
---|
134 | assertEquals(expected, result);
|
---|
135 | }
|
---|
136 |
|
---|
137 | @Test
|
---|
138 | public void testFindMin_1() throws Exception {
|
---|
139 | int expected = 0;
|
---|
140 |
|
---|
141 | int result = ArrayTools.findMin(array);
|
---|
142 |
|
---|
143 | assertEquals(expected, result);
|
---|
144 | }
|
---|
145 |
|
---|
146 | @Test
|
---|
147 | public void testFindMin_2() throws Exception {
|
---|
148 | Integer[] arrayUnsorted = new Integer[]{2,3,6,1,8,9,1,1,-3,15,4,0,-1};
|
---|
149 | int expected = 8;
|
---|
150 |
|
---|
151 | int result = ArrayTools.findMin(arrayUnsorted);
|
---|
152 |
|
---|
153 | assertEquals(expected, result);
|
---|
154 | }
|
---|
155 |
|
---|
156 | @Test
|
---|
157 | public void testFindMin_3() throws Exception {
|
---|
158 | Integer[] arrayUnsorted = new Integer[]{2,3,6,1,8,9,1,-1,3,15,4,15,-1};
|
---|
159 | int expected = 7;
|
---|
160 |
|
---|
161 | int result = ArrayTools.findMin(arrayUnsorted);
|
---|
162 |
|
---|
163 | assertEquals(expected, result);
|
---|
164 | }
|
---|
165 |
|
---|
166 | @Test
|
---|
167 | public void testFindMin_4() throws Exception {
|
---|
168 | Integer[] arrayNoLenght = new Integer[]{};
|
---|
169 | int expected = -1;
|
---|
170 |
|
---|
171 | int result = ArrayTools.findMin(arrayNoLenght);
|
---|
172 |
|
---|
173 | assertEquals(expected, result);
|
---|
174 | }
|
---|
175 |
|
---|
176 | @Test
|
---|
177 | public void testFindMin_5() throws Exception {
|
---|
178 | Integer[] arrayNulls = new Integer[]{null, null};
|
---|
179 | int expected = -1;
|
---|
180 |
|
---|
181 | int result = ArrayTools.findMin(arrayNulls);
|
---|
182 |
|
---|
183 | assertEquals(expected, result);
|
---|
184 | }
|
---|
185 |
|
---|
186 | @Test
|
---|
187 | public void testFindMin_6() throws Exception {
|
---|
188 | int expected = -1;
|
---|
189 |
|
---|
190 | int result = ArrayTools.findMin(null);
|
---|
191 |
|
---|
192 | assertEquals(expected, result);
|
---|
193 | }
|
---|
194 |
|
---|
195 | @Before
|
---|
196 | public void setUp() throws Exception {
|
---|
197 | array = new Integer[] { 0, 1, 2, 3, 4, 4, 5, null, 6 };
|
---|
198 | }
|
---|
199 |
|
---|
200 | public static void main(String[] args) {
|
---|
201 | new org.junit.runner.JUnitCore().run(ArrayToolsTest.class);
|
---|
202 | }
|
---|
203 | } |
---|