|
| 1 | +package com.thealgorithms.sorts; |
| 2 | +import org.junit.jupiter.api.Test; |
| 3 | + |
| 4 | +import java.util.Arrays; |
| 5 | + |
| 6 | +import static org.junit.jupiter.api.Assertions.*; |
| 7 | + |
| 8 | +public class DutchNationalFlagSortTest { |
| 9 | + @Test |
| 10 | + /* |
| 11 | + 1 will be used as intended middle. |
| 12 | + Partitions on the result array: [ smaller than 1 , equal 1, greater than 1] |
| 13 | + */ |
| 14 | + void DNFSTestOdd() { |
| 15 | + Integer[] integers = {1, 3, 1, 4, 0}; |
| 16 | + Integer[] integersResult = {0, 1, 1, 4, 3}; |
| 17 | + DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort(); |
| 18 | + dutchNationalFlagSort.sort(integers); |
| 19 | + assertArrayEquals(integers, integersResult); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + /* |
| 24 | + 3 will be used as intended middle. |
| 25 | + Partitions on the result array: [ smaller than 3 , equal 3, greater than 3] |
| 26 | + */ |
| 27 | + void DNFSTestEven() { |
| 28 | + Integer[] integers = {8, 1, 3, 1, 4, 0}; |
| 29 | + Integer[] integersResult = {0, 1, 1, 3, 4, 8}; |
| 30 | + DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort(); |
| 31 | + dutchNationalFlagSort.sort(integers); |
| 32 | + assertArrayEquals(integers, integersResult); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + /* |
| 37 | + "b" will be used as intended middle. |
| 38 | + Partitions on the result array: [ smaller than b , equal b, greater than b] |
| 39 | + */ |
| 40 | + void DNFSTestEvenStrings() { |
| 41 | + String[] strings = {"a", "d", "b", "s", "e", "e"}; |
| 42 | + String[] stringsResult = {"a", "b", "s", "e", "e", "d"}; |
| 43 | + DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort(); |
| 44 | + dutchNationalFlagSort.sort(strings); |
| 45 | + assertArrayEquals(strings, stringsResult); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + /* |
| 50 | + "b" will be used as intended middle. |
| 51 | + Partitions on the result array: [ smaller than b , equal b, greater than b] |
| 52 | + */ |
| 53 | + void DNFSTestOddStrings() { |
| 54 | + String[] strings = {"a", "d", "b", "s", "e"}; |
| 55 | + String[] stringsResult = {"a", "b", "s", "e", "d"}; |
| 56 | + DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort(); |
| 57 | + dutchNationalFlagSort.sort(strings); |
| 58 | + assertArrayEquals(strings, stringsResult); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + /* |
| 63 | + 0 will be used as intended middle. |
| 64 | + Partitions on the result array: [ smaller than 0 , equal 0, greater than 0] |
| 65 | + */ |
| 66 | + void DNFSTestOddMidGiven() { |
| 67 | + Integer[] integers = {1, 3, 1, 4, 0}; |
| 68 | + Integer[] integersResult = {0, 1, 4, 3, 1}; |
| 69 | + DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort(); |
| 70 | + dutchNationalFlagSort.sort(integers, 0); |
| 71 | + assertArrayEquals(integers, integersResult); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + /* |
| 76 | + 4 will be used as intended middle. |
| 77 | + Partitions on the result array: [ smaller than 4 , equal 4, greater than 4] |
| 78 | + */ |
| 79 | + void DNFSTestEvenMidGiven() { |
| 80 | + Integer[] integers = {8, 1, 3, 1, 4, 0}; |
| 81 | + Integer[] integersResult = {0, 1, 3, 1, 4, 8}; |
| 82 | + DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort(); |
| 83 | + dutchNationalFlagSort.sort(integers, 4); |
| 84 | + assertArrayEquals(integers, integersResult); |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + /* |
| 89 | + "s" will be used as intended middle. |
| 90 | + Partitions on the result array: [ smaller than s , equal s, greater than s] |
| 91 | + */ |
| 92 | + void DNFSTestEvenStringsMidGiven() { |
| 93 | + String[] strings = {"a", "d", "b", "s", "e", "e"}; |
| 94 | + String[] stringsResult = {"a", "d", "b", "e", "e", "s"}; |
| 95 | + DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort(); |
| 96 | + dutchNationalFlagSort.sort(strings, "s"); |
| 97 | + assertArrayEquals(strings, stringsResult); |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + /* |
| 102 | + "e" will be used as intended middle. |
| 103 | + Partitions on the result array: [ smaller than e , equal e, greater than e] |
| 104 | + */ |
| 105 | + void DNFSTestOddStringsMidGiven() { |
| 106 | + String[] strings = {"a", "d", "b", "s", "e"}; |
| 107 | + String[] stringsResult = {"a", "d", "b", "e", "s"}; |
| 108 | + DutchNationalFlagSort dutchNationalFlagSort = new DutchNationalFlagSort(); |
| 109 | + dutchNationalFlagSort.sort(strings, "e"); |
| 110 | + assertArrayEquals(strings, stringsResult); |
| 111 | + } |
| 112 | +} |
0 commit comments