From: Roland Häder Date: Wed, 19 Oct 2022 11:34:34 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f1c3cb0fb32764397705c588ed82a9b31a9716d3;p=jcore-utils.git Continued: - added GIT hook "pre-commit" which you should copy to .git/hooks/ or symlink it there - renamed Comparables -> ComparableUtils to conform with naming-convention --- diff --git a/commit-hooks/README.txt b/commit-hooks/README.txt new file mode 100644 index 0000000..6bacfed --- /dev/null +++ b/commit-hooks/README.txt @@ -0,0 +1,2 @@ +Please copy these scripts to your clone-directory's .git/hooks/ directory to +have e.g. unit-tests being run. diff --git a/commit-hooks/pre-commit b/commit-hooks/pre-commit new file mode 100755 index 0000000..22bef22 --- /dev/null +++ b/commit-hooks/pre-commit @@ -0,0 +1,6 @@ +#!/bin/sh + +echo "$0: Running unit tests ..." +ant -silent test || exit 255 + +echo "$0: All done." diff --git a/src/org/mxchange/jcoreutils/comparable/ComparableUtils.java b/src/org/mxchange/jcoreutils/comparable/ComparableUtils.java new file mode 100644 index 0000000..bfc6063 --- /dev/null +++ b/src/org/mxchange/jcoreutils/comparable/ComparableUtils.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2022 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcoreutils.comparable; + +import java.io.Serializable; + +/** + * An utilities class for comparison of objects/entities + *

+ * @author Roland Häder + */ +public class ComparableUtils implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 19_286_457_671_390L; + + /** + * Checks all comparison values if they are not zero and returns proper + * value. These comparators should come from an implementation of + * Comparable.compareTo(). + *

+ * @param comparators An array of at least one comparator + *

+ * @return Comparison value + */ + public static int checkAll (final int[] comparators) { + // Is array empty? + if (comparators.length == 0) { + // Should not happen + throw new IllegalArgumentException("comparators is empty."); //NOI18N + } + + // Loop through all + for (int i = 0; i < comparators.length; i++) { + // Is it smaller or bigger? + if (comparators[i] < 0) { + return -1; + } else if (comparators[i] > 0) { + return 1; + } + } + + // Assume equality + return 0; + } + + /** + * Utility classes should not have instances + */ + private ComparableUtils () { + } + +} diff --git a/src/org/mxchange/jcoreutils/comparable/Comparables.java b/src/org/mxchange/jcoreutils/comparable/Comparables.java deleted file mode 100644 index ee7951b..0000000 --- a/src/org/mxchange/jcoreutils/comparable/Comparables.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2022 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcoreutils.comparable; - -import java.io.Serializable; - -/** - * An utilities class for comparison of objects/entities - *

- * @author Roland Häder - */ -public class Comparables implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 19_286_457_671_390L; - - /** - * Checks all comparison values if they are not zero and returns proper - * value. These comparators should come from an implementation of - * Comparable.compareTo(). - *

- * @param comparators An array of at least one comparator - *

- * @return Comparison value - */ - public static int checkAll (final int[] comparators) { - // Is array empty? - if (comparators.length == 0) { - // Should not happen - throw new IllegalArgumentException("comparators is empty."); //NOI18N - } - - // Loop through all - for (int i = 0; i < comparators.length; i++) { - // Is it smaller or bigger? - if (comparators[i] < 0) { - return -1; - } else if (comparators[i] > 0) { - return 1; - } - } - - // Assume equality - return 0; - } - - /** - * Utility classes should not have instances - */ - private Comparables () { - } - -} diff --git a/test/org/mxchange/jcoreutils/test/comparable/ComparableUtilsTest.java b/test/org/mxchange/jcoreutils/test/comparable/ComparableUtilsTest.java new file mode 100644 index 0000000..8a7987d --- /dev/null +++ b/test/org/mxchange/jcoreutils/test/comparable/ComparableUtilsTest.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2022 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcoreutils.test.comparable; + +import org.mxchange.jcoreutils.comparable.ComparableUtils; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * Test cases for ComparableUtils utilities class + *

+ * @author Roland Häder + */ +public class ComparableUtilsTest { + + /** + * Default constructor + */ + public ComparableUtilsTest () { + } + + @Test (description = "Tests if 1 is returned") + public void testAboveZero () { + // Test method + Assert.assertEquals(ComparableUtils.checkAll(new int[]{0, 0, 1}), 1); + Assert.assertEquals(ComparableUtils.checkAll(new int[]{0, 0, 10}), 1); + Assert.assertEquals(ComparableUtils.checkAll(new int[]{0, 0, 100}), 1); + } + + @Test (description = "Tests if -1 is returned") + public void testBelowZero () { + // Test method + Assert.assertEquals(ComparableUtils.checkAll(new int[]{0, 0, -1}), -1); + Assert.assertEquals(ComparableUtils.checkAll(new int[]{0, 0, -10}), -1); + Assert.assertEquals(ComparableUtils.checkAll(new int[]{0, 0, -100}), -1); + } + + @Test (description = "Tests if when provided array is empty a specific exception is thrown", expectedExceptions = {IllegalArgumentException.class}) + public void testIllegalArgumentException () { + // Test method + ComparableUtils.checkAll(new int[]{}); + } + + @Test (description = "Tests if zero is returned") + public void testZero () { + // Test method + Assert.assertEquals(ComparableUtils.checkAll(new int[]{0, 0, 0}), 0); + } + +} diff --git a/test/org/mxchange/jcoreutils/test/comparable/ComparablesTest.java b/test/org/mxchange/jcoreutils/test/comparable/ComparablesTest.java deleted file mode 100644 index 2c734dd..0000000 --- a/test/org/mxchange/jcoreutils/test/comparable/ComparablesTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2022 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcoreutils.test.comparable; - -import org.mxchange.jcoreutils.comparable.Comparables; -import org.testng.Assert; -import org.testng.annotations.Test; - -/** - * Test cases for Comparables utlities class - *

- * @author Roland Häder - */ -public class ComparablesTest { - - /** - * Default constructor - */ - public ComparablesTest () { - } - - @Test (description = "Tests if 1 is returned") - public void testAboveZero () { - // Test method - Assert.assertEquals(Comparables.checkAll(new int[]{0, 0, 1}), 1); - Assert.assertEquals(Comparables.checkAll(new int[]{0, 0, 10}), 1); - Assert.assertEquals(Comparables.checkAll(new int[]{0, 0, 100}), 1); - } - - @Test (description = "Tests if -1 is returned") - public void testBelowZero () { - // Test method - Assert.assertEquals(Comparables.checkAll(new int[]{0, 0, -1}), -1); - Assert.assertEquals(Comparables.checkAll(new int[]{0, 0, -10}), -1); - Assert.assertEquals(Comparables.checkAll(new int[]{0, 0, -100}), -1); - } - - @Test (description = "Tests if when provided array is empty a specific exception is thrown", expectedExceptions = {IllegalArgumentException.class}) - public void testIllegalArgumentException () { - // Test method - Comparables.checkAll(new int[]{}); - } - - @Test (description = "Tests if zero is returned") - public void testZero () { - // Test method - Assert.assertEquals(Comparables.checkAll(new int[]{0, 0, 0}), 0); - } - -}