diff --git a/src/main/java/com/sorts/BubbleSort.java b/src/main/java/com/sorts/BubbleSort.java index f12504cfc014..a22737bd6b5d 100644 --- a/src/main/java/com/sorts/BubbleSort.java +++ b/src/main/java/com/sorts/BubbleSort.java @@ -2,7 +2,7 @@ import com.types.Sort; -public class BubbleSort implements Sort { +public class BubbleSort> implements Sort { /** * This method implements the Generic Bubble Sort * @@ -11,7 +11,7 @@ public class BubbleSort implements Sort { **/ @Override - public > T[] sort(T[] array) { + public T[] sort(T[] array) { int last = array.length; //Sorting boolean swap; diff --git a/src/main/java/com/types/DataStructure.java b/src/main/java/com/types/DataStructure.java index c8151ea32428..d2a9050bb8dc 100644 --- a/src/main/java/com/types/DataStructure.java +++ b/src/main/java/com/types/DataStructure.java @@ -3,7 +3,7 @@ import java.util.Iterator; /** - * This interface is to define bacis functionality expected out of any implementation class + * This interface is to define basic functionality expected out of any implementation class * Since this is a data structure it should have the flexibility to contain any kind of object hence it has been made generic * Any implementation class need not to be thread safe or it could be depending on the implementation class how does it want to behave. * diff --git a/src/main/java/com/types/Sort.java b/src/main/java/com/types/Sort.java index cc9519caf8e4..876b8ee1e09d 100644 --- a/src/main/java/com/types/Sort.java +++ b/src/main/java/com/types/Sort.java @@ -1,7 +1,7 @@ package com.types; @FunctionalInterface -public interface Sort { +public interface Sort> { - > T[] sort(T[] array); + T[] sort(T[] array); } diff --git a/src/test/java/com/sorts/BubbleSortTest.java b/src/test/java/com/sorts/BubbleSortTest.java index 4d153d168a6d..3a9f6d3ac560 100644 --- a/src/test/java/com/sorts/BubbleSortTest.java +++ b/src/test/java/com/sorts/BubbleSortTest.java @@ -6,17 +6,32 @@ class BubbleSortTest { @Test - void bubbleSortTest() { - BubbleSort bubbleSort = new BubbleSort(); + void bubbleSortTestIntegers() { + BubbleSort bubbleSort = new BubbleSort<>(); - Integer[] unsortedInt = new Integer[]{0, 5, 9, 2, 1, 3, 4, 8, 6, 7}; - Integer[] sortedInt = new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + Integer[] unsortedInt = {0, 5, 9, 2, 1, 3, 4, 8, 6, 7}; + Integer[] sortedInt = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; Assertions.assertArrayEquals(sortedInt, bubbleSort.sort(unsortedInt)); - Character[] unsortedChar = new Character[]{'f', 'h', 'c', 'a', 'b', 'd', 'g', 'e'}; - Character[] sortedChar = new Character[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}; + } + + @Test + void bubbleSortTestCharacters() { + BubbleSort bubbleSort = new BubbleSort<>(); + + Character[] unsortedChar = {'f', 'h', 'c', 'a', 'b', 'd', 'g', 'e'}; + Character[] sortedChar = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}; Assertions.assertArrayEquals(sortedChar, bubbleSort.sort(unsortedChar)); } + @Test + void bubbleSortTestStrings() { + BubbleSort bubbleSort = new BubbleSort<>(); + + String[] unsortedChar = {"abc", "adc", "bcd", "abb", "abc", "acb"}; + String[] sortedChar = {"abb", "abc", "abc", "acb", "adc", "bcd"}; + Assertions.assertArrayEquals(sortedChar, bubbleSort.sort(unsortedChar)); + + } }