Added test cases to CocktailShakerSort. (#3766)

* Add testcase to CocktailShakerSort Algorithm

* fixed method name to lowerCamelCase
This commit is contained in:
김준홍 2022-11-16 17:09:02 +09:00 committed by GitHub
parent f7dee0d958
commit ac71f6eb79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,68 @@
package com.thealgorithms.sorts;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.junit.jupiter.api.Test;
/**
* @author Tabbygray (https://github.com/Tabbygray)
* @see CocktailShakerSort
*/
public class CocktailShakerSortTest {
private CocktailShakerSort cocktailShakerSort = new CocktailShakerSort();
@Test
public void cocktailShakerSortEmptyArray(){
Integer[] inputArray = {};
Integer[] outputArray = cocktailShakerSort.sort(inputArray);
Integer[] expectedOutput = {};
assertArrayEquals(outputArray, expectedOutput);
}
@Test
public void cocktailShakerSortSingleStringElementArray(){
String[] inputArray = {"Test"};
String[] outputArray = cocktailShakerSort.sort(inputArray);
String[] expectedOutput = {"Test"};
assertArrayEquals(outputArray, expectedOutput);
}
@Test
public void cocktailShakerSortIntegerArray(){
Integer[] inputArray = { 2, 92, 1, 33, -33, 27, 5, 100, 78, 99, -100};
Integer[] outputArray = cocktailShakerSort.sort(inputArray);
Integer[] expectedOutput = { -100, -33, 1, 2, 5, 27, 33, 78, 92, 99, 100};
assertArrayEquals(outputArray, expectedOutput);
}
@Test
public void cocktailShakerSortStringArray(){
String[] inputArray = {
"g3x1",
"dN62",
"oMdr",
"KL2b",
"JddJ",
"mvE8",
"Ej7Q",
"n7n7",
"LGTg",
"2E1w",
};
String[] outputArray = cocktailShakerSort.sort(inputArray);
String[] expectedOutput = {
"2E1w",
"Ej7Q",
"JddJ",
"KL2b",
"LGTg",
"dN62",
"g3x1",
"mvE8",
"n7n7",
"oMdr",
};
assertArrayEquals(outputArray, expectedOutput);
}
}