Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Improve regression diff and update some test fixtures #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.classpath
.project
.settings/
build/
dist/
doc/

8 changes: 4 additions & 4 deletions weka/src/test/java/weka/core/OptionHandlersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class OptionHandlersTest extends TestCase {
/**
* tests a specific OptionHandler
*/
public static class OptionHandlerTest extends TestCase {
static class OptionHandlerTestInternal extends TestCase {

/** the class to test */
protected String m_Classname;
Expand All @@ -57,7 +57,7 @@ public static class OptionHandlerTest extends TestCase {
* @param name the name of the test class
* @param classname the actual classname
*/
public OptionHandlerTest(String name, String classname) {
public OptionHandlerTestInternal(String name, String classname) {
super(name);

m_Classname = classname;
Expand Down Expand Up @@ -215,7 +215,7 @@ public static Test suite() {
try {
// determine all test methods in the OptionHandlerTest class
Vector<String> testMethods = new Vector<String>();
Method[] methods = OptionHandlerTest.class.getDeclaredMethods();
Method[] methods = OptionHandlerTestInternal.class.getDeclaredMethods();
for (Method method : methods) {
if (method.getName().startsWith("test")) {
testMethods.add(method.getName());
Expand Down Expand Up @@ -251,7 +251,7 @@ public static Test suite() {

// add tests for this class
for (int i = 0; i < testMethods.size(); i++) {
suite.addTest(new OptionHandlerTest(testMethods.get(i), classname));
suite.addTest(new OptionHandlerTestInternal(testMethods.get(i), classname));
}
}
}
Expand Down
37 changes: 25 additions & 12 deletions weka/src/test/java/weka/test/Regression.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
import java.util.Properties;

Expand Down Expand Up @@ -141,19 +142,31 @@ public String diff() throws IOException {
* differences.
*/
protected String diff(String reference, String current) {

if (reference.equals(current)) {
return "";
} else {
// Should do something more cunning here, like try to isolate the
// actual differences. We could also try calling unix diff utility
// if it exists.
StringBuffer diff = new StringBuffer();
diff.append("+++ Reference: ").append(m_RefFile).append(" +++\n")
.append(reference).append("+++ Current +++\n").append(current)
.append("+++\n");
return diff.toString();
StringBuffer diff = new StringBuffer();
try {
BufferedReader brExp = new BufferedReader(new StringReader(reference));
BufferedReader brWas = new BufferedReader(new StringReader(current));
String expLine = brExp.readLine();
String wasLine = brWas.readLine();
while (expLine != null || wasLine != null) {
if (!("" + expLine).equals("" + wasLine)) {
if (diff.length() == 0) {
diff.append("+++ Reference: ").append(m_RefFile).append(" +++\n")
.append(reference)
.append("+++ Current +++\n")
.append(current)
.append("+++\n");
}
diff.append("Exp: " + expLine + "\n");
diff.append("Was: " + wasLine + "\n");
}
expLine = brExp.readLine();
wasLine = brWas.readLine();
}
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
return diff.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ NUM: 1.0427293479442596 1.1169759757532756 1.0

10 predictions
NUM: 2.80855806E12 2.8085580597055015E12 1.0
NUM: 2.58763326E12 2.5876332599510005E12 1.0
NUM: 1.54625406E12 1.5462540611080254E12 1.0
NUM: 2.58763326E12 2.587633259951001E12 1.0
NUM: 1.54625406E12 1.546254061108026E12 1.0
NUM: 2.61925566E12 2.619255659915878E12 1.0
NUM: 2.84009406E12 2.8400940596704585E12 1.0
NUM: 1.04133246E12 1.0413324616691511E12 1.0
NUM: 1.04133246E12 1.0413324616691517E12 1.0
NUM: 3.43971006E12 3.439710059004154E12 1.0
NUM: 2.80855806E12 2.8085580597055015E12 1.0
NUM: 1.83025086E12 1.8302508607925725E12 1.0
NUM: 1.29379326E12 1.2937932613885295E12 1.0
NUM: 1.83025086E12 1.8302508607925728E12 1.0
NUM: 1.29379326E12 1.29379326138853E12 1.0

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
10 predictions
NOM: 0.0 0.0 1.0 0.973341367583095 0.02665863241690505
NOM: 0.0 0.0 1.0 0.9524951020531026 0.047504897946897384
NOM: 0.0 0.0 1.0 0.993490469203576 0.006509530796424058
NOM: 0.0 0.0 1.0 0.9429297606330429 0.05707023936695715
NOM: 1.0 1.0 1.0 0.0022872290965505475 0.9977127709034495
NOM: 0.0 0.0 1.0 0.9733413675830949 0.026658632416905144
NOM: 0.0 0.0 1.0 0.9524951020531025 0.04750489794689747
NOM: 0.0 0.0 1.0 0.9934904692035759 0.006509530796424155
NOM: 0.0 0.0 1.0 0.9429297606330428 0.05707023936695722
NOM: 1.0 1.0 1.0 0.002287229096550769 0.9977127709034492
NOM: 1.0 1.0 1.0 0.0 1.0
NOM: 1.0 1.0 1.0 0.05165225921391215 0.9483477407860879
NOM: 0.0 0.0 1.0 0.9732051524144633 0.026794847585536737
NOM: 1.0 1.0 1.0 0.051652259213912366 0.9483477407860876
NOM: 0.0 0.0 1.0 0.9732051524144631 0.026794847585536827
NOM: 1.0 1.0 1.0 0.0 1.0
NOM: 1.0 1.0 1.0 0.024988999313463548 0.9750110006865365
NOM: 1.0 1.0 1.0 0.024988999313463767 0.9750110006865362

Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ NUM: 0.09358982741832733 0.07144234520918284 1.0
NUM: 1.0427293479442596 1.116975975753276 1.0

10 predictions
NUM: 2.80855806E12 2.8085580597055024E12 1.0
NUM: 2.80855806E12 2.808558059705502E12 1.0
NUM: 2.58763326E12 2.5876332599510015E12 1.0
NUM: 1.54625406E12 1.546254061108025E12 1.0
NUM: 1.54625406E12 1.5462540611080254E12 1.0
NUM: 2.61925566E12 2.619255659915879E12 1.0
NUM: 2.84009406E12 2.8400940596704595E12 1.0
NUM: 1.04133246E12 1.0413324616691499E12 1.0
NUM: 3.43971006E12 3.439710059004156E12 1.0
NUM: 2.80855806E12 2.8085580597055024E12 1.0
NUM: 1.83025086E12 1.8302508607925723E12 1.0
NUM: 1.29379326E12 1.2937932613885286E12 1.0
NUM: 1.04133246E12 1.0413324616691508E12 1.0
NUM: 3.43971006E12 3.4397100590041553E12 1.0
NUM: 2.80855806E12 2.808558059705502E12 1.0
NUM: 1.83025086E12 1.8302508607925728E12 1.0
NUM: 1.29379326E12 1.2937932613885293E12 1.0

Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ NUM: 0.09358982741832733 0.07144234520918284 1.0
NUM: 1.0427293479442596 1.116975975753276 1.0

10 predictions
NUM: 2.80855806E12 2.8085580597055024E12 1.0
NUM: 2.80855806E12 2.808558059705502E12 1.0
NUM: 2.58763326E12 2.5876332599510015E12 1.0
NUM: 1.54625406E12 1.546254061108025E12 1.0
NUM: 1.54625406E12 1.5462540611080254E12 1.0
NUM: 2.61925566E12 2.619255659915879E12 1.0
NUM: 2.84009406E12 2.8400940596704595E12 1.0
NUM: 1.04133246E12 1.0413324616691499E12 1.0
NUM: 3.43971006E12 3.439710059004156E12 1.0
NUM: 2.80855806E12 2.8085580597055024E12 1.0
NUM: 1.83025086E12 1.8302508607925723E12 1.0
NUM: 1.29379326E12 1.2937932613885286E12 1.0
NUM: 1.04133246E12 1.0413324616691508E12 1.0
NUM: 3.43971006E12 3.4397100590041553E12 1.0
NUM: 2.80855806E12 2.808558059705502E12 1.0
NUM: 1.83025086E12 1.8302508607925728E12 1.0
NUM: 1.29379326E12 1.2937932613885293E12 1.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@relation FilterTest-weka.filters.unsupervised.attribute.NumericToNominal-Rfirst-last

@attribute StringAtt1 string
@attribute NominalAtt1 {r,g,b}
@attribute NumericAtt1 {0,1,1.4,2,2.3,3,3.3,4,4.3,5,5.3,6,6.5,7,7.5,8,8.5,9,9.4}
@attribute StringAtt2 string
@attribute NominalAtt2 {a,b,c,d}
@attribute NumericAtt2 {-9.3,-9,-8.3,-7.3,-5.6,-5.3,-4.3,-3.8,-3.3,-2.8,-2.6,-2.4,-2.3,-2,-1,0,3.4}
@attribute DateAtt1 {1970-01-01,2001-04-03,2001-04-04,2001-05-04,2001-05-05,2001-05-06,2001-06-06,2001-06-07}

@data
humpty,g,1,the,a,-2.3,2001-04-03
dumpty,b,2,quick,b,-3.3,2001-04-03
sat,r,3,brown,c,-2.4,2001-04-03
on,r,4,fox,d,-5.3,2001-04-03
a,b,5,jumped,a,-2.6,2001-04-03
wall,r,6,over,b,-7.3,2001-04-04
humpty,r,7,the,c,-2.8,2001-04-04
dumpty,g,8,lazy,d,-9.3,2001-04-04
had,b,9,dog,?,-2,2001-05-04
a,r,9.4,?,?,-9,2001-05-04
great,r,1.4,the,a,-8.3,2001-05-05
fall,b,2.3,quick,b,-7.3,2001-05-05
all,r,3.3,brown,c,?,2001-05-05
the,r,4.3,fox,d,-5.3,2001-05-05
kings,g,5.3,jumped,?,-5.6,2001-05-06
horses,b,6.5,over,b,-4.3,2001-05-06
and,r,7.5,the,c,-3.8,2001-06-06
all,r,8.5,lazy,d,-2.3,2001-06-06
the,r,9.4,?,a,-1,2001-06-07
{0 wall,2 4.3,3 the,4 d,5 0}
{0 humpty,1 b,3 lazy,5 3.4}