Skip to content

Commit 898c2f6

Browse files
authored
Add tests for Selection Sort (TheAlgorithms#3091)
1 parent 0abce97 commit 898c2f6

File tree

2 files changed

+66
-25
lines changed

2 files changed

+66
-25
lines changed
Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1-
package com.thealgorithms.maths;
2-
3-
import org.junit.jupiter.api.Test;
4-
5-
import static org.junit.jupiter.api.Assertions.assertEquals;
6-
7-
/**
8-
* @author SirFixalot16
9-
* @since 01/06/22
10-
*/
11-
public class SumOfDigitsTest {
12-
@Test
13-
void isSumOf2Digits() {
14-
SumOfDigits sum = new SumOfDigits();
15-
assertEquals(11, sum.sumOfDigits(56));
16-
}
17-
void isSumOf3Digits() {
18-
SumOfDigits sum = new SumOfDigits();
19-
assertEquals(12, sum.sumOfDigits(192));
20-
}
21-
void isSumOf4Digits() {
22-
SumOfDigits sum = new SumOfDigits();
23-
assertEquals(25, sum.sumOfDigits(8962));
24-
}
25-
}
1+
package com.thealgorithms.maths;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class SumOfDigitsTest {
8+
9+
SumOfDigits SoD = new SumOfDigits();
10+
11+
@Test
12+
void testZero() {
13+
assertEquals(0, SoD.sumOfDigits(0));
14+
assertEquals(0, SoD.sumOfDigitsRecursion(0));
15+
assertEquals(0, SoD.sumOfDigitsFast(0));
16+
}
17+
18+
@Test
19+
void testPositive() {
20+
assertEquals(15, SoD.sumOfDigits(12345));
21+
assertEquals(15, SoD.sumOfDigitsRecursion(12345));
22+
assertEquals(15, SoD.sumOfDigitsFast(12345));
23+
}
24+
25+
@Test
26+
void testNegative() {
27+
assertEquals(6, SoD.sumOfDigits(-123));
28+
assertEquals(6, SoD.sumOfDigitsRecursion(-123));
29+
assertEquals(6, SoD.sumOfDigitsFast(-123));
30+
}
31+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.thealgorithms.sorts;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class SelectionSortTest {
8+
9+
@Test
10+
// valid test case
11+
void IntegerArrTest() {
12+
Integer[] arr = {4, 23, 6, 78, 1, 54, 231, 9, 12};
13+
SelectionSort selectionSort = new SelectionSort();
14+
15+
assertArrayEquals(new Integer[]{1, 4, 6, 9, 12, 23, 54, 78, 231}, selectionSort.sort(arr));
16+
}
17+
18+
@Test
19+
// valid test case
20+
void StringArrTest() {
21+
String[] arr = {"c", "a", "e", "b", "d"};
22+
SelectionSort selectionSort = new SelectionSort();
23+
24+
assertArrayEquals(new String[]{"a", "b", "c", "d", "e"}, selectionSort.sort(arr));
25+
}
26+
27+
@Test
28+
// invalid test case
29+
void emptyArrTest() {
30+
Integer[] arr = {};
31+
SelectionSort selectionSort = new SelectionSort();
32+
33+
assertArrayEquals(new Integer[]{}, selectionSort.sort(arr));
34+
}
35+
}

0 commit comments

Comments
 (0)