forked from pedrovgs/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/test/java/com/github/pedrovgs/problem74/BubbleSortTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.github.pedrovgs.problem74; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
|
||
/** | ||
* @author Pedro Vicente Gómez Sánchez. | ||
*/ | ||
public class BubbleSortTest { | ||
|
||
private BubbleSort bubbleSort; | ||
|
||
@Before public void setUp() { | ||
bubbleSort = new BubbleSort(); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullArrays() { | ||
bubbleSort.sort(null); | ||
} | ||
|
||
@Test public void shouldNotModifyArrayIfIsAlreadySorted() { | ||
int[] input = { 1, 2, 3, 4 }; | ||
|
||
bubbleSort.sort(input); | ||
|
||
int[] expectedArray = { 1, 2, 3, 4 }; | ||
assertArrayEquals(expectedArray, input); | ||
} | ||
|
||
@Test public void shouldSortArrayWhenTheInputDataIsInDescendingOrder() { | ||
int[] input = { 4, 3, 2, 1 }; | ||
|
||
bubbleSort.sort(input); | ||
|
||
int[] expectedArray = { 1, 2, 3, 4 }; | ||
assertArrayEquals(expectedArray, input); | ||
} | ||
|
||
@Test public void shouldSortArrayPartiallySorted() { | ||
int[] input = { 1, 2, 4, 3 }; | ||
|
||
bubbleSort.sort(input); | ||
|
||
int[] expectedArray = { 1, 2, 3, 4 }; | ||
assertArrayEquals(expectedArray, input); | ||
} | ||
|
||
@Test public void shouldSortArray() { | ||
int[] input = { 3, 4, 1, 2 }; | ||
|
||
bubbleSort.sort(input); | ||
|
||
int[] expectedArray = { 1, 2, 3, 4 }; | ||
assertArrayEquals(expectedArray, input); | ||
} | ||
} |