Skip to content

Commit

Permalink
Add some tests to problem 74
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrovgs committed Jan 28, 2015
1 parent 700378b commit 5bf9b54
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/test/java/com/github/pedrovgs/problem74/BubbleSortTest.java
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);
}
}

0 comments on commit 5bf9b54

Please sign in to comment.