Fix a bug whereby FactorCovariate fails when "NA" is provided.
Also improved testing around this.
This commit is contained in:
parent
6b62ad95c3
commit
4bbb0e0948
3 changed files with 11 additions and 3 deletions
|
@ -69,7 +69,7 @@ public final class FactorCovariate implements Covariate<String>{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FactorValue createValue(String value) {
|
public FactorValue createValue(String value) {
|
||||||
if(value == null){
|
if(value == null || value.equalsIgnoreCase("na")){
|
||||||
return this.naValue;
|
return this.naValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class TestLoadingCSV {
|
||||||
5,3.0,"mouse",true
|
5,3.0,"mouse",true
|
||||||
2,1.0,"dog",false
|
2,1.0,"dog",false
|
||||||
9,1.5,"cat",true
|
9,1.5,"cat",true
|
||||||
|
-3,NA,NA,NA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -41,7 +42,7 @@ public class TestLoadingCSV {
|
||||||
|
|
||||||
final List<Row<Double>> data = Main.loadData(covariates, settings);
|
final List<Row<Double>> data = Main.loadData(covariates, settings);
|
||||||
|
|
||||||
assertEquals(3, data.size());
|
assertEquals(4, data.size());
|
||||||
|
|
||||||
Row<Double> row = data.get(0);
|
Row<Double> row = data.get(0);
|
||||||
assertEquals(5.0, (double)row.getResponse());
|
assertEquals(5.0, (double)row.getResponse());
|
||||||
|
@ -61,6 +62,12 @@ public class TestLoadingCSV {
|
||||||
assertEquals("cat", row.getCovariateValue("x2").getValue());
|
assertEquals("cat", row.getCovariateValue("x2").getValue());
|
||||||
assertEquals(true, row.getCovariateValue("x3").getValue());
|
assertEquals(true, row.getCovariateValue("x3").getValue());
|
||||||
|
|
||||||
|
row = data.get(3);
|
||||||
|
assertEquals(-3.0, (double)row.getResponse());
|
||||||
|
assertEquals(true, row.getCovariateValue("x1").isNA());
|
||||||
|
assertEquals(true, row.getCovariateValue("x2").isNA());
|
||||||
|
assertEquals(true, row.getCovariateValue("x3").isNA());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,3 +2,4 @@ y,x1,x2,x3
|
||||||
5,3.0,"mouse",true
|
5,3.0,"mouse",true
|
||||||
2,1.0,"dog",false
|
2,1.0,"dog",false
|
||||||
9,1.5,"cat",true
|
9,1.5,"cat",true
|
||||||
|
-3,NA,NA,NA
|
|
Loading…
Reference in a new issue