You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by pi...@apache.org on 2024/09/06 12:42:09 UTC
(incubator-kie-drools) branch main updated: Assertj cleanup. Junit5 migration (#6070)
This is an automated email from the ASF dual-hosted git repository.
pibizza pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-drools.git
The following commit(s) were added to refs/heads/main by this push:
new 6be58bcdcd Assertj cleanup. Junit5 migration (#6070)
6be58bcdcd is described below
commit 6be58bcdcda1b15a64268d8e3d3d4f60514f35d0
Author: Paolo Bizzarri <pi...@gmail.com>
AuthorDate: Fri Sep 6 14:42:05 2024 +0200
Assertj cleanup. Junit5 migration (#6070)
---
drools-beliefs/pom.xml | 6 +-
.../drools/beliefs/bayes/BayesAbsorbtionTest.java | 15 ++--
.../drools/beliefs/bayes/BayesProjectionTest.java | 12 +--
.../org/drools/beliefs/bayes/GlobalUpdateTest.java | 62 +++++++--------
.../java/org/drools/beliefs/bayes/GraphTest.java | 14 +---
.../beliefs/bayes/JunctionTreeBuilderTest.java | 87 +++++++++++-----------
.../org/drools/beliefs/bayes/JunctionTreeTest.java | 38 +++-------
.../org/drools/beliefs/bayes/LikelyhoodTest.java | 27 -------
.../org/drools/beliefs/bayes/MarginalizerTest.java | 2 +-
.../org/drools/beliefs/bayes/PassMessageTest.java | 10 +--
.../beliefs/bayes/example/EarthQuakeTest.java | 69 ++++++++---------
.../drools/beliefs/bayes/example/SprinkerTest.java | 76 +++++++++----------
.../beliefs/bayes/integration/AssemblerTest.java | 2 +-
.../bayes/integration/BayesBeliefSystemTest.java | 2 +-
.../bayes/integration/BayesRuntimeTest.java | 2 +-
.../beliefs/bayes/integration/ParserTest.java | 50 ++++++-------
.../beliefs/bayes/integration/WeaverTest.java | 2 +-
17 files changed, 202 insertions(+), 274 deletions(-)
diff --git a/drools-beliefs/pom.xml b/drools-beliefs/pom.xml
index d3e31fc78f..cfd1cbaefb 100644
--- a/drools-beliefs/pom.xml
+++ b/drools-beliefs/pom.xml
@@ -95,10 +95,10 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
<scope>test</scope>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/BayesAbsorbtionTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/BayesAbsorbtionTest.java
index 07c5a481dd..e2a8cd601f 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/BayesAbsorbtionTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/BayesAbsorbtionTest.java
@@ -20,15 +20,16 @@ package org.drools.beliefs.bayes;
import org.drools.beliefs.graph.Graph;
import org.drools.beliefs.graph.GraphNode;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.drools.beliefs.bayes.GraphTest.addNode;
import static org.drools.beliefs.bayes.GraphTest.bitSet;
-import static org.drools.beliefs.bayes.JunctionTreeTest.assertArray;
import static org.drools.beliefs.bayes.JunctionTreeTest.scaleDouble;
+
public class BayesAbsorbtionTest {
@Test
@@ -37,7 +38,7 @@ public class BayesAbsorbtionTest {
double[] oldD = new double[] { 2, 4, 1 };
double[] r = BayesAbsorption.dividePotentials(newD, oldD);
- assertArray(new double[]{5, 2, 4}, scaleDouble(3, r));
+ assertThat(scaleDouble(3, r)).containsExactly(5, 2, 4);
}
@Test
@@ -46,7 +47,7 @@ public class BayesAbsorbtionTest {
double[] oldD = new double[] { 0.1, 0.2, 0.3, 0.4 };
double[] r = BayesAbsorption.dividePotentials(newD, oldD);
- assertArray(new double[]{5.0, 5.0, 5.0, 5.0}, scaleDouble(3, r));
+ assertThat(scaleDouble(3, r)).containsExactly(5.0, 5.0, 5.0, 5.0);
}
@Test
@@ -94,7 +95,7 @@ public class BayesAbsorbtionTest {
BayesAbsorption p = new BayesAbsorption(sepVarPos, oldSepPotentials, sep.getPotentials(), sepVarMultipliers, vars, node1.getPotentials());
p.absorb();
- assertArray(new double[]{0.035, 0.135, 0.3, 0.529}, scaleDouble(3, node1.getPotentials()));
+ assertThat(scaleDouble(3, node1.getPotentials())).containsExactly(0.035, 0.135, 0.3, 0.529);
}
@Test
@@ -145,7 +146,7 @@ public class BayesAbsorbtionTest {
BayesAbsorption p = new BayesAbsorption(sepVarPos, oldSepPotentials, sep.getPotentials(), sepVarMultipliers, vars, node1.getPotentials());
p.absorb();
- assertArray(new double[]{ 0.01, 0.019, 0.055, 0.073, 0.137, 0.163, 0.254, 0.289 }, scaleDouble(3, node1.getPotentials()));
+ assertThat(scaleDouble(3, node1.getPotentials())).containsExactly(0.01, 0.019, 0.055, 0.073, 0.137, 0.163, 0.254, 0.289);
}
@Test
@@ -197,6 +198,6 @@ public class BayesAbsorbtionTest {
BayesAbsorption p = new BayesAbsorption(sepVarPos, oldSepPotentials, sep.getPotentials(), sepVarMultipliers, vars, node1.getPotentials());
p.absorb();
- assertArray(new double[]{0.01, 0.038, 0.028, 0.075, 0.139, 0.222, 0.194, 0.295}, scaleDouble(3, node1.getPotentials()));
+ assertThat(scaleDouble(3, node1.getPotentials())).containsExactly(0.01, 0.038, 0.028, 0.075, 0.139, 0.222, 0.194, 0.295);
}
}
\ No newline at end of file
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/BayesProjectionTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/BayesProjectionTest.java
index bb6aabcace..2d72957bb9 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/BayesProjectionTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/BayesProjectionTest.java
@@ -20,11 +20,11 @@ package org.drools.beliefs.bayes;
import org.drools.beliefs.graph.Graph;
import org.drools.beliefs.graph.GraphNode;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.drools.beliefs.bayes.GraphTest.addNode;
import static org.drools.beliefs.bayes.GraphTest.bitSet;
-import static org.drools.beliefs.bayes.JunctionTreeTest.assertArray;
import static org.drools.beliefs.bayes.JunctionTreeTest.scaleDouble;
public class BayesProjectionTest {
@@ -66,7 +66,7 @@ public class BayesProjectionTest {
BayesProjection p = new BayesProjection(vars, node1.getPotentials(), sepVarPos, sepVarMultipliers, projectedSepPotentials);
p.project();
- assertArray(new double[]{0.1, 0.2, 0.3, 0.4}, scaleDouble(3, projectedSepPotentials));
+ assertThat(scaleDouble(3, projectedSepPotentials)).containsExactly(0.1, 0.2, 0.3, 0.4);
}
@Test
@@ -110,7 +110,7 @@ public class BayesProjectionTest {
p.project();
// remember it's been normalized, from 0.3, 0.7, 1.1, 1.5
- assertArray(new double[]{0.083, 0.194, 0.306, 0.417}, scaleDouble(3, projectedSepPotentials));
+ assertThat(scaleDouble(3, projectedSepPotentials)).containsExactly(0.083, 0.194, 0.306, 0.417);
}
@Test
@@ -156,7 +156,7 @@ public class BayesProjectionTest {
p.project();
// remember it's been normalized, from 0.4, 0.6, 1.2, 1.4
- assertArray(new double[]{0.111, 0.167, 0.333, 0.389}, scaleDouble(3, projectedSepPotentials));
+ assertThat(scaleDouble(3, projectedSepPotentials)).containsExactly(0.111, 0.167, 0.333, 0.389);
}
@Test
@@ -202,7 +202,7 @@ public class BayesProjectionTest {
p.project();
// remember it's been normalized, from 0.6 0.8 1.0 1.2
- assertArray(new double[]{0.167, 0.222, 0.278, 0.333}, scaleDouble(3, projectedSepPotentials));
+ assertThat(scaleDouble(3, projectedSepPotentials)).containsExactly(0.167, 0.222, 0.278, 0.333);
}
}
\ No newline at end of file
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/GlobalUpdateTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/GlobalUpdateTest.java
index 3955b007ec..a60859989e 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/GlobalUpdateTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/GlobalUpdateTest.java
@@ -20,11 +20,10 @@ package org.drools.beliefs.bayes;
import org.drools.beliefs.graph.Graph;
import org.drools.beliefs.graph.GraphNode;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@@ -63,7 +62,7 @@ public class GlobalUpdateTest {
final List<String> messageResults = new ArrayList<String>();
final List<String> globalUpdateResults = new ArrayList<String>();
- @Before
+ @BeforeEach
public void startUp() {
int i = 0;
List<JunctionTreeSeparator> list = new ArrayList<JunctionTreeSeparator>();
@@ -111,92 +110,92 @@ public class GlobalUpdateTest {
@Test
public void testCollectFromRootClique() {
bayesInstance.collectEvidence(n0);
- assertThat(messageResults).isEqualTo(asList("3:2", "4:2", "2:1", "7:6", "8:6", "6:5", "5:1", "1:0"));
+ assertThat(messageResults).containsExactly("3:2", "4:2", "2:1", "7:6", "8:6", "6:5", "5:1", "1:0");
}
@Test
public void testCollectFromMidTipClique() {
bayesInstance.collectEvidence(n4);
- assertThat(messageResults).isEqualTo(asList("0:1", "7:6", "8:6", "6:5", "5:1", "1:2", "3:2", "2:4"));
+ assertThat(messageResults).containsExactly("0:1", "7:6", "8:6", "6:5", "5:1", "1:2", "3:2", "2:4");
}
@Test
public void testCollectFromEndTipClique() {
bayesInstance.collectEvidence(n7);
- assertThat(messageResults).isEqualTo(asList("0:1", "3:2", "4:2", "2:1", "1:5", "5:6", "8:6", "6:7"));
+ assertThat(messageResults).containsExactly("0:1", "3:2", "4:2", "2:1", "1:5", "5:6", "8:6", "6:7");
}
@Test
public void testCollectFromMidClique() {
bayesInstance.collectEvidence(n5);
- assertThat(messageResults).isEqualTo(asList("0:1", "3:2", "4:2", "2:1", "1:5", "7:6", "8:6", "6:5"));
+ assertThat(messageResults).containsExactly("0:1", "3:2", "4:2", "2:1", "1:5", "7:6", "8:6", "6:5");
}
@Test
public void testDistributeFromRootClique() {
bayesInstance.distributeEvidence(n0);
- assertThat(messageResults).isEqualTo(asList("0:1", "1:2", "2:3", "2:4", "1:5", "5:6", "6:7", "6:8"));
+ assertThat(messageResults).containsExactly("0:1", "1:2", "2:3", "2:4", "1:5", "5:6", "6:7", "6:8");
}
@Test
public void testDistributeFromMidTipClique() {
bayesInstance.distributeEvidence(n4);
- assertThat(messageResults).isEqualTo(asList("4:2", "2:1", "1:0", "1:5", "5:6", "6:7", "6:8", "2:3"));
+ assertThat(messageResults).containsExactly("4:2", "2:1", "1:0", "1:5", "5:6", "6:7", "6:8", "2:3");
}
@Test
public void testDistributeFromEndTipClique() {
bayesInstance.distributeEvidence(n7);
- assertThat(messageResults).isEqualTo(asList("7:6", "6:5", "5:1", "1:0", "1:2", "2:3", "2:4", "6:8"));
+ assertThat(messageResults).containsExactly("7:6", "6:5", "5:1", "1:0", "1:2", "2:3", "2:4", "6:8");
}
@Test
public void testDistributeFromMidClique() {
bayesInstance.distributeEvidence(n5);
- assertThat(messageResults).isEqualTo(asList("5:1", "1:0", "1:2", "2:3", "2:4", "5:6", "6:7", "6:8"));
+ assertThat(messageResults).containsExactly("5:1", "1:0", "1:2", "2:3", "2:4", "5:6", "6:7", "6:8");
}
@Test
public void testGlobalUpdateFromRootClique() {
bayesInstance.globalUpdate(n0);
- assertThat(messageResults).isEqualTo(asList("3:2", "4:2", "2:1", "7:6", "8:6", "6:5", "5:1", "1:0", //n0
+ assertThat(messageResults).containsExactly("3:2", "4:2", "2:1", "7:6", "8:6", "6:5", "5:1", "1:0", //n0
"0:1", "1:2", "2:3", "2:4", "1:5", "5:6", "6:7", "6:8" //n0
- ));
- assertThat(globalUpdateResults).isEqualTo(asList("0"));
+ );
+ assertThat(globalUpdateResults).containsExactly("0");
}
@Test
public void testGlobalUpdateFromMidTipClique() {
bayesInstance.globalUpdate(n4);
- assertThat(messageResults).isEqualTo(asList("0:1", "7:6", "8:6", "6:5", "5:1", "1:2", "3:2", "2:4", //n4
+ assertThat(messageResults).containsExactly("0:1", "7:6", "8:6", "6:5", "5:1", "1:2", "3:2", "2:4", //n4
"4:2", "2:1", "1:0", "1:5", "5:6", "6:7", "6:8", "2:3" //n4
- ));
- assertThat(globalUpdateResults).isEqualTo(asList("4"));
+ );
+ assertThat(globalUpdateResults).containsExactly("4");
}
@Test
public void testGlobalUpdateFromEndTipClique() {
bayesInstance.globalUpdate(n7);
- assertThat(messageResults).isEqualTo(asList("0:1", "3:2", "4:2", "2:1", "1:5", "5:6", "8:6", "6:7", //n7
+ assertThat(messageResults).containsExactly("0:1", "3:2", "4:2", "2:1", "1:5", "5:6", "8:6", "6:7", //n7
"7:6", "6:5", "5:1", "1:0", "1:2", "2:3", "2:4", "6:8" //n7
- ));
- assertThat(globalUpdateResults).isEqualTo(asList("7"));
+ );
+ assertThat(globalUpdateResults).containsExactly("7");
}
@Test
public void testGlobalUpdateFromMidClique() {
bayesInstance.globalUpdate(n5);
- assertThat(messageResults).isEqualTo(asList("0:1", "3:2", "4:2", "2:1", "1:5", "7:6", "8:6", "6:5", //n5
+ assertThat(messageResults).containsExactly("0:1", "3:2", "4:2", "2:1", "1:5", "7:6", "8:6", "6:5", //n5
"5:1", "1:0", "1:2", "2:3", "2:4", "5:6", "6:7", "6:8" //n5
- ));
- assertThat(globalUpdateResults).isEqualTo(asList("5"));
+ );
+ assertThat(globalUpdateResults).containsExactly("5");
}
@Test
public void testDistributeFromGlobalUpdate() {
bayesInstance.globalUpdate();
- assertThat(messageResults).isEqualTo(asList("3:2", "4:2", "2:1", "7:6", "8:6", "6:5", "5:1", "1:0", //n0
+ assertThat(messageResults).containsExactly("3:2", "4:2", "2:1", "7:6", "8:6", "6:5", "5:1", "1:0", //n0
"0:1", "1:2", "2:3", "2:4", "1:5", "5:6", "6:7", "6:8" //n0
// "0:1", "3:2", "4:2", "2:1", "7:6", "8:6", "6:5", "5:1", //n1
// "1:0", "1:2", "2:3", "2:4", "1:5", "5:6", "6:7", "6:8", //n1
@@ -214,18 +213,9 @@ public class GlobalUpdateTest {
// "7:6", "6:5", "5:1", "1:0", "1:2", "2:3", "2:4", "6:8", //n7
// "0:1", "3:2", "4:2", "2:1", "1:5", "5:6", "7:6", "6:8", //n8
// "8:6", "6:5", "5:1", "1:0", "1:2", "2:3", "2:4", "6:7" //n8
- ));
+ );
-// assertEquals( asList( "0", "1", "2", "3", "4", "5", "6", "7", "8"), globalUpdateResults);
- assertThat(globalUpdateResults).isEqualTo(asList("0"));
- }
-
- public void testGlobalUpdate() {
- bayesInstance.globalUpdate();
- }
-
- public List asList(String... items) {
- return Arrays.asList(items);
+ assertThat(globalUpdateResults).containsExactly("0");
}
public void connectChildren(Graph<BayesVariable> graph, JunctionTreeClique parent, List list, JunctionTreeClique... children) {
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/GraphTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/GraphTest.java
index 640b78a32a..f844aec965 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/GraphTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/GraphTest.java
@@ -23,9 +23,7 @@ import org.drools.beliefs.graph.GraphNode;
import org.drools.beliefs.graph.impl.EdgeImpl;
import org.drools.util.bitmask.OpenBitSet;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@@ -56,11 +54,11 @@ public class GraphTest {
int id = ints[0];
Collection<Integer> adjVert = JunctionTreeBuilder.getAdjacentVertices(adjMatrix, id);
- assertThat(adjVert.size()).isEqualTo(ints.length - 1);
+ assertThat(adjVert).hasSize(ints.length - 1);
for ( int i = 1; i < ints.length; i++ ) {
assertThat(adjMatrix[id][ints[i]]).as("link was not true " + id + ", " + i).isTrue();
assertThat(adjMatrix[ints[i]][id]).as("link was not true " + i + ", " + id).isTrue();
- assertThat(adjVert.contains(ints[i])).as("does not contain " + ints[i]).isTrue();
+ assertThat(adjVert).as("does not contain " + ints[i]).contains(ints[i]);
}
return false;
@@ -75,14 +73,6 @@ public class GraphTest {
- public static List asList(int[] array) {
- List list = new ArrayList(array.length);
- for (int i = 0; i < array.length; i++) {
- list.add(array[i]);
- }
- return list;
- }
-
public static OpenBitSet bitSet(String s) {
OpenBitSet bitSet = new OpenBitSet( );
bitSet.setBits(new long[] { Long.valueOf(s, 2) });
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/JunctionTreeBuilderTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/JunctionTreeBuilderTest.java
index 56fcb2675a..a284033836 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/JunctionTreeBuilderTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/JunctionTreeBuilderTest.java
@@ -21,10 +21,9 @@ package org.drools.beliefs.bayes;
import org.drools.beliefs.graph.Graph;
import org.drools.beliefs.graph.GraphNode;
import org.drools.util.bitmask.OpenBitSet;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -187,8 +186,8 @@ public class JunctionTreeBuilderTest {
boolean[][] clonedAdjMatrix = JunctionTreeBuilder.cloneAdjacencyMarix(jtBuilder.getAdjacencyMatrix());
jtBuilder.createClique(dX1.getId(), clonedAdjMatrix, vertices, adjList );
- assertThat(vertices.size()).isEqualTo(3);
- assertThat(vertices.containsAll(Arrays.asList(2, 3, 4))).isTrue();
+ assertThat(vertices).hasSize(3);
+ assertThat(vertices).containsExactly(2, 3, 4);
assertLinkedNode(jtBuilder, 1, 2, 3, 4);
assertLinkedNode(jtBuilder, 2, 1, 3, 4);
@@ -204,18 +203,18 @@ public class JunctionTreeBuilderTest {
List<OpenBitSet> cliques = new ArrayList<OpenBitSet>();
OpenBitSet OpenBitSet1 = bitSet("00011110");
jtBuilder.updateCliques(cliques, OpenBitSet1);
- assertThat(cliques.size()).isEqualTo(1);
+ assertThat(cliques).hasSize(1);
// ignore subset
OpenBitSet OpenBitSet2 = bitSet("00000110");
jtBuilder.updateCliques(cliques, OpenBitSet2);
- assertThat(cliques.size()).isEqualTo(1);
+ assertThat(cliques).hasSize(1);
assertThat(cliques.get(0)).isEqualTo(OpenBitSet1);
// add overlapping, as not a pure subset
OpenBitSet OpenBitSet3 = bitSet("01000110");
jtBuilder.updateCliques(cliques, OpenBitSet3);
- assertThat(cliques.size()).isEqualTo(2);
+ assertThat(cliques).hasSize(2);
assertThat(cliques.get(0)).isEqualTo(OpenBitSet1);
assertThat(cliques.get(1)).isEqualTo(OpenBitSet3);
}
@@ -288,7 +287,7 @@ public class JunctionTreeBuilderTest {
assertThat(id).isEqualTo(8);
assertThat(v.getNewEdgesRequired()).isEqualTo(6);
- assertThat(p.size()).isEqualTo(0);
+ assertThat(p).isEmpty();
}
@Test
@@ -363,7 +362,7 @@ public class JunctionTreeBuilderTest {
assertThat(id).isEqualTo(5);
assertThat(v.getWeightRequired()).isEqualTo(81);
- assertThat(p.size()).isEqualTo(0);
+ assertThat(p).isEmpty();
}
@Test
@@ -443,8 +442,8 @@ public class JunctionTreeBuilderTest {
Set<Integer> verticesToUpdate = new HashSet<Integer>();
boolean[] adjList = clonedAdjMatrix[ id ];
jtBuilder.createClique(5, clonedAdjMatrix, verticesToUpdate, adjList);
- assertThat(verticesToUpdate.size()).isEqualTo(4);
- assertThat(verticesToUpdate.containsAll(Arrays.asList(1, 3, 6))).isTrue();
+ assertThat(verticesToUpdate).hasSize(4);
+ assertThat(verticesToUpdate).contains(1, 3, 6);
jtBuilder.eliminateVertex(p, elmVertMap, clonedAdjMatrix, adjList, verticesToUpdate, v );
// assert all new edges
@@ -477,8 +476,8 @@ public class JunctionTreeBuilderTest {
verticesToUpdate = new HashSet<Integer>();
adjList = clonedAdjMatrix[ id ];
jtBuilder.createClique(4, clonedAdjMatrix, verticesToUpdate, adjList);
- assertThat(verticesToUpdate.size()).isEqualTo(3);
- assertThat(verticesToUpdate.containsAll(Arrays.asList(1, 2, 6))).isTrue(); // don't forget 3 and 5 were already eliminated
+ assertThat(verticesToUpdate).hasSize(3);
+ assertThat(verticesToUpdate).containsExactly(1, 2, 6); // don't forget 3 and 5 were already eliminated
jtBuilder.eliminateVertex(p, elmVertMap, clonedAdjMatrix, adjList, verticesToUpdate, v );
// assert all new edges
@@ -518,7 +517,7 @@ public class JunctionTreeBuilderTest {
jtBuilder.createClique(6, clonedAdjMatrix, verticesToUpdate, adjList);
jtBuilder.eliminateVertex(p, elmVertMap, clonedAdjMatrix, adjList, verticesToUpdate, v );
- assertThat(p.size()).isEqualTo(0);
+ assertThat(p).isEmpty();
}
@Test
@@ -611,11 +610,11 @@ public class JunctionTreeBuilderTest {
assertLinkedVertex(jtBuilder.getAdjacencyMatrix(), 5, 2, 3, 6);
assertLinkedVertex(jtBuilder.getAdjacencyMatrix(), 6, 2, 5);
- assertThat(cliques.size()).isEqualTo(5); // 5th is 0, which is just a dummy V to get numbers aligned
- assertThat(cliques.contains(bitSet("1110"))).isTrue(); // x1, x2, x3 //a, b, c
- assertThat(cliques.contains(bitSet("10100"))).isTrue(); // x2, x4
- assertThat(cliques.contains(bitSet("1100100"))).isTrue(); // x2, x5, x6
- assertThat(cliques.contains(bitSet("101100"))).isTrue(); // x2, x3, x5
+ assertThat(cliques).hasSize(5); // 5th is 0, which is just a dummy V to get numbers aligned
+ assertThat(cliques).contains(bitSet("1110")); // x1, x2, x3 //a, b, c
+ assertThat(cliques).contains(bitSet("10100")); // x2, x4
+ assertThat(cliques).contains(bitSet("1100100")); // x2, x5, x6
+ assertThat(cliques).contains(bitSet("101100")); // x2, x3, x5
}
@Test
@@ -805,7 +804,7 @@ public class JunctionTreeBuilderTest {
assertThat(jtNode.getBitSet()).isEqualTo(OpenBitSet1);
- assertThat(jtNode.getChildren().size()).isEqualTo(1);
+ assertThat(jtNode.getChildren()).hasSize(1);
JunctionTreeSeparator sep = jtNode.getChildren().get(0);
assertThat(sep.getParent().getBitSet()).isEqualTo(OpenBitSet1);
assertThat(sep.getChild().getBitSet()).isEqualTo(OpenBitSet2);
@@ -813,7 +812,7 @@ public class JunctionTreeBuilderTest {
jtNode = sep.getChild();
assertThat(jtNode.getBitSet()).isEqualTo(OpenBitSet2);
- assertThat(jtNode.getChildren().size()).isEqualTo(1);
+ assertThat(jtNode.getChildren()).hasSize(1);
sep = jtNode.getChildren().get(0);
assertThat(sep.getParent().getBitSet()).isEqualTo(OpenBitSet2);
assertThat(sep.getChild().getBitSet()).isEqualTo(OpenBitSet3);
@@ -853,16 +852,16 @@ public class JunctionTreeBuilderTest {
assertThat(jtNode.getBitSet()).isEqualTo(OpenBitSet1);
- assertThat(jtNode.getChildren().size()).isEqualTo(2);
+ assertThat(jtNode.getChildren()).hasSize(2);
JunctionTreeSeparator sep = jtNode.getChildren().get(0);
assertThat(sep.getParent().getBitSet()).isEqualTo(OpenBitSet1);
assertThat(sep.getChild().getBitSet()).isEqualTo(OpenBitSet2);
- assertThat(sep.getChild().getChildren().size()).isEqualTo(0);
+ assertThat(sep.getChild().getChildren()).isEmpty();
sep = jtNode.getChildren().get(1);
assertThat(sep.getParent().getBitSet()).isEqualTo(OpenBitSet1);
assertThat(sep.getChild().getBitSet()).isEqualTo(OpenBitSet3);
- assertThat(sep.getChild().getChildren().size()).isEqualTo(0);
+ assertThat(sep.getChild().getChildren()).isEmpty();
}
@@ -904,26 +903,26 @@ public class JunctionTreeBuilderTest {
assertThat(root.getBitSet()).isEqualTo(OpenBitSet1);
- assertThat(root.getChildren().size()).isEqualTo(2);
+ assertThat(root.getChildren()).hasSize(2);
JunctionTreeSeparator sep = root.getChildren().get(0);
assertThat(sep.getParent().getBitSet()).isEqualTo(OpenBitSet1);
assertThat(sep.getChild().getBitSet()).isEqualTo(OpenBitSet2);
- assertThat(sep.getChild().getChildren().size()).isEqualTo(1);
+ assertThat(sep.getChild().getChildren()).hasSize(1);
jtNode = sep.getChild();
assertThat(jtNode.getBitSet()).isEqualTo(OpenBitSet2);
- assertThat(jtNode.getChildren().size()).isEqualTo(1);
+ assertThat(jtNode.getChildren()).hasSize(1);
sep = jtNode.getChildren().get(0);
assertThat(sep.getParent().getBitSet()).isEqualTo(OpenBitSet2);
assertThat(sep.getChild().getBitSet()).isEqualTo(OpenBitSet3);
assertThat(sep.getBitSet()).isEqualTo(intersect2And3);
- assertThat(sep.getChild().getChildren().size()).isEqualTo(0);
+ assertThat(sep.getChild().getChildren()).isEmpty();
sep = root.getChildren().get(1);
assertThat(sep.getParent().getBitSet()).isEqualTo(OpenBitSet1);
assertThat(sep.getChild().getBitSet()).isEqualTo(OpenBitSet4);
assertThat(sep.getBitSet()).isEqualTo(intersect1And4);
- assertThat(sep.getChild().getChildren().size()).isEqualTo(0);
+ assertThat(sep.getChild().getChildren()).isEmpty();
}
@Test
@@ -966,26 +965,26 @@ public class JunctionTreeBuilderTest {
JunctionTreeClique root = jtNode;
assertThat(root.getBitSet()).isEqualTo(OpenBitSet1);
- assertThat(root.getChildren().size()).isEqualTo(2);
+ assertThat(root.getChildren()).hasSize(2);
JunctionTreeSeparator sep = root.getChildren().get(0);
assertThat(sep.getParent().getBitSet()).isEqualTo(OpenBitSet1);
assertThat(sep.getChild().getBitSet()).isEqualTo(OpenBitSet2);
- assertThat(sep.getChild().getChildren().size()).isEqualTo(0);
+ assertThat(sep.getChild().getChildren()).isEmpty();
sep = root.getChildren().get(1);
assertThat(sep.getParent().getBitSet()).isEqualTo(OpenBitSet1);
assertThat(sep.getChild().getBitSet()).isEqualTo(OpenBitSet4);
assertThat(sep.getBitSet()).isEqualTo(intersect1And4);
- assertThat(sep.getChild().getChildren().size()).isEqualTo(1);
+ assertThat(sep.getChild().getChildren()).hasSize(1);
jtNode = sep.getChild();
assertThat(jtNode.getBitSet()).isEqualTo(OpenBitSet4);
- assertThat(jtNode.getChildren().size()).isEqualTo(1);
+ assertThat(jtNode.getChildren()).hasSize(1);
sep = jtNode.getChildren().get(0);
assertThat(sep.getParent().getBitSet()).isEqualTo(OpenBitSet4);
assertThat(sep.getChild().getBitSet()).isEqualTo(OpenBitSet3);
assertThat(sep.getBitSet()).isEqualTo(intersect3And4);
- assertThat(sep.getChild().getChildren().size()).isEqualTo(0);
+ assertThat(sep.getChild().getChildren()).isEmpty();
}
@@ -1109,7 +1108,7 @@ public class JunctionTreeBuilderTest {
JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph );
JunctionTreeClique root = jtBuilder.build(false).getRoot();
assertThat(root.getBitSet()).isEqualTo(clique1);
- assertThat(root.getChildren().size()).isEqualTo(1);
+ assertThat(root.getChildren()).hasSize(1);
// clique2
JunctionTreeSeparator sep = root.getChildren().get(0);
@@ -1117,7 +1116,7 @@ public class JunctionTreeBuilderTest {
JunctionTreeClique jtNode2 = sep.getChild();
assertThat(sep.getParent().getBitSet()).isEqualTo(clique1);
assertThat(jtNode2.getBitSet()).isEqualTo(clique2);
- assertThat(jtNode2.getChildren().size()).isEqualTo(2);
+ assertThat(jtNode2.getChildren()).hasSize(2);
// clique3
sep = jtNode2.getChildren().get(0);
@@ -1125,7 +1124,7 @@ public class JunctionTreeBuilderTest {
JunctionTreeClique jtNode3 =sep.getChild();
assertThat(sep.getParent().getBitSet()).isEqualTo(clique2);
assertThat(jtNode3.getBitSet()).isEqualTo(clique3);
- assertThat(jtNode3.getChildren().size()).isEqualTo(1);
+ assertThat(jtNode3.getChildren()).hasSize(1);
// clique4
sep = jtNode3.getChildren().get(0);
@@ -1133,7 +1132,7 @@ public class JunctionTreeBuilderTest {
JunctionTreeClique jtNode4 = sep.getChild();
assertThat(sep.getParent().getBitSet()).isEqualTo(clique3);
assertThat(jtNode4.getBitSet()).isEqualTo(clique4);
- assertThat(jtNode4.getChildren().size()).isEqualTo(0);
+ assertThat(jtNode4.getChildren()).isEmpty();
// clique5
sep = jtNode2.getChildren().get(1);
@@ -1141,7 +1140,7 @@ public class JunctionTreeBuilderTest {
JunctionTreeClique jtNode5 = sep.getChild();
assertThat(sep.getParent().getBitSet()).isEqualTo(clique2);
assertThat(jtNode5.getBitSet()).isEqualTo(clique5);
- assertThat(jtNode5.getChildren().size()).isEqualTo(1);
+ assertThat(jtNode5.getChildren()).hasSize(1);
//clique 6
sep = jtNode5.getChildren().get(0);
@@ -1149,7 +1148,7 @@ public class JunctionTreeBuilderTest {
JunctionTreeClique jtNode6 = sep.getChild();
assertThat(sep.getParent().getBitSet()).isEqualTo(clique5);
assertThat(jtNode6.getBitSet()).isEqualTo(clique6);
- assertThat(jtNode6.getChildren().size()).isEqualTo(0);
+ assertThat(jtNode6.getChildren()).isEmpty();
}
@Test
@@ -1214,7 +1213,7 @@ public class JunctionTreeBuilderTest {
// clique1
assertThat(root.getBitSet()).isEqualTo(clique1);
- assertThat(root.getChildren().size()).isEqualTo(1);
+ assertThat(root.getChildren()).hasSize(1);
// clique2
JunctionTreeSeparator sep = root.getChildren().get(0);
@@ -1222,7 +1221,7 @@ public class JunctionTreeBuilderTest {
JunctionTreeClique jtNode2 = sep.getChild();
assertThat(sep.getParent().getBitSet()).isEqualTo(clique1);
assertThat(jtNode2.getBitSet()).isEqualTo(clique2);
- assertThat(jtNode2.getChildren().size()).isEqualTo(2);
+ assertThat(jtNode2.getChildren()).hasSize(2);
// clique3
assertThat(jtNode2.getParentSeparator()).isSameAs(sep);
@@ -1231,7 +1230,7 @@ public class JunctionTreeBuilderTest {
JunctionTreeClique jtNode3 = sep.getChild();
assertThat(sep.getParent().getBitSet()).isEqualTo(clique2);
assertThat(jtNode3.getBitSet()).isEqualTo(clique3);
- assertThat(jtNode3.getChildren().size()).isEqualTo(0);
+ assertThat(jtNode3.getChildren()).isEmpty();
// clique4
sep = jtNode2.getChildren().get(1);
@@ -1239,7 +1238,7 @@ public class JunctionTreeBuilderTest {
JunctionTreeClique jtNode4 = sep.getChild();
assertThat(sep.getParent().getBitSet()).isEqualTo(clique2);
assertThat(jtNode4.getBitSet()).isEqualTo(clique4);
- assertThat(jtNode4.getChildren().size()).isEqualTo(0);
+ assertThat(jtNode4.getChildren()).isEmpty();
}
}
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/JunctionTreeTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/JunctionTreeTest.java
index 9787252a3e..cb8d228fc6 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/JunctionTreeTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/JunctionTreeTest.java
@@ -18,12 +18,10 @@
*/
package org.drools.beliefs.bayes;
-import junit.framework.AssertionFailedError;
-
import org.drools.beliefs.graph.Graph;
import org.drools.beliefs.graph.GraphNode;
import org.drools.util.bitmask.OpenBitSet;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.util.Arrays;
@@ -109,11 +107,11 @@ public class JunctionTreeTest {
PotentialMultiplier m = new PotentialMultiplier(b.getProbabilityTable(), 1, parentVarPos, parentIndexMultipliers, vars, multipliers, potentials);
m.multiple();
- assertArray(new double[]{0.1, 0.2, 0.3, 0.4}, potentials);
+ assertThat(potentials).containsExactly(0.1, 0.2, 0.3, 0.4);
// test that it's applying variable multiplications correctly ontop of each other. This simulates the application of project variabe multiplications
m.multiple();
- assertArray(new double[]{0.01, 0.04, 0.09, 0.16}, scaleDouble( 3, potentials ));
+ assertThat(scaleDouble(3, potentials)).containsExactly(0.01, 0.04, 0.09, 0.16);
}
@Test
@@ -145,11 +143,11 @@ public class JunctionTreeTest {
PotentialMultiplier m = new PotentialMultiplier(c.getProbabilityTable(), 2, parentVarPos, parentIndexMultipliers, vars, multipliers, potentials);
m.multiple();
- assertArray(new double[]{0.1, 0.1, 0.2, 0.2, 0.3, 0.3, 0.4, 0.4, 0.5, 0.5, 0.6, 0.6, 0.7, 0.7, 0.8, 0.8}, scaleDouble( 3, potentials ));
+ assertThat(scaleDouble( 3, potentials )).containsExactly(0.1, 0.1, 0.2, 0.2, 0.3, 0.3, 0.4, 0.4, 0.5, 0.5, 0.6, 0.6, 0.7, 0.7, 0.8, 0.8);
// test that it's applying variable multiplications correctly ontop of each other. This simulates the application of project variabe multiplications
m.multiple();
- assertArray(new double[]{0.01, 0.01, 0.04, 0.04, 0.09, 0.09, 0.16, 0.16, 0.25, 0.25, 0.36, 0.36, 0.49, 0.49, 0.64, 0.64}, scaleDouble( 3, potentials ) );
+ assertThat(scaleDouble( 3, potentials )).containsExactly(0.01, 0.01, 0.04, 0.04, 0.09, 0.09, 0.16, 0.16, 0.25, 0.25, 0.36, 0.36, 0.49, 0.49, 0.64, 0.64);
}
@Test
@@ -181,11 +179,11 @@ public class JunctionTreeTest {
PotentialMultiplier m = new PotentialMultiplier(c.getProbabilityTable(), 2, parentVarPos, parentIndexMultipliers, vars, multipliers, potentials);
m.multiple();
- assertArray(new double[]{0.1, 0.3, 0.2, 0.4, 0.5, 0.7, 0.6, 0.8, 0.1, 0.3, 0.2, 0.4, 0.5, 0.7, 0.6, 0.8}, potentials);
+ assertThat(potentials).containsExactly(0.1, 0.3, 0.2, 0.4, 0.5, 0.7, 0.6, 0.8, 0.1, 0.3, 0.2, 0.4, 0.5, 0.7, 0.6, 0.8);
// test that it's applying variable multiplications correctly ontop of each other. This simulates the application of project variabe multiplications
m.multiple();
- assertArray(new double[]{0.01, 0.09, 0.04, 0.16, 0.25, 0.49, 0.36, 0.64, 0.01, 0.09, 0.04, 0.16, 0.25, 0.49, 0.36, 0.64}, scaleDouble( 3, potentials ) );
+ assertThat(scaleDouble( 3, potentials )).containsExactly(0.01, 0.09, 0.04, 0.16, 0.25, 0.49, 0.36, 0.64, 0.01, 0.09, 0.04, 0.16, 0.25, 0.49, 0.36, 0.64);
}
@Test
@@ -228,27 +226,11 @@ public class JunctionTreeTest {
JunctionTree jtree = new JunctionTree(graph, node1, new JunctionTreeClique[] { node1, node2 }, null );
- assertArray(new double[]{0.1, 0.2, 0.1, 0.2}, scaleDouble( 3, node1.getPotentials() ));
- assertArray(new double[]{0.01, 0.02, 0.06, 0.08}, scaleDouble( 3, node2.getPotentials() ));
+ assertThat(scaleDouble(3, node1.getPotentials())).containsExactly(0.1, 0.2, 0.1, 0.2);
+
+ assertThat(scaleDouble(3, node2.getPotentials())).containsExactly(0.01, 0.02, 0.06, 0.08);
}
- public static void assertArray(double[] expected, double[] actual) {
- if ( !Arrays.equals(expected, actual) ) {
- System.err.print( "expected " );
- for ( int i = 0; i <expected.length; i++ ) {
- System.err.format("%.7f ", expected[i]);
- }
- System.err.println();
- System.err.print( "actual " );
- for ( int i = 0; i <actual.length; i++ ) {
- System.err.format("%.7f ", actual[i]);
- }
- System.err.println();
- throw new AssertionFailedError("Arrays are not Equal");
- }
- }
-
-
public static void assertIndexToKeyMapping(int numberOfStates, int[] indexMultipliers) {
for (int i = 0; i < numberOfStates; i++) {
int[] key = indexToKey(i, indexMultipliers);
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/LikelyhoodTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/LikelyhoodTest.java
deleted file mode 100644
index 757703c93a..0000000000
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/LikelyhoodTest.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.drools.beliefs.bayes;
-
-public class LikelyhoodTest {
-
- public void test1() {
-
- }
-
-}
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/MarginalizerTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/MarginalizerTest.java
index d22cbd91f3..8f0f71fc5c 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/MarginalizerTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/MarginalizerTest.java
@@ -20,7 +20,7 @@ package org.drools.beliefs.bayes;
import org.drools.beliefs.graph.Graph;
import org.drools.beliefs.graph.GraphNode;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import static org.drools.beliefs.bayes.GraphTest.addNode;
import static org.drools.beliefs.bayes.JunctionTreeTest.scaleDouble;
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/PassMessageTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/PassMessageTest.java
index 73dfbb5894..29b4d38918 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/PassMessageTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/PassMessageTest.java
@@ -20,11 +20,11 @@ package org.drools.beliefs.bayes;
import org.drools.beliefs.graph.Graph;
import org.drools.beliefs.graph.GraphNode;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.drools.beliefs.bayes.GraphTest.addNode;
import static org.drools.beliefs.bayes.GraphTest.bitSet;
-import static org.drools.beliefs.bayes.JunctionTreeTest.assertArray;
import static org.drools.beliefs.bayes.JunctionTreeTest.scaleDouble;
public class PassMessageTest {
@@ -59,9 +59,9 @@ public class PassMessageTest {
bayesInstance.passMessage(node1, sep, node2);
- assertArray(new double[]{0.2, 0.3}, scaleDouble(3, bayesInstance.getCliqueStates()[node1.getId()].getPotentials()));
- assertArray(new double[]{0.4, 0.6}, scaleDouble(3, sepState.getPotentials()));
- assertArray(new double[]{0.417, 0.583}, scaleDouble(3, bayesInstance.getCliqueStates()[node2.getId()].getPotentials()));
+ assertThat(scaleDouble(3, bayesInstance.getCliqueStates()[node1.getId()].getPotentials())).containsExactly(0.2, 0.3);
+ assertThat(scaleDouble(3, sepState.getPotentials())).containsExactly(0.4, 0.6);
+ assertThat(scaleDouble(3, bayesInstance.getCliqueStates()[node2.getId()].getPotentials())).containsExactly(0.417, 0.583);
}
}
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/example/EarthQuakeTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/example/EarthQuakeTest.java
index 2ada7aaf4e..dbb5d21521 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/example/EarthQuakeTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/example/EarthQuakeTest.java
@@ -27,10 +27,10 @@ import org.drools.beliefs.bayes.JunctionTreeBuilder;
import org.drools.beliefs.bayes.JunctionTreeClique;
import org.drools.beliefs.graph.Graph;
import org.drools.beliefs.graph.GraphNode;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-import static org.drools.beliefs.bayes.JunctionTreeTest.assertArray;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.drools.beliefs.bayes.JunctionTreeTest.scaleDouble;
import static org.drools.beliefs.bayes.example.SprinkerTest.connectParentToChildren;
@@ -63,7 +63,7 @@ public class EarthQuakeTest {
BayesInstance bayesInstance;
- @Before
+ @BeforeEach
public void setUp() {
connectParentToChildren(burglaryNode, alarmNode);
connectParentToChildren(earthquakeNode, alarmNode);
@@ -95,49 +95,50 @@ public class EarthQuakeTest {
@Test
public void testInitialize() {
// johnCalls
- assertArray(new double[]{0.90, 0.1, 0.05, 0.95}, scaleDouble( 3, jtNode1.getPotentials() ));
+ assertThat(scaleDouble(3, jtNode1.getPotentials())).containsExactly(0.90, 0.1, 0.05, 0.95);
// maryCalls
- assertArray( new double[]{ 0.7, 0.3, 0.01, 0.99 }, scaleDouble( 3, jtNode2.getPotentials() ));
+ assertThat(scaleDouble(3, jtNode2.getPotentials())).containsExactly(0.7, 0.3, 0.01, 0.99);
// burglary, earthquake, alarm
- assertArray( new double[]{0.0000019, 0.0000001, 0.0009381, 0.0000599, 0.0005794, 0.0014186, 0.0009970, 0.9960050 },
- scaleDouble( 7, jtNode3.getPotentials() ));
+ assertThat(scaleDouble(7, jtNode3.getPotentials())).containsExactly(0.0000019, 0.0000001, 0.0009381, 0.0000599, 0.0005794, 0.0014186, 0.0009970, 0.9960050);
}
@Test
public void testNoEvidence() {
bayesInstance.globalUpdate();
- assertArray( new double[]{0.052139, 0.947861}, scaleDouble(6, bayesInstance.marginalize("JohnCalls").getDistribution()) );
+ assertThat(scaleDouble(6, bayesInstance.marginalize("JohnCalls").getDistribution())).containsExactly(0.052139, 0.947861);
- assertArray( new double[]{0.011736, 0.988264 }, scaleDouble( 6, bayesInstance.marginalize("MaryCalls").getDistribution() ) );
+ assertThat(scaleDouble(6, bayesInstance.marginalize("MaryCalls").getDistribution() )).containsExactly(0.011736, 0.988264);
- assertArray( new double[]{0.001, 0.999}, scaleDouble(3, bayesInstance.marginalize("Burglary").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Burglary").getDistribution())).containsExactly(0.001, 0.999);
- assertArray( new double[]{ 0.002, 0.998}, scaleDouble( 3, bayesInstance.marginalize("Earthquake").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Earthquake").getDistribution() )).containsExactly(0.002, 0.998);
- assertArray( new double[]{0.002516, 0.997484}, scaleDouble(6, bayesInstance.marginalize("Alarm").getDistribution()) );
+ assertThat(scaleDouble(6, bayesInstance.marginalize("Alarm").getDistribution())).containsExactly(0.002516, 0.997484);
}
@Test
public void testAlarmEvidence() {
BayesInstance bayesInstance = new BayesInstance(jTree);
- bayesInstance.setLikelyhood( "Alarm", new double[]{1.0, 0.0} );
+ bayesInstance.setLikelyhood("Alarm", new double[]{1.0, 0.0});
bayesInstance.globalUpdate();
- assertArray( new double[]{0.9, 0.1}, scaleDouble(3, bayesInstance.marginalize("JohnCalls").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("JohnCalls").getDistribution())).containsExactly(0.9, 0.1);
- assertArray( new double[]{0.7, 0.3 }, scaleDouble( 3, bayesInstance.marginalize("MaryCalls").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("MaryCalls").getDistribution() )).containsExactly(0.7, 0.3);
- assertArray( new double[]{0.374, 0.626}, scaleDouble(3, bayesInstance.marginalize("Burglary").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Burglary").getDistribution())).containsExactly(0.374, 0.626);
- assertArray( new double[]{ 0.231, 0.769}, scaleDouble( 3, bayesInstance.marginalize("Earthquake").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Earthquake").getDistribution() )).containsExactly(0.231, 0.769);
- assertArray( new double[]{1.0, 0.0}, scaleDouble(3, bayesInstance.marginalize("Alarm").getDistribution()) ); }
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Alarm").getDistribution())).containsExactly(1.0, 0.0);
+
+ }
@Test
public void testEathQuakeEvidence() {
@@ -146,15 +147,15 @@ public class EarthQuakeTest {
bayesInstance.setLikelyhood("Earthquake", new double[]{1.0, 0.0});
bayesInstance.globalUpdate();
- assertArray( new double[]{0.297, 0.703}, scaleDouble(3, bayesInstance.marginalize("JohnCalls").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("JohnCalls").getDistribution())).containsExactly(0.297, 0.703);
- assertArray( new double[]{0.211, 0.789 }, scaleDouble( 3, bayesInstance.marginalize("MaryCalls").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("MaryCalls").getDistribution() )).containsExactly(0.211, 0.789);
- assertArray( new double[]{.001, 0.999}, scaleDouble(3, bayesInstance.marginalize("Burglary").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Burglary").getDistribution())).containsExactly(.001, 0.999);
- assertArray( new double[]{1.0, 0.0}, scaleDouble( 3, bayesInstance.marginalize("Earthquake").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Earthquake").getDistribution() )).containsExactly(1.0, 0.0);
- assertArray( new double[]{0.291, 0.709}, scaleDouble(3, bayesInstance.marginalize("Alarm").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Alarm").getDistribution())).containsExactly(0.291, 0.709);
}
@Test
@@ -164,15 +165,15 @@ public class EarthQuakeTest {
bayesInstance.setLikelyhood("JohnCalls", new double[]{1.0, 0.0});
bayesInstance.globalUpdate();
- assertArray( new double[]{1.0, 0.0}, scaleDouble(3, bayesInstance.marginalize("JohnCalls").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("JohnCalls").getDistribution())).containsExactly(1.0, 0.0);
- assertArray( new double[]{0.04, 0.96 }, scaleDouble( 3, bayesInstance.marginalize("MaryCalls").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("MaryCalls").getDistribution() )).containsExactly(0.04, 0.96);
- assertArray( new double[]{0.016, 0.984}, scaleDouble(3, bayesInstance.marginalize("Burglary").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Burglary").getDistribution())).containsExactly(0.016, 0.984);
- assertArray( new double[]{0.011, 0.989}, scaleDouble( 3, bayesInstance.marginalize("Earthquake").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Earthquake").getDistribution() )).containsExactly(0.011, 0.989);
- assertArray( new double[]{0.043, 0.957}, scaleDouble(3, bayesInstance.marginalize("Alarm").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Alarm").getDistribution())).containsExactly(0.043, 0.957);
}
@Test
@@ -183,15 +184,15 @@ public class EarthQuakeTest {
bayesInstance.globalUpdate();
- assertArray( new double[]{1.0, 0.0}, scaleDouble(3, bayesInstance.marginalize("JohnCalls").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("JohnCalls").getDistribution())).containsExactly(1.0, 0.0);
- assertArray( new double[]{0.618, 0.382 }, scaleDouble( 3, bayesInstance.marginalize("MaryCalls").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("MaryCalls").getDistribution() )).containsExactly(0.618, 0.382);
- assertArray( new double[]{0.003, 0.997}, scaleDouble(3, bayesInstance.marginalize("Burglary").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Burglary").getDistribution())).containsExactly(0.003, 0.997);
- assertArray( new double[]{ 1.0, 0.0}, scaleDouble( 3, bayesInstance.marginalize("Earthquake").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Earthquake").getDistribution() )).containsExactly(1.0, 0.0);
- assertArray( new double[]{0.881, 0.119}, scaleDouble(3, bayesInstance.marginalize("Alarm").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Alarm").getDistribution())).containsExactly(0.881, 0.119);
}
}
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/example/SprinkerTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/example/SprinkerTest.java
index 7d164305e0..db7f7495a3 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/example/SprinkerTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/example/SprinkerTest.java
@@ -30,10 +30,10 @@ import org.drools.beliefs.bayes.Marginalizer;
import org.drools.beliefs.graph.Graph;
import org.drools.beliefs.graph.GraphNode;
import org.drools.beliefs.graph.impl.EdgeImpl;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-import static org.drools.beliefs.bayes.JunctionTreeTest.assertArray;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.drools.beliefs.bayes.JunctionTreeTest.scaleDouble;
public class SprinkerTest {
@@ -46,23 +46,23 @@ public class SprinkerTest {
BayesVariable cloudy = new BayesVariable<String>("Cloudy", cloudyNode.getId(), new String[]{"true", "false"}, new double[][]{{0.5, 0.5}});
BayesVariable sprinkler = new BayesVariable<String>("Sprinkler", sprinklerNode.getId(), new String[]{"true", "false"}, new double[][]{{0.5, 0.5}, {0.9, 0.1}});
- BayesVariable rain = new BayesVariable<String>( "Rain", rainNode.getId(), new String[] { "true", "false" }, new double[][] { { 0.8, 0.2 }, { 0.2, 0.8 } } );
- BayesVariable wetGrass = new BayesVariable<String>( "WetGrass", wetGrassNode.getId(), new String[] { "true", "false" }, new double[][] { { 1.0, 0.0 }, { 0.1, 0.9 }, { 0.1, 0.9 }, { 0.01, 0.99 } } );
+ BayesVariable rain = new BayesVariable<String>("Rain", rainNode.getId(), new String[] { "true", "false" }, new double[][] { { 0.8, 0.2 }, { 0.2, 0.8 } });
+ BayesVariable wetGrass = new BayesVariable<String>("WetGrass", wetGrassNode.getId(), new String[] { "true", "false" }, new double[][] { { 1.0, 0.0 }, { 0.1, 0.9 }, { 0.1, 0.9 }, { 0.01, 0.99 } });
JunctionTree jTree;
- @Before
+ @BeforeEach
public void setUp() {
- connectParentToChildren( cloudyNode, sprinklerNode, rainNode);
- connectParentToChildren( sprinklerNode, wetGrassNode);
- connectParentToChildren( rainNode, wetGrassNode);
+ connectParentToChildren(cloudyNode, sprinklerNode, rainNode);
+ connectParentToChildren(sprinklerNode, wetGrassNode);
+ connectParentToChildren(rainNode, wetGrassNode);
cloudyNode.setContent(cloudy);
- sprinklerNode.setContent( sprinkler);
- rainNode.setContent( rain );
- wetGrassNode.setContent( wetGrass );
+ sprinklerNode.setContent(sprinkler);
+ rainNode.setContent(rain);
+ wetGrassNode.setContent(wetGrass);
- JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph );
+ JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder(graph);
jTree = jtBuilder.build();
}
@@ -71,79 +71,79 @@ public class SprinkerTest {
JunctionTreeClique jtNode = jTree.getRoot();
// cloud, rain sprinkler
- assertArray(new double[]{0.2, 0.05, 0.2, 0.05, 0.09, 0.36, 0.01, 0.04 }, scaleDouble( 3, jtNode.getPotentials() ));
+ assertThat(scaleDouble(3, jtNode.getPotentials())).containsExactly(0.2, 0.05, 0.2, 0.05, 0.09, 0.36, 0.01, 0.04);
// wetGrass
jtNode = jTree.getRoot().getChildren().get(0).getChild();
- assertArray(new double[]{1.0, 0.0, 0.1, 0.9, 0.1, 0.9, 0.01, 0.99 }, scaleDouble( 3, jtNode.getPotentials() ));
+ assertThat(scaleDouble(3, jtNode.getPotentials())).containsExactly(1.0, 0.0, 0.1, 0.9, 0.1, 0.9, 0.01, 0.99);
}
@Test
public void testNoEvidence() {
- JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph );
+ JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder(graph);
JunctionTree jTree = jtBuilder.build();
JunctionTreeClique jtNode = jTree.getRoot();
BayesInstance bayesInstance = new BayesInstance(jTree);
bayesInstance.globalUpdate();
- assertArray(new double[]{0.5, 0.5}, scaleDouble(3, bayesInstance.marginalize("Cloudy").getDistribution()));
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Cloudy").getDistribution())).containsExactly(0.5, 0.5);
- assertArray( new double[]{0.5, 0.5}, scaleDouble( 3, bayesInstance.marginalize("Rain").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Rain").getDistribution())).containsExactly(0.5, 0.5);
- assertArray( new double[]{0.7, 0.3}, scaleDouble(3, bayesInstance.marginalize("Sprinkler").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Sprinkler").getDistribution())).containsExactly(0.7, 0.3);
- assertArray( new double[]{0.353, 0.647}, scaleDouble( 3, bayesInstance.marginalize("WetGrass").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("WetGrass").getDistribution())).containsExactly(0.353, 0.647);
}
@Test
public void testGrassWetEvidence() {
- JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph );
+ JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder(graph);
JunctionTree jTree = jtBuilder.build();
JunctionTreeClique jtNode = jTree.getRoot();
BayesInstance bayesInstance = new BayesInstance(jTree);
- bayesInstance.setLikelyhood( "WetGrass", new double[]{1.0, 0.0} );
+ bayesInstance.setLikelyhood("WetGrass", new double[]{1.0, 0.0});
bayesInstance.globalUpdate();
- assertArray(new double[]{0.639, 0.361}, scaleDouble(3, bayesInstance.marginalize("Cloudy").getDistribution()));
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Cloudy").getDistribution())).containsExactly(0.639, 0.361);
- assertArray( new double[]{0.881, 0.119}, scaleDouble( 3, bayesInstance.marginalize("Rain").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Rain").getDistribution())).containsExactly(0.881, 0.119);
- assertArray( new double[]{0.938, 0.062}, scaleDouble(3, bayesInstance.marginalize("Sprinkler").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Sprinkler").getDistribution())).containsExactly(0.938, 0.062);
- assertArray( new double[]{1.0, 0.0}, scaleDouble( 3, bayesInstance.marginalize("WetGrass").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("WetGrass").getDistribution())).containsExactly(1.0, 0.0);
}
@Test
public void testSprinklerEvidence() {
- JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph );
+ JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder(graph);
JunctionTree jTree = jtBuilder.build();
JunctionTreeClique jtNode = jTree.getRoot();
BayesInstance bayesInstance = new BayesInstance(jTree);
- bayesInstance.setLikelyhood( "Sprinkler", new double[]{1.0, 0.0} );
- bayesInstance.setLikelyhood( "Cloudy", new double[]{1.0, 0.0} );
+ bayesInstance.setLikelyhood("Sprinkler", new double[]{1.0, 0.0});
+ bayesInstance.setLikelyhood("Cloudy", new double[]{1.0, 0.0});
bayesInstance.globalUpdate();
- assertArray(new double[]{1.0, 0.0}, scaleDouble(3, bayesInstance.marginalize("Cloudy").getDistribution()));
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Cloudy").getDistribution())).containsExactly(1.0, 0.0);
- assertArray( new double[]{0.8, 0.2}, scaleDouble( 3, bayesInstance.marginalize("Rain").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Rain").getDistribution())).containsExactly(0.8, 0.2);
- assertArray( new double[]{1.0, 0.0}, scaleDouble(3, bayesInstance.marginalize("Sprinkler").getDistribution()) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("Sprinkler").getDistribution())).containsExactly(1.0, 0.0);
- assertArray( new double[]{0.82, 0.18}, scaleDouble( 3, bayesInstance.marginalize("WetGrass").getDistribution() ) );
+ assertThat(scaleDouble(3, bayesInstance.marginalize("WetGrass").getDistribution())).containsExactly(0.82, 0.18);
}
public static void marginalize(BayesVariableState varState, CliqueState cliqueState) {
JunctionTreeClique jtNode = cliqueState.getJunctionTreeClique();
- new Marginalizer(jtNode.getValues().toArray( new BayesVariable[jtNode.getValues().size()]), cliqueState.getPotentials(), varState.getVariable(), varState.getDistribution() );
- System.out.print( varState.getVariable().getName() + " " );
- for ( double d : varState.getDistribution() ) {
+ new Marginalizer(jtNode.getValues().toArray(new BayesVariable[jtNode.getValues().size()]), cliqueState.getPotentials(), varState.getVariable(), varState.getDistribution());
+ System.out.print(varState.getVariable().getName() + " ");
+ for (double d : varState.getDistribution()) {
System.out.print(d);
System.out.print(" ");
}
@@ -152,12 +152,12 @@ public class SprinkerTest {
public static GraphNode<BayesVariable> addNode(Graph<BayesVariable> graph) {
GraphNode<BayesVariable> x = graph.addNode();
- x.setContent( new BayesVariable<String>( "x" + x.getId(), x.getId(), new String[] { "a", "b" }, new double[][] { { 0.1, 0.1 } } ) );
+ x.setContent(new BayesVariable<String>("x" + x.getId(), x.getId(), new String[] { "a", "b" }, new double[][] { { 0.1, 0.1 } }));
return x;
}
public static void connectParentToChildren(GraphNode parent, GraphNode... children) {
- for ( GraphNode child : children ) {
+ for (GraphNode child : children) {
EdgeImpl e = new EdgeImpl();
e.setOutGraphNode(parent);
e.setInGraphNode(child);
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/AssemblerTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/AssemblerTest.java
index 639433d3e8..bee6c7eb0c 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/AssemblerTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/AssemblerTest.java
@@ -20,8 +20,8 @@ package org.drools.beliefs.bayes.integration;
import org.drools.beliefs.bayes.assembler.BayesPackage;
import org.drools.compiler.builder.impl.KnowledgeBuilderImpl;
+import org.junit.jupiter.api.Test;
import org.drools.base.definitions.InternalKnowledgePackage;
-import org.junit.Test;
import org.kie.api.io.ResourceType;
import org.kie.internal.io.ResourceFactory;
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/BayesBeliefSystemTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/BayesBeliefSystemTest.java
index 1736cef541..2789052745 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/BayesBeliefSystemTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/BayesBeliefSystemTest.java
@@ -33,7 +33,7 @@ import org.drools.base.rule.EntryPointId;
import org.drools.kiesession.rulebase.InternalKnowledgeBase;
import org.drools.kiesession.rulebase.KnowledgeBaseFactory;
import org.drools.kiesession.session.StatefulKnowledgeSessionImpl;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.KieSessionConfiguration;
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/BayesRuntimeTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/BayesRuntimeTest.java
index 18ade7b855..72fdc12eca 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/BayesRuntimeTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/BayesRuntimeTest.java
@@ -24,7 +24,7 @@ import org.drools.compiler.builder.impl.KnowledgeBuilderImpl;
import org.drools.kiesession.rulebase.InternalKnowledgeBase;
import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase;
import org.drools.kiesession.session.StatefulKnowledgeSessionImpl;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.kie.api.io.ResourceType;
import org.kie.internal.io.ResourceFactory;
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/ParserTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/ParserTest.java
index e8207f4dd7..03084d43a2 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/ParserTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/ParserTest.java
@@ -26,9 +26,8 @@ import org.drools.beliefs.bayes.model.Network;
import org.drools.beliefs.bayes.model.Variable;
import org.drools.beliefs.bayes.model.XmlBifParser;
import org.drools.beliefs.graph.GraphNode;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -46,39 +45,34 @@ public class ParserTest {
assertThat(network.getProperties().get(0)).isEqualTo("package = org.drools.beliefs.bayes.integration");
Map<String, Variable> varMap = varToMap( network.getVariables() );
- assertThat(varMap.size()).isEqualTo(4);
+ assertThat(varMap).hasSize(4);
Variable var = varMap.get("WetGrass");
assertThat(var.getName()).isEqualTo("WetGrass");
- assertThat(var.getOutComes().size()).isEqualTo(2);
- assertThat(Arrays.asList("false", "true")).isEqualTo(var.getOutComes());
+ assertThat(var.getOutComes()).hasSize(2).containsExactly("false", "true");
assertThat(var.getProperties().get(0)).isEqualTo("position = (0,10)");
var = varMap.get("Cloudy");
assertThat(var.getName()).isEqualTo("Cloudy");
- assertThat(var.getOutComes().size()).isEqualTo(2);
- assertThat(Arrays.asList("false", "true")).isEqualTo(var.getOutComes());
+ assertThat(var.getOutComes()).hasSize(2).containsExactly("false", "true");
assertThat(var.getProperties().get(0)).isEqualTo("position = (0,-10)");
var = varMap.get("Sprinkler");
assertThat(var.getName()).isEqualTo("Sprinkler");
- assertThat(var.getOutComes().size()).isEqualTo(2);
- assertThat(Arrays.asList("false", "true")).isEqualTo(var.getOutComes());
+ assertThat(var.getOutComes()).hasSize(2).containsExactly("false", "true");
assertThat(var.getProperties().get(0)).isEqualTo("position = (13,0)");
var = varMap.get("Rain");
assertThat(var.getName()).isEqualTo("Rain");
- assertThat(var.getOutComes().size()).isEqualTo(2);
- assertThat(Arrays.asList("false", "true")).isEqualTo(var.getOutComes());
+ assertThat(var.getOutComes()).hasSize(2).containsExactly("false", "true");
assertThat(var.getProperties().get(0)).isEqualTo("position = (-12,0)");
Map<String, Definition> defMap = defToMap( network.getDefinitions() );
- assertThat(defMap.size()).isEqualTo(4);
+ assertThat(defMap).hasSize(4);
Definition def = defMap.get( "WetGrass");
assertThat(def.getName()).isEqualTo("WetGrass");
- assertThat(def.getGiven().size()).isEqualTo(2);
- assertThat(Arrays.asList("Sprinkler", "Rain")).isEqualTo(def.getGiven());
+ assertThat(def.getGiven()).hasSize(2).containsExactly("Sprinkler", "Rain");
assertThat(def.getProbabilities()).isEqualTo("1.0 0.0 0.1 0.9 0.1 0.9 0.01 0.99");
def = defMap.get( "Cloudy");
@@ -88,8 +82,7 @@ public class ParserTest {
def = defMap.get( "Sprinkler");
assertThat(def.getName()).isEqualTo("Sprinkler");
- assertThat(def.getGiven().size()).isEqualTo(1);
- assertThat(def.getGiven().get(0)).isEqualTo("Cloudy");
+ assertThat(def.getGiven()).hasSize(1).containsExactly("Cloudy");
assertThat(def.getProbabilities().trim()).isEqualTo("0.5 0.5 0.9 0.1");
def = defMap.get( "Rain");
@@ -107,29 +100,28 @@ public class ParserTest {
GraphNode<BayesVariable> node = map.get( "WetGrass" );
BayesVariable wetGrass = node.getContent();
- assertThat(Arrays.asList(wetGrass.getOutcomes())).isEqualTo(Arrays.asList("false", "true"));
- assertThat(wetGrass.getGiven().length).isEqualTo(2);
- assertThat(Arrays.asList("Sprinkler", "Rain")).isEqualTo(Arrays.asList(wetGrass.getGiven()));
- assertThat(Arrays.deepEquals(new double[][]{{1.0, 0.0}, {0.1, 0.9}, {0.1, 0.9}, {0.01, 0.99}}, wetGrass.getProbabilityTable())).isTrue();
+ assertThat(wetGrass.getOutcomes()).containsExactly("false", "true");
+ assertThat(wetGrass.getGiven()).hasSize(2).containsExactly("Sprinkler", "Rain");
+ assertThat(wetGrass.getProbabilityTable()).isDeepEqualTo(new double[][]{{1.0, 0.0}, {0.1, 0.9}, {0.1, 0.9}, {0.01, 0.99}});
node = map.get( "Sprinkler" );
BayesVariable sprinkler = node.getContent();
- assertThat(Arrays.asList(sprinkler.getOutcomes())).isEqualTo(Arrays.asList("false", "true"));
- assertThat(sprinkler.getGiven().length).isEqualTo(1);
+ assertThat(wetGrass.getOutcomes()).containsExactly("false", "true");
+ assertThat(sprinkler.getGiven()).hasSize(1);
assertThat(sprinkler.getGiven()[0]).isEqualTo("Cloudy");
- assertThat(Arrays.deepEquals(new double[][]{{0.5, 0.5}, {0.9, 0.1}}, sprinkler.getProbabilityTable())).isTrue();
+ assertThat(sprinkler.getProbabilityTable()).isDeepEqualTo(new double[][]{{0.5, 0.5}, {0.9, 0.1}});
node = map.get( "Cloudy" );
BayesVariable cloudy = node.getContent();
- assertThat(Arrays.asList(cloudy.getOutcomes())).isEqualTo(Arrays.asList("false", "true"));
- assertThat(cloudy.getGiven().length).isEqualTo(0);
- assertThat(Arrays.deepEquals(new double[][]{{0.5, 0.5}}, cloudy.getProbabilityTable())).isTrue();
+ assertThat(wetGrass.getOutcomes()).containsExactly("false", "true");
+ assertThat(cloudy.getGiven()).isEmpty();
+ assertThat(cloudy.getProbabilityTable()).isDeepEqualTo(new double[][]{{0.5, 0.5}});
node = map.get( "Rain" );
BayesVariable rain = node.getContent();
- assertThat(Arrays.asList(rain.getOutcomes())).isEqualTo(Arrays.asList("false", "true"));
- assertThat(rain.getGiven().length).isEqualTo(0);
- assertThat(Arrays.deepEquals(new double[][]{{0.5, 0.5}}, rain.getProbabilityTable())).isTrue();
+ assertThat(rain.getOutcomes()).containsExactly("false", "true");
+ assertThat(rain.getGiven()).isEmpty();
+ assertThat(rain.getProbabilityTable()).isDeepEqualTo(new double[][]{{0.5, 0.5}});
}
Map<String, GraphNode<BayesVariable>> nodeToMap(BayesNetwork network) {
diff --git a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/WeaverTest.java b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/WeaverTest.java
index 60daf82220..a7951f34bc 100644
--- a/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/WeaverTest.java
+++ b/drools-beliefs/src/test/java/org/drools/beliefs/bayes/integration/WeaverTest.java
@@ -25,7 +25,7 @@ import org.drools.base.definitions.InternalKnowledgePackage;
import org.drools.base.definitions.ResourceTypePackageRegistry;
import org.drools.kiesession.rulebase.InternalKnowledgeBase;
import org.drools.kiesession.rulebase.KnowledgeBaseFactory;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.kie.api.io.ResourceType;
import org.kie.internal.io.ResourceFactory;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org