Skip to content

Commit 1e933eb

Browse files
committed
Adding Unit Testing
1 parent 3bed2b5 commit 1e933eb

File tree

3 files changed

+741
-103
lines changed

3 files changed

+741
-103
lines changed

TODO.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66

77
<hr>
88

9-
- [ ] Add Testing for NumberUtils and ArrayList8
9+
- [X] Add Testing for NumberUtils
10+
- [ ] Add Testing for ArrayList8
1011
- [ ] Complete JavaDoc for new methods

src/main/java/CodingUtils/NumberUtils.java

Lines changed: 17 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
.
1010
. The NumberUtils Class was Coded by : Alexandre BOLOT
1111
.
12-
. Last Modified : 02/12/17 01:03
12+
. Last Modified : 10/12/17 23:03
1313
.
1414
. Contact : [email protected]
1515
...............................................................................................................................*/
@@ -172,7 +172,7 @@ public static boolean isInBounds (double minBound, double value, double maxBound
172172
{
173173
if (maxBound < minBound) throw new IllegalArgumentException("maxBound < minBound");
174174

175-
return minBound < value && value > maxBound;
175+
return minBound < value && value < maxBound;
176176
}
177177

178178
/**
@@ -190,10 +190,11 @@ public static <T> boolean isInBounds (T minBound, T value, T maxBound, Comparato
190190
Objects.requireNonNull(value, "value is null");
191191
Objects.requireNonNull(minBound, "minBound is null");
192192
Objects.requireNonNull(maxBound, "maxBound is null");
193+
Objects.requireNonNull(comparator, "comparator is null");
193194

194195
if (comparator.compare(maxBound, minBound) < 0) throw new IllegalArgumentException("maxBound < minBound");
195196

196-
return comparator.compare(value, minBound) > 0 && comparator.compare(value, maxBound) < 0;
197+
return comparator.compare(minBound, value) < 0 && comparator.compare(value, maxBound) < 0;
197198
}
198199

199200
/**
@@ -214,43 +215,15 @@ public static <T extends Comparable<T>> boolean isInBounds (T minBound, T value,
214215

215216
if (maxBound.compareTo(minBound) < 0) throw new IllegalArgumentException("maxBound < minBound");
216217

217-
return value.compareTo(minBound) > 0 && value.compareTo(maxBound) < 0;
218+
return minBound.compareTo(value) < 0 && value.compareTo(maxBound) < 0;
218219
}
219220
//endregion
220221

221-
//region ============ min (x7) ===================
222-
public static int min (int[] array)
223-
{
224-
if (array.length == 0) throw new IllegalArgumentException("Array is empty");
225-
if (array.length == 1) return array[0];
226-
227-
int min = Integer.MAX_VALUE;
228-
229-
for (int i : array)
230-
{
231-
if (i < min) min = i;
232-
}
233-
234-
return min;
235-
}
236-
237-
public static float min (float[] array)
238-
{
239-
if (array.length == 0) throw new IllegalArgumentException("Array is empty");
240-
if (array.length == 1) return array[0];
241-
242-
float min = Float.MAX_VALUE;
243-
244-
for (Float i : array)
245-
{
246-
if (i < min) min = i;
247-
}
248-
249-
return min;
250-
}
251-
222+
//region ============ min (x5) ===================
252223
public static double min (double[] array)
253224
{
225+
Objects.requireNonNull(array);
226+
254227
if (array.length == 0) throw new IllegalArgumentException("Array is empty");
255228
if (array.length == 1) return array[0];
256229

@@ -266,6 +239,8 @@ public static double min (double[] array)
266239

267240
public static <T> T min (T[] array, Comparator<T> comparator)
268241
{
242+
Objects.requireNonNull(array);
243+
269244
if (array.length == 0) throw new IllegalArgumentException("Array is empty");
270245
if (array.length == 1) return array[0];
271246

@@ -281,6 +256,8 @@ public static <T> T min (T[] array, Comparator<T> comparator)
281256

282257
public static <T> T min (Collection<T> collection, Comparator<T> comparator)
283258
{
259+
Objects.requireNonNull(collection);
260+
284261
if (collection.size() == 0) throw new IllegalArgumentException("Collection is empty");
285262
if (collection.size() == 1) return (T) collection.toArray()[0];
286263

@@ -296,6 +273,8 @@ public static <T> T min (Collection<T> collection, Comparator<T> comparator)
296273

297274
public static <T extends Comparable<T>> T min (T[] array)
298275
{
276+
Objects.requireNonNull(array);
277+
299278
if (array.length == 0) throw new IllegalArgumentException("Array is empty");
300279
if (array.length == 1) return array[0];
301280

@@ -311,6 +290,8 @@ public static <T extends Comparable<T>> T min (T[] array)
311290

312291
public static <T extends Comparable<T>> T min (Collection<T> collection)
313292
{
293+
Objects.requireNonNull(collection);
294+
314295
if (collection.size() == 0) throw new IllegalArgumentException("Collection is empty");
315296
if (collection.size() == 1) return (T) collection.toArray()[0];
316297

@@ -325,35 +306,7 @@ public static <T extends Comparable<T>> T min (Collection<T> collection)
325306
}
326307
//endregion
327308

328-
//region ============ max (x7) ===================
329-
public static int max (int[] array)
330-
{
331-
if (array.length == 0) throw new IllegalArgumentException("Array is empty");
332-
333-
int max = Integer.MIN_VALUE;
334-
335-
for (int i : array)
336-
{
337-
if (i > max) max = i;
338-
}
339-
340-
return max;
341-
}
342-
343-
public static float max (float[] array)
344-
{
345-
if (array.length == 0) throw new IllegalArgumentException("Array is empty");
346-
347-
float max = Integer.MIN_VALUE;
348-
349-
for (float i : array)
350-
{
351-
if (i > max) max = i;
352-
}
353-
354-
return max;
355-
}
356-
309+
//region ============ max (x5) ===================
357310
public static double max (double[] array)
358311
{
359312
if (array.length == 0) throw new IllegalArgumentException("Array is empty");

0 commit comments

Comments
 (0)