Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bubblesort): add tests #13

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/edu/ifrs/vvs/BubbleSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class BubbleSort {
*/
public void sort(int... v) {
// for utilizado para controlar a quantidade de vezes que o vetor será ordenado.
if (v != null) {
for (int i = 0; i < v.length - 1; i++) {
// for utilizado para ordenar o vetor.
for (int j = 0; j < v.length - 1 - i; j++) {
Expand All @@ -49,6 +50,7 @@ public void sort(int... v) {
}
}
}
}
}

/**
Expand Down
35 changes: 0 additions & 35 deletions src/test/java/edu/ifrs/vvs/AppTest.java

This file was deleted.

56 changes: 56 additions & 0 deletions src/test/java/edu/ifrs/vvs/BubbleSortTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package edu.ifrs.vvs;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class AppTest {

BubbleSort bubbleSort = new BubbleSort();

@Test
void testSortPositiveArray() {
int[] testArray = { 6, 3, 7, 1, 9, 5 };
int [] expectedArray = { 1, 3, 5, 6, 7, 9 };
bubbleSort.sort(testArray);

assertArrayEquals(testArray, expectedArray);
}

@Test
void testSortNegativeArray() {
int[] testArray = { -6, -3, -7, -1, -9, -5 };
int [] expectedArray = { -9, -7, -6, -5, -3, -1 };
bubbleSort.sort(testArray);

assertArrayEquals(testArray, expectedArray);
}

@Test
void testSortMixedArray() {
int[] testArray = { 1, -5, 7, -4, -2, 10, 20, -32 };
int [] expectedArray = { -32, -5, -4, -2, 1, 7, 10, 20 };
bubbleSort.sort(testArray);

assertArrayEquals(testArray, expectedArray);
}

@Test
void testEmptyArray() {
int[] testArray = {};
int [] expectedArray = {};
bubbleSort.sort(testArray);

assertArrayEquals(testArray, expectedArray);
}

@Test
void testNullArray() {
int[] testArray = null;
int [] expectedArray = null;
bubbleSort.sort(testArray);

assertArrayEquals(testArray, expectedArray);
}

}