package water.score;

import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import org.junit.Assert;
import org.junit.Test;
import water.parser.PMMLParser;
import water.util.TestUtil;
import water.*;

public class ScoreTest extends TestUtil {
  static final HashMap<String, Comparable> ROW;
  static {
    ROW = new HashMap<String, Comparable>();
    ROW.put("id", "80457298");
    ROW.put("string", "AOS");
    ROW.put("int", "71");
    ROW.put("long", 399L);
  }

  @Test
  public void testScorecard() throws Exception {
  }

  // Load and score a simple PMML RF model against the iris dataset.
  // Not ready, so not turned on.
  public void testRandomForest1() throws Exception {
    File file = find_test_file("smalldata/pmml/iris_rf_1tree.pmml.xml");
    ScoreModel rfm = PMMLParser.load(new FileInputStream(file));
  
    Key irisk = loadAndParseKey("iris.hex","smalldata/iris/iris.csv");
    ValueArray ary = ValueArray.value(DKV.get(irisk));
    AutoBuffer bits = ary.getChunk(0);
    int rows = ary.rpc(0);
    for( int i=0; i<rows; i++ ) {
      StringBuilder sb = new StringBuilder();
      for( int j=0; j<ary._cols.length; j++ )
        sb.append(ary._cols[j]._name).append("=").append(ary.datad(bits,i,j));
      sb.append("\n");
      System.err.println(sb.toString());
    }
  
  }
}

@@ -34,44 +34,9 @@
 .io.
-File;%0Aimport java.io.FileInputStream
+*
 ;%0Aim
@@ -506,16 +506,283 @@
 ption %7B%0A
+    File file = find_test_file(%22smalldata/pmml/Loan_Scorecard.xml%22);%0A    ScorecardModel scm = (ScorecardModel)PMMLParser.parse(new FileInputStream(file));%0A    Assert.assertEquals(0, scm.score_interpreter(ROW), 1e-6);%0A    Assert.assertEquals(0, scm.score(ROW), 1e-6);%0A
   %7D%0A%0A  /
@@ -853,39 +853,13 @@
 .%0A  
-// Not ready, so not turned on.
+@Test
 %0A  p
@@ -904,32 +904,149 @@
 Exception %7B%0A    
+// The 1-tree set scores with 2 errors.%0A    // The 500-tree set scores perfectly, takes slightly long to load.%0A    //
 File file = find
@@ -1084,20 +1084,88 @@
 _rf_
-1
+500
 tree
+s
 .pmml
-.x
+%22);%0A    File file = find_test_file(%22smalldata/pmml/iris_rf_1tree.pm
 ml%22)
@@ -1166,24 +1166,26 @@
 pmml%22);%0A    
+RF
 ScoreModel r
@@ -1193,23 +1193,62 @@
 m = 
-PMMLParser.load
+(RFScoreModel)PMMLParser.parse(new BufferedInputStream
 (new
@@ -1266,24 +1266,25 @@
 tream(file))
+)
 ;%0A  %0A    Key
@@ -1339,16 +1339,17 @@
 ris/iris
+2
 .csv%22);%0A
@@ -1465,24 +1465,42 @@
 ary.rpc(0);%0A
+    int errs = 0;%0A
     for( int
@@ -1531,44 +1531,52 @@
     
-StringBuilder sb = new StringBuilder
+HashMap%3CString,Comparable%3E row = new HashMap
 ();%0A
@@ -1629,25 +1629,23 @@
         
-sb.append
+row.put
 (ary._co
@@ -1659,37 +1659,95 @@
 name
-).append(%22=%22).append(
+,ary.datad(bits,i,j));%0A      int pr = (int)rfm.score(row);%0A      int ac = (int)
 ary.data
 d(bi
@@ -1738,33 +1738,32 @@
 int)ary.data
-d
 (bits,i,
 j));%0A      s
@@ -1742,34 +1742,33 @@
 ary.data(bits,i,
-j)
+4
 );%0A      sb.appe
@@ -1764,74 +1764,100 @@
     
-sb.append(%22%5Cn%22);%0A      System.err.println(sb.toString());%0A    %7D%0A  
+if( pr != ac )%0A        errs++;%0A    %7D%0A    Assert.assertEquals(2,errs);%0A    UKV.remove(irisk);
 %0A  %7D

Fix merge