Skip to content

Commit 8d083bf

Browse files
fix tests
1 parent 4d8063b commit 8d083bf

4 files changed

Lines changed: 46 additions & 28 deletions

File tree

.github/workflows/capymoa.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ jobs:
2020
distribution: 'temurin'
2121
cache: maven
2222

23+
- name: Unit Tests
24+
working-directory: ./moa
25+
run: mvn -B test
26+
2327
- name: Package Jar
2428
working-directory: ./moa
2529
# Package as JAR while skipping tests, javadoc, and latex build

moa/src/main/java/moa/clusterers/clustream/ClustreamKernel.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,8 @@ public ClustreamKernel(Instance instance, int dimensions, long timestamp , doubl
4646
// Avoid situations where the instance header hasn't been defined and runtime errors.
4747
if(instance.dataset() != null) {
4848
this.classObserver = new double[instance.numClasses()];
49-
// instance.numAttributes() <= instance.classIndex() -> edge case where the class index is equal the
50-
// number of attributes (i.e. there is no class value in the attributes array).
51-
if (instance.numAttributes() > instance.classIndex() &&
52-
!instance.classIsMissing() &&
53-
instance.classValue() >= 0 &&
54-
instance.classValue() < instance.numClasses()) {
49+
//
50+
if (this.instanceHasClass(instance)) {
5551
this.classObserver[(int) instance.classValue()]++;
5652
}
5753
}
@@ -72,12 +68,22 @@ public ClustreamKernel( ClustreamKernel cluster, double t, int m ) {
7268
this.classObserver = cluster.classObserver;
7369
}
7470

71+
private boolean instanceHasClass(Instance instance) {
72+
// TODO: Why is this check necessary? Shouldn't classIsMissing() be enough?
73+
// Edge case where the class index is out of bounds. number of attributes
74+
// (i.e. there is no class value in the attributes array).
75+
return instance.numAttributes() > instance.classIndex() &&
76+
!instance.classIsMissing() && // Also check for missing class.
77+
instance.classValue() >= 0 && // Or invalid class values.
78+
instance.classValue() < instance.numClasses();
79+
}
80+
7581
public void insert( Instance instance, long timestamp ) {
7682
if(this.classObserver == null)
7783
this.classObserver = new double[instance.numClasses()];
78-
if(!instance.classIsMissing() &&
79-
instance.classValue() >= 0 &&
80-
instance.classValue() < instance.numClasses()) {
84+
System.out.println(instance.classIndex());
85+
86+
if(this.instanceHasClass(instance)) {
8187
this.classObserver[(int)instance.classValue()]++;
8288
}
8389
N++;

moa/src/test/java/moa/integration/SimpleClusterTest.java

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,34 @@ public class SimpleClusterTest extends TestCase {
2222
final static String [] Clusterers = new String[]{"ClusterGenerator", "CobWeb", "KMeans",
2323
"clustream.Clustream", "clustree.ClusTree", "denstream.WithDBSCAN -i 1000", "streamkm.StreamKM"};
2424

25-
@Test
26-
public void testClusterGenerator(){testClusterer(Clusterers[0]);}
27-
// @Test
28-
// public void testCobWeb(){testClusterer(Clusterers[1]);}
29-
@Test
30-
public void testClustream(){testClusterer(Clusterers[3]);}
31-
@Test
32-
public void testClusTree(){testClusterer(Clusterers[4]);}
33-
@Test
34-
public void testDenStream(){testClusterer(Clusterers[5]);}
35-
@Test
36-
public void testStreamKM(){testClusterer(Clusterers[6]);}
25+
@Test
26+
public void testClusterGenerator() throws Exception {
27+
testClusterer(Clusterers[0]);
28+
}
29+
30+
@Test
31+
public void testClustream() throws Exception {
32+
testClusterer(Clusterers[3]);
33+
}
34+
35+
@Test
36+
public void testClusTree() throws Exception {
37+
testClusterer(Clusterers[4]);
38+
}
39+
40+
@Test
41+
public void testDenStream() throws Exception {
42+
testClusterer(Clusterers[5]);
43+
}
44+
45+
@Test
46+
public void testStreamKM() throws Exception {
47+
testClusterer(Clusterers[6]);
48+
}
3749

38-
void testClusterer(String clusterer) {
50+
void testClusterer(String clusterer) throws Exception {
3951
System.out.println("Processing: " + clusterer);
40-
try {
41-
doTask(new String[]{"EvaluateClustering -l " + clusterer});
42-
} catch (Exception e) {
43-
assertTrue("Failed on clusterer " + clusterer + ": " + e.getMessage(), false);
44-
}
52+
doTask(new String[]{"EvaluateClustering -l " + clusterer});
4553
}
4654

4755
// code copied from moa.DoTask.main, to allow exceptions to be thrown in case of failure

moa/src/test/resources/moa/classifiers/trees/AdaHoeffdingOptionTree.ref

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Index
4949
30000
5050
Votes
5151
0: 3.612203649887567E14
52-
1: 1.24768970176524544E17
52+
1: 1.2476897017652454E17
5353
Measurements
5454
classified instances: 29999
5555
classifications correct (percent): 85.57618587

0 commit comments

Comments
 (0)