Commit 4b784bab authored by edmundszagars's avatar edmundszagars
Browse files

Implementing tests for Bubble sort

parent bb0aa342
......@@ -4,8 +4,19 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.12.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
\ No newline at end of file
This diff is collapsed.
......@@ -7,7 +7,6 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
......
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import sorting_algorithms.BubbleSort;
import java.util.Arrays;
import java.util.Random;
public class BubbleSortTests {
private BubbleSort bs;
private double[] testArrayGiven = {1,6,2,3,4,8,9,0,2,3,4,7,6,5,4,1,3,34,56,78,90,12,43,57,88,99,64,12,43,19,86};
private double[] testArrayExpected = {0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 5.0, 6.0, 6.0, 7.0, 8.0, 9.0, 12.0, 12.0, 19.0, 34.0, 43.0, 43.0, 56.0, 57.0, 64.0, 78.0, 86.0, 88.0, 90.0, 99.0} ;
double[] largeArray;
@Before
public void setup(){
bs = new BubbleSort();
largeArray= generateLargeArray(10000);
}
@Test
public void sortTest(){
double[] result = bs.sort(testArrayGiven);
System.out.println(Arrays.toString(testArrayGiven));
Assert.assertArrayEquals(testArrayExpected,result,0.0);
}
@Test
public void executionTime(){
bs.sort(largeArray);
long resultTime = bs.getExecutionEndTime();
System.out.println(resultTime);
Assert.assertTrue(resultTime >= 0);
}
private double[] generateLargeArray(int size){
Random random = new Random();
double[] array = new double[size];
for (int i=0; i< size;i++){
array[i] = random.nextInt();
}
return array;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment