Skip to content

Commit ce55420

Browse files
authored
Add tests for Tree Sort (#3787)
1 parent 9123474 commit ce55420

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.thealgorithms.sorts;
2+
3+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
/**
8+
* @author Tabbygray (https://github.com/Tabbygray)
9+
* @see TreeSort
10+
*/
11+
12+
public class TreeSortTest {
13+
private TreeSort treeSort = new TreeSort();
14+
15+
@Test
16+
public void treeSortEmptyArray(){
17+
Integer[] inputArray = {};
18+
Integer[] outputArray = treeSort.sort(inputArray);
19+
Integer[] expectedOutput = {};
20+
assertArrayEquals(outputArray, expectedOutput);
21+
}
22+
23+
@Test
24+
public void treeSortSingleStringElement() {
25+
String[] inputArray = {"Test"};
26+
String[] outputArray = treeSort.sort(inputArray);
27+
String[] expectedArray = {"Test"};
28+
assertArrayEquals(outputArray, expectedArray);
29+
}
30+
31+
@Test
32+
public void treeSortStringArray() {
33+
String[] inputArray = {
34+
"F6w9",
35+
"l1qz",
36+
"dIxH",
37+
"larj",
38+
"kRzy",
39+
"vnNH",
40+
"3ftM",
41+
"hc4n",
42+
"C5Qi",
43+
"btGF"
44+
};
45+
String[] outputArray = treeSort.sort(inputArray);
46+
String[] expectedArray = {
47+
"3ftM",
48+
"C5Qi",
49+
"F6w9",
50+
"btGF",
51+
"dIxH",
52+
"hc4n",
53+
"kRzy",
54+
"l1qz",
55+
"larj",
56+
"vnNH"
57+
};
58+
assertArrayEquals(outputArray, expectedArray);
59+
}
60+
61+
@Test
62+
public void treeSortIntegerArray() {
63+
Integer[] inputArray = { -97, -44, -4, -85, -92, 74, 79, -26, 76, -5 };
64+
Integer[] outputArray = treeSort.sort(inputArray);
65+
Integer[] expectedArray = { -97, -92, -85, -44, -26, -5, -4, 74, 76, 79 };
66+
assertArrayEquals(outputArray, expectedArray);
67+
}
68+
69+
@Test
70+
public void treeSortDoubleArray() {
71+
Double[] inputArray = {
72+
0.8047485045, 0.4493112337,
73+
0.8298433723, 0.2691406748,
74+
0.2482782839, 0.5976243420,
75+
0.6746235284, 0.0552623569,
76+
0.3515624123, 0.0536747336
77+
};
78+
Double[] outputArray = treeSort.sort(inputArray);
79+
Double[] expectedArray = {
80+
0.0536747336, 0.0552623569,
81+
0.2482782839, 0.2691406748,
82+
0.3515624123, 0.4493112337,
83+
0.5976243420, 0.6746235284,
84+
0.8047485045, 0.8298433723
85+
};
86+
assertArrayEquals(outputArray, expectedArray);
87+
}
88+
}

0 commit comments

Comments
 (0)