From bdfecbe1c1b80761c2a061a3304ba873095131d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A4=80=ED=99=8D?= Date: Sun, 27 Nov 2022 00:20:53 +0900 Subject: [PATCH] Added test cases to CombSort. (#3776) * Add testcase to CocktailShakerSort Algorithm * fixed method name to lowerCamelCase * Added test cases to OddEvenSortTest * Added test case to CombSort --- .../com/thealgorithms/sorts/CombSortTest.java | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/test/java/com/thealgorithms/sorts/CombSortTest.java diff --git a/src/test/java/com/thealgorithms/sorts/CombSortTest.java b/src/test/java/com/thealgorithms/sorts/CombSortTest.java new file mode 100644 index 000000000..a6eb40c6b --- /dev/null +++ b/src/test/java/com/thealgorithms/sorts/CombSortTest.java @@ -0,0 +1,89 @@ +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 CombSort + */ + +public class CombSortTest { + + private CombSort combSort = new CombSort(); + + @Test + public void combSortEmptyArray() { + Integer[] inputArray = {}; + Integer[] outputArray = combSort.sort(inputArray); + Integer[] expectedOutput = {}; + assertArrayEquals(outputArray, expectedOutput); + } + + @Test + public void combSortSingleStringElement() { + String[] inputArray = {"Test"}; + String[] outputArray = combSort.sort(inputArray); + String[] expectedArray = {"Test"}; + assertArrayEquals(outputArray, expectedArray); + } + + @Test + public void combSortStringArray() { + String[] inputArray = { + "4gp8", + "aBJ2", + "85cW", + "Pmk9", + "ewZO", + "meuU", + "RhNd", + "5TKB", + "eDd5", + "zzyo" + }; + String[] outputArray = combSort.sort(inputArray); + String[] expectedArray = { + "4gp8", + "5TKB", + "85cW", + "Pmk9", + "RhNd", + "aBJ2", + "eDd5", + "ewZO", + "meuU", + "zzyo" + }; + assertArrayEquals(outputArray, expectedArray); + } + + @Test + public void combSortIntegerArray() { + Integer[] inputArray = { 36, 98, -51, -23, 66, -58, 31, 25, -30, 40 }; + Integer[] outputArray = combSort.sort(inputArray); + Integer[] expectedArray = { -58, -51, -30, -23, 25, 31, 36, 40, 66, 98 }; + assertArrayEquals(outputArray, expectedArray); + } + + @Test + public void combSortDoubleArray() { + Double[] inputArray = { + 0.8335545399, 0.9346214114, + 0.3096396752, 0.6433840668, + 0.3973191975, 0.6118850724, + 0.0553975453, 0.1961108601, + 0.6172800885, 0.1065247772 + }; + Double[] outputArray = combSort.sort(inputArray); + Double[] expectedArray = { + 0.0553975453, 0.1065247772, + 0.1961108601, 0.3096396752, + 0.3973191975, 0.6118850724, + 0.6172800885, 0.6433840668, + 0.8335545399, 0.9346214114, + }; + assertArrayEquals(outputArray, expectedArray); + } +}