* BAEL-5563 Reverse a number initial commit * BAEL-5563 Final improvements before PR * BAEL-5563 Reverse a number - Draft improvements * BAEL-5563 Reverse a number - Recursive method improvements * BAEL-5563 Reverse a number - Recursive method improvements * BAEL-5563 Reverse a number - Remove unused imports Co-authored-by: Timothy Kruger - Lenny <gapptechnology@gmail.com> Co-authored-by: claud <180181@virtualwindow.co.za>
34 lines
1.3 KiB
Java
34 lines
1.3 KiB
Java
package com.baeldung.reversenumber;
|
|
|
|
import org.assertj.core.api.Assertions;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
class ReverseNumberUnitTest {
|
|
|
|
private static final int ORIGINAL_NUMBER = 123456789;
|
|
private static final int REVERSED_NUMBER = 987654321;
|
|
|
|
@Test
|
|
void whenReverseNumberWhileLoop_thenOriginalEqualToReverse() {
|
|
Assertions.assertThat(ReverseNumber.reverseNumberWhileLoop(ORIGINAL_NUMBER)).isEqualTo(REVERSED_NUMBER);
|
|
}
|
|
|
|
@Test
|
|
void whenReverseNumberForLoop_thenOriginalEqualToReverse() {
|
|
Assertions.assertThat(ReverseNumber.reverseNumberForLoop(ORIGINAL_NUMBER)).isEqualTo(REVERSED_NUMBER);
|
|
}
|
|
|
|
@Test
|
|
void whenReverseNumberRec_thenOriginalEqualToReverse() {
|
|
Assertions.assertThat(ReverseNumber.reverseNumberRecWrapper(ORIGINAL_NUMBER)).isEqualTo(REVERSED_NUMBER);
|
|
}
|
|
|
|
@Test
|
|
void whenReverseNegativeNumber_thenNumberShouldReverse() {
|
|
Assertions.assertThat(ReverseNumber.reverseNumberWhileLoop(ORIGINAL_NUMBER * -1)).isEqualTo(REVERSED_NUMBER * -1);
|
|
Assertions.assertThat(ReverseNumber.reverseNumberForLoop(ORIGINAL_NUMBER * -1)).isEqualTo(REVERSED_NUMBER * -1);
|
|
Assertions.assertThat(ReverseNumber.reverseNumberRecWrapper(ORIGINAL_NUMBER * -1)).isEqualTo(REVERSED_NUMBER * -1);
|
|
}
|
|
} |