File tree Expand file tree Collapse file tree 3 files changed +32
-8
lines changed
main/java/com/thealgorithms/maths
test/java/com/thealgorithms/maths Expand file tree Collapse file tree 3 files changed +32
-8
lines changed Original file line number Diff line number Diff line change 655
655
* [ MedianTest] ( https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MedianTest.java )
656
656
* [ MobiusFunctionTest] ( https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MobiusFunctionTest.java )
657
657
* [ NthUglyNumberTest] ( https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/NthUglyNumberTest.java )
658
+ * [ PalindromeNumberTest] ( https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PalindromeNumberTest.java )
658
659
* [ PascalTriangleTest] ( https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PascalTriangleTest.java )
659
660
* [ PerfectCubeTest] ( https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PerfectCubeTest.java )
660
661
* [ PerfectNumberTest] ( https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PerfectNumberTest.java )
Original file line number Diff line number Diff line change 1
1
package com .thealgorithms .maths ;
2
2
3
3
public class PalindromeNumber {
4
-
5
- public static void main (String [] args ) {
6
- assert isPalindrome (12321 );
7
- assert !isPalindrome (1234 );
8
- assert isPalindrome (1 );
9
- }
10
-
11
4
/**
12
5
* Check if {@code n} is palindrome number or not
13
6
*
@@ -17,7 +10,7 @@ public static void main(String[] args) {
17
10
*/
18
11
public static boolean isPalindrome (int number ) {
19
12
if (number < 0 ) {
20
- throw new IllegalArgumentException (number + " " );
13
+ throw new IllegalArgumentException ("Input parameter must not be negative! " );
21
14
}
22
15
int numberCopy = number ;
23
16
int reverseNumber = 0 ;
Original file line number Diff line number Diff line change
1
+ package com .thealgorithms .maths ;
2
+
3
+ import org .junit .jupiter .api .Assertions ;
4
+ import org .junit .jupiter .api .Test ;
5
+
6
+ /**
7
+ * @author Albina Gimaletdinova on 01/07/2023
8
+ */
9
+ public class PalindromeNumberTest {
10
+ @ Test
11
+ public void testNumbersArePalindromes () {
12
+ Assertions .assertTrue (PalindromeNumber .isPalindrome (0 ));
13
+ Assertions .assertTrue (PalindromeNumber .isPalindrome (1 ));
14
+ Assertions .assertTrue (PalindromeNumber .isPalindrome (2332 ));
15
+ Assertions .assertTrue (PalindromeNumber .isPalindrome (12321 ));
16
+ }
17
+
18
+ @ Test
19
+ public void testNumbersAreNotPalindromes () {
20
+ Assertions .assertFalse (PalindromeNumber .isPalindrome (12 ));
21
+ Assertions .assertFalse (PalindromeNumber .isPalindrome (990 ));
22
+ Assertions .assertFalse (PalindromeNumber .isPalindrome (1234 ));
23
+ }
24
+
25
+ @ Test
26
+ public void testIfNegativeInputThenExceptionExpected () {
27
+ IllegalArgumentException exception = Assertions .assertThrows (IllegalArgumentException .class , () -> PalindromeNumber .isPalindrome (-1 ));
28
+ Assertions .assertEquals (exception .getMessage (), "Input parameter must not be negative!" );
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments