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 = 9;
|
---|
131 |
|
---|
132 | double[] array = {2,3,6,1,8,9,1,1,3,15,4,15,-1};
|
---|
133 |
|
---|
134 | int result = ArrayTools.findMax(array);
|
---|
135 |
|
---|
136 | assertEquals(expected, result);
|
---|
137 | }
|
---|
138 |
|
---|
139 | @Test
|
---|
140 | public void testFindMin_1() throws Exception {
|
---|
141 | int expected = 0;
|
---|
142 |
|
---|
143 | int result = ArrayTools.findMin(array);
|
---|
144 |
|
---|
145 | assertEquals(expected, result);
|
---|
146 | }
|
---|
147 |
|
---|
148 | @Test
|
---|
149 | public void testFindMin_2() throws Exception {
|
---|
150 | Integer[] arrayUnsorted = new Integer[]{2,3,6,1,8,9,1,1,-3,15,4,0,-1};
|
---|
151 | int expected = 8;
|
---|
152 |
|
---|
153 | int result = ArrayTools.findMin(arrayUnsorted);
|
---|
154 |
|
---|
155 | assertEquals(expected, result);
|
---|
156 | }
|
---|
157 |
|
---|
158 | @Test
|
---|
159 | public void testFindMin_3() throws Exception {
|
---|
160 | Integer[] arrayUnsorted = new Integer[]{2,3,6,1,8,9,1,-1,3,15,4,15,-1};
|
---|
161 | int expected = 7;
|
---|
162 |
|
---|
163 | int result = ArrayTools.findMin(arrayUnsorted);
|
---|
164 |
|
---|
165 | assertEquals(expected, result);
|
---|
166 | }
|
---|
167 |
|
---|
168 | @Test
|
---|
169 | public void testFindMin_4() throws Exception {
|
---|
170 | Integer[] arrayNoLenght = new Integer[]{};
|
---|
171 | int expected = -1;
|
---|
172 |
|
---|
173 | int result = ArrayTools.findMin(arrayNoLenght);
|
---|
174 |
|
---|
175 | assertEquals(expected, result);
|
---|
176 | }
|
---|
177 |
|
---|
178 | @Test
|
---|
179 | public void testFindMin_5() throws Exception {
|
---|
180 | Integer[] arrayNulls = new Integer[]{null, null};
|
---|
181 | int expected = -1;
|
---|
182 |
|
---|
183 | int result = ArrayTools.findMin(arrayNulls);
|
---|
184 |
|
---|
185 | assertEquals(expected, result);
|
---|
186 | }
|
---|
187 |
|
---|
188 | @Test
|
---|
189 | public void testFindMin_6() throws Exception {
|
---|
190 | int expected = -1;
|
---|
191 |
|
---|
192 | int result = ArrayTools.findMin(null);
|
---|
193 |
|
---|
194 | assertEquals(expected, result);
|
---|
195 | }
|
---|
196 |
|
---|
197 | @Before
|
---|
198 | public void setUp() throws Exception {
|
---|
199 | array = new Integer[] { 0, 1, 2, 3, 4, 4, 5, null, 6 };
|
---|
200 | }
|
---|
201 |
|
---|
202 | public static void main(String[] args) {
|
---|
203 | new org.junit.runner.JUnitCore().run(ArrayToolsTest.class);
|
---|
204 | }
|
---|
205 | } |
---|