xor can also accept 2+ params, rewrite tests to be consistent
This commit is contained in:
parent
4ea0f440e9
commit
909df1b6a7
@ -38,10 +38,10 @@ public class Xor implements Function {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object call(Properties bindings, Object[] args) {
|
public Object call(Properties bindings, Object[] args) {
|
||||||
if (args.length == 2 && args[0] instanceof Boolean && args[1] instanceof Boolean) {
|
if (args.length >= 2 && args[0] instanceof Boolean && args[1] instanceof Boolean) {
|
||||||
return (Boolean) args[0] ^ (Boolean) args[1];
|
return (Boolean) args[0] ^ (Boolean) args[1];
|
||||||
}
|
}
|
||||||
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 booleans");
|
return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 or more booleans");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,7 +50,7 @@ public class Xor implements Function {
|
|||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("description");
|
writer.key("description");
|
||||||
writer.value("XORs two boolean values");
|
writer.value("XORs two or more boolean values");
|
||||||
writer.key("params");
|
writer.key("params");
|
||||||
writer.value("boolean a, boolean b");
|
writer.value("boolean a, boolean b");
|
||||||
writer.key("returns");
|
writer.key("returns");
|
||||||
|
@ -66,20 +66,20 @@ import com.google.refine.tests.util.TestUtils;
|
|||||||
public class BooleanTests extends RefineTest {
|
public class BooleanTests extends RefineTest {
|
||||||
|
|
||||||
private static String TRUTH_TABLE[][] = {
|
private static String TRUTH_TABLE[][] = {
|
||||||
{"and","true","true","true"},
|
{"and","true","true","true","true"},
|
||||||
{"and","false","false","false"},
|
{"and","false","false","false","false"},
|
||||||
{"and","true","false","false"},
|
{"and","true","false","false","false"},
|
||||||
{"and","false","true","false"},
|
{"and","false","true","true","false"},
|
||||||
|
|
||||||
{"or","true","true","true"},
|
{"or","true","true","true","true"},
|
||||||
{"or","false","false","false"},
|
{"or","false","false","false","false"},
|
||||||
{"or","true","false","true"},
|
{"or","true","false","false","true"},
|
||||||
{"or","false","true","true"},
|
{"or","false","true","true","true"},
|
||||||
|
|
||||||
{"xor","true","true","false"},
|
{"xor","true","true","true","false"},
|
||||||
{"xor","false","false","false"},
|
{"xor","false","false","false","false"},
|
||||||
{"xor","true","false","true"},
|
{"xor","true","false","false","true"},
|
||||||
{"xor","false","true","true"},
|
{"xor","false","true","false","true"},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -155,7 +155,6 @@ public class BooleanTests extends RefineTest {
|
|||||||
Assert.assertTrue(invoke(op, "foo", Boolean.TRUE) instanceof EvalError);
|
Assert.assertTrue(invoke(op, "foo", Boolean.TRUE) instanceof EvalError);
|
||||||
Assert.assertTrue(invoke(op, Boolean.TRUE) instanceof EvalError);
|
Assert.assertTrue(invoke(op, Boolean.TRUE) instanceof EvalError);
|
||||||
}
|
}
|
||||||
Assert.assertTrue(invoke("xor", Boolean.TRUE, Boolean.TRUE, Boolean.TRUE) instanceof EvalError);
|
|
||||||
String op = "not";
|
String op = "not";
|
||||||
Assert.assertTrue(invoke(op) instanceof EvalError);
|
Assert.assertTrue(invoke(op) instanceof EvalError);
|
||||||
Assert.assertTrue(invoke(op, Boolean.TRUE, Boolean.TRUE) instanceof EvalError);
|
Assert.assertTrue(invoke(op, Boolean.TRUE, Boolean.TRUE) instanceof EvalError);
|
||||||
@ -169,8 +168,9 @@ public class BooleanTests extends RefineTest {
|
|||||||
String operator = test[0];
|
String operator = test[0];
|
||||||
Boolean op1 = Boolean.valueOf(test[1]);
|
Boolean op1 = Boolean.valueOf(test[1]);
|
||||||
Boolean op2 = Boolean.valueOf(test[2]);
|
Boolean op2 = Boolean.valueOf(test[2]);
|
||||||
Boolean result = Boolean.valueOf(test[3]);
|
Boolean op3 = Boolean.valueOf(test[3]);
|
||||||
Assert.assertEquals(invoke(operator, op1, op2),result);
|
Boolean result = Boolean.valueOf(test[4]);
|
||||||
|
Assert.assertEquals(invoke(operator, op1, op2, op3),result);
|
||||||
}
|
}
|
||||||
Assert.assertEquals(invoke("not", Boolean.TRUE),Boolean.FALSE);
|
Assert.assertEquals(invoke("not", Boolean.TRUE),Boolean.FALSE);
|
||||||
Assert.assertEquals(invoke("not", Boolean.FALSE),Boolean.TRUE);
|
Assert.assertEquals(invoke("not", Boolean.FALSE),Boolean.TRUE);
|
||||||
|
Loading…
Reference in New Issue
Block a user