Skip to content

Commit

Permalink
clust4j junit4 -> junit5 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
samypr100 committed Jun 8, 2024
1 parent 5d53ed6 commit 3644cfa
Show file tree
Hide file tree
Showing 52 changed files with 2,015 additions and 1,484 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ dependencies {

testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.10.2'
testRuntimeOnly 'org.junit.platform:junit-platform-suite:1.10.2'
}

// Make sure every single dependency is modularized.
Expand Down
15 changes: 11 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<git.commit.maven.plugin.version>8.0.2</git.commit.maven.plugin.version>
<org.owasp.dependency-check-maven.plugin.version>9.0.10</org.owasp.dependency-check-maven.plugin.version>
<junit.jupiter.version>5.10.2</junit.jupiter.version>
<junit.jupiter.platform.version>1.10.2</junit.jupiter.platform.version>
<litfx.controls.version>0.1.3</litfx.controls.version>
<fxyz3d.version>0.6.0</fxyz3d.version>
<hansolo.charts.version>21.0.7</hansolo.charts.version>
Expand Down Expand Up @@ -97,14 +98,20 @@
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit.jupiter.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>${junit.jupiter.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@
opens edu.jhuapl.trinity.javafx.javafx3d.particle to java.base;
exports com.clust4j;
exports com.clust4j.algo;
exports com.clust4j.algo.pipeline;
exports com.clust4j.algo.preprocess;
exports com.clust4j.data;
exports com.clust4j.except;
exports com.clust4j.kernel;
exports com.clust4j.log;
exports com.clust4j.metrics.pairwise;
exports com.clust4j.metrics.scoring;
exports com.clust4j.optimize;
exports com.clust4j.sample;
exports com.clust4j.utils;
exports com.clust4j.utils.parallel;
exports edu.jhuapl.trinity;
exports edu.jhuapl.trinity.data;
exports edu.jhuapl.trinity.data.messages;
Expand Down
16 changes: 11 additions & 5 deletions src/test/java/com/clust4j/TestClust4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,28 @@
*******************************************************************************/
package com.clust4j;

import org.junit.jupiter.api.Test;

import java.io.IOException;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class TestClust4j {
final static Clust4j c4j = new Clust4j() {
private static final long serialVersionUID = 1L;
};

@Test(expected = NullPointerException.class)
@Test
public void testSaveNPE() throws IOException {
c4j.saveObject(null);
assertThrows(NullPointerException.class, () -> {
c4j.saveObject(null);
});
}

@Test(expected = NullPointerException.class)
@Test
public void testLoadNPE() throws IOException, ClassNotFoundException {
Clust4j.loadObject(null);
assertThrows(NullPointerException.class, () -> {
Clust4j.loadObject(null);
});
}
}
4 changes: 2 additions & 2 deletions src/test/java/com/clust4j/TestGlobals.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*******************************************************************************/
package com.clust4j;

import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TestGlobals {

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/clust4j/TestPublicAPI.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.clust4j;

import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TestPublicAPI {

Expand Down
29 changes: 11 additions & 18 deletions src/test/java/com/clust4j/TestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@
*******************************************************************************/
package com.clust4j;

import java.io.File;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.Random;

import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.junit.runner.JUnitCore;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

import com.clust4j.TestClust4j;
import com.clust4j.TestGlobals;
import com.clust4j.algo.AffinityPropagationTests;
import com.clust4j.algo.BoruvkaTests;
import com.clust4j.algo.ClustTests;
Expand All @@ -40,8 +28,8 @@
import com.clust4j.algo.NearestCentroidTests;
import com.clust4j.algo.NearestNeighborsTests;
import com.clust4j.algo.ParallelTaskTests;
import com.clust4j.algo.TestLabelEncoder;
import com.clust4j.algo.RadiusNeighborsTests;
import com.clust4j.algo.TestLabelEncoder;
import com.clust4j.algo.pipeline.PipelineTest;
import com.clust4j.algo.preprocess.ImputationTests;
import com.clust4j.algo.preprocess.PreProcessorTests;
Expand Down Expand Up @@ -69,9 +57,17 @@
import com.clust4j.utils.TestUtils;
import com.clust4j.utils.VectorTests;
import com.clust4j.utils.parallel.ParallelTests;
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

import java.io.File;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.Random;

@RunWith(Suite.class)
@Suite.SuiteClasses({
@Suite
@SelectClasses({
AffinityPropagationTests.class,
BootstrapTest.class,
BoruvkaTests.class,
Expand Down Expand Up @@ -169,7 +165,4 @@ public static Array2DRowRealMatrix getRandom(final int rows, final int cols) {
return new Array2DRowRealMatrix(data, false);
}

public static void main(String[] args) throws Exception {
JUnitCore.main("com.clust4j.TestSuite");
}
}
29 changes: 14 additions & 15 deletions src/test/java/com/clust4j/algo/AffinityPropagationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,8 @@
*******************************************************************************/
package com.clust4j.algo;

import static org.junit.Assert.*;
import static com.clust4j.TestSuite.getRandom;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Random;

import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.apache.commons.math3.util.Precision;
import org.junit.Test;

import com.clust4j.GlobalState;
import com.clust4j.TestSuite;
import com.clust4j.algo.AffinityPropagationParameters;
import com.clust4j.data.DataSet;
import com.clust4j.except.ModelNotFitException;
import com.clust4j.kernel.GaussianKernel;
Expand All @@ -42,8 +28,21 @@
import com.clust4j.metrics.pairwise.Similarity;
import com.clust4j.metrics.pairwise.SimilarityMetric;
import com.clust4j.utils.MatUtils;
import com.clust4j.utils.VecUtils;
import com.clust4j.utils.Series.Inequality;
import com.clust4j.utils.VecUtils;
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.apache.commons.math3.util.Precision;
import org.junit.jupiter.api.Test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Random;

import static com.clust4j.TestSuite.getRandom;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class AffinityPropagationTests implements ClusterTest, ClassifierTest, ConvergeableTest, BaseModelTest {
final DataSet irisds = TestSuite.IRIS_DATASET.copy();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/clust4j/algo/BaseModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*******************************************************************************/
package com.clust4j.algo;

import java.io.IOException;
import org.junit.jupiter.api.Test;

import org.junit.Test;
import java.io.IOException;

public interface BaseModelTest {
@Test
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/clust4j/algo/BoruvkaTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*******************************************************************************/
package com.clust4j.algo;

import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class BoruvkaTests {

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/clust4j/algo/ClassifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*******************************************************************************/
package com.clust4j.algo;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public interface ClassifierTest {
@Test
Expand Down
56 changes: 28 additions & 28 deletions src/test/java/com/clust4j/algo/ClustTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,21 @@
*******************************************************************************/
package com.clust4j.algo;

import static org.junit.Assert.*;
import static com.clust4j.TestSuite.getRandom;

import java.util.Random;

import org.apache.commons.math3.linear.AbstractRealMatrix;
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.junit.Test;

import com.clust4j.TestSuite;
import com.clust4j.algo.BaseClustererParameters;
import com.clust4j.algo.DBSCAN;
import com.clust4j.algo.KMeansParameters;
import com.clust4j.algo.preprocess.StandardScaler;
import com.clust4j.except.NaNException;
import com.clust4j.log.Log.Tag.Algo;
import com.clust4j.metrics.pairwise.GeometricallySeparable;
import com.clust4j.metrics.pairwise.Similarity;
import com.clust4j.utils.MatrixFormatter;
import org.apache.commons.math3.linear.AbstractRealMatrix;
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.junit.jupiter.api.Test;

import java.util.Random;

import static com.clust4j.TestSuite.getRandom;
import static org.junit.jupiter.api.Assertions.*;

public class ClustTests {

Expand Down Expand Up @@ -69,16 +65,18 @@ public void mutabilityTest1() {
}


@Test(expected = NaNException.class)
@Test
public void testNanException() {
final double[][] train_array = new double[][]{
new double[]{0.0, 1.0, 2.0, 3.0},
new double[]{1.0, 2.3, Double.NaN, 4.0},
new double[]{9.06, 12.6, 6.5, 9.0}
};

final Array2DRowRealMatrix mat = new Array2DRowRealMatrix(train_array);
new NearestNeighbors(mat, 1);
assertThrows(NaNException.class, () -> {
final double[][] train_array = new double[][]{
new double[]{0.0, 1.0, 2.0, 3.0},
new double[]{1.0, 2.3, Double.NaN, 4.0},
new double[]{9.06, 12.6, 6.5, 9.0}
};

final Array2DRowRealMatrix mat = new Array2DRowRealMatrix(train_array);
new NearestNeighbors(mat, 1);
});
}

@Test
Expand Down Expand Up @@ -126,14 +124,16 @@ protected Object[] getModelFitSummaryHeaders() {
assertTrue(ref == a.data);
}

@Test(expected = NaNException.class)
@Test
public void ensureNanException() {
double[][] d = new double[][]{
new double[]{1, 2, 3},
new double[]{Double.NaN, 0, 1}
};

new KMeans(toMat(d), 2);
assertThrows(NaNException.class, () -> {
double[][] d = new double[][]{
new double[]{1, 2, 3},
new double[]{Double.NaN, 0, 1}
};

new KMeans(toMat(d), 2);
});
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/clust4j/algo/ClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*******************************************************************************/
package com.clust4j.algo;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public interface ClusterTest {
@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/clust4j/algo/ConvergeableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*******************************************************************************/
package com.clust4j.algo;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public interface ConvergeableTest {
@Test
Expand Down
Loading

0 comments on commit 3644cfa

Please sign in to comment.