|
| 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 Aitor Fidalgo (https://github.com/aitorfi) |
| 9 | + * @see BubbleSort |
| 10 | + */ |
| 11 | +public class BubbleSortTest { |
| 12 | + private BubbleSort bubbleSort = new BubbleSort(); |
| 13 | + |
| 14 | + @Test |
| 15 | + public void bubbleSortEmptyArray() { |
| 16 | + Integer[] inputArray = {}; |
| 17 | + Integer[] outputArray = bubbleSort.sort(inputArray); |
| 18 | + Integer[] expectedOutput = {}; |
| 19 | + assertArrayEquals(outputArray, expectedOutput); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + public void bubbleSortSingleIntegerElementArray() { |
| 24 | + Integer[] inputArray = {4}; |
| 25 | + Integer[] outputArray = bubbleSort.sort(inputArray); |
| 26 | + Integer[] expectedOutput = {4}; |
| 27 | + assertArrayEquals(outputArray, expectedOutput); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void bubbleSortSingleStringElementArray() { |
| 32 | + String[] inputArray = {"s"}; |
| 33 | + String[] outputArray = bubbleSort.sort(inputArray); |
| 34 | + String[] expectedOutput = {"s"}; |
| 35 | + assertArrayEquals(outputArray, expectedOutput); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void bubbleSortIntegerArray() { |
| 40 | + Integer[] inputArray = {4, 23, -6, 78, 1, 54, 23, -6, -231, 9, 12}; |
| 41 | + Integer[] outputArray = bubbleSort.sort(inputArray); |
| 42 | + Integer[] expectedOutput = {-231, -6, -6, 1, 4, 9, 12, 23, 23, 54, 78}; |
| 43 | + assertArrayEquals(outputArray, expectedOutput); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void bubbleSortStringArray() { |
| 48 | + String[] inputArray = {"cbf", "auk", "ó", "(b", "a", ")", "au", "á", "cba", "auk", "(a", "bhy", "cba"}; |
| 49 | + String[] outputArray = bubbleSort.sort(inputArray); |
| 50 | + String[] expectedOutput = {"(a", "(b", ")", "a", "au", "auk", "auk", "bhy", "cba", "cba", "cbf", "á", "ó"}; |
| 51 | + assertArrayEquals(outputArray, expectedOutput); |
| 52 | + } |
| 53 | +} |
0 commit comments