byte[] a = {1,2,3};
DataByteArray dba = new DataByteArray(a);
Long expected = new Long(3);
Tuple t = TupleFactory.getInstance().newTuple(1);
t.set(0, dba);
EvalFunc<Long> size = new SIZE();
String msg = "[Testing SIZE on input type: bytearray]";
assertTrue(msg, expected.equals(size.exec(t)));
// String size
String s = "Unit test case";
expected = new Long(14);
t.set(0, s);
size = new StringSize();
msg = "[Testing StringSize on input type: String]";
assertTrue(msg, expected.equals(size.exec(t)));
// Map size
String[] mapContents = new String[]{"key1", "value1", "key2", "value2"};
Map<String, Object> map = Util.createMap(mapContents);
expected = new Long(2);
t.set(0, map);
size = new MapSize();
msg = "[Testing MapSize on input type: Map]";
assertTrue(msg, expected.equals(size.exec(t)));
// Bag size
Tuple t1 = Util.createTuple(new String[]{"a", "b", "c"});
Tuple t2 = Util.createTuple(new String[]{"d", "e", "f"});
Tuple t3 = Util.createTuple(new String[]{"g", "h", "i"});
Tuple t4 = Util.createTuple(new String[]{"j", "k", "l"});
DataBag b = Util.createBag(new Tuple[]{t1, t2, t3, t4});
expected = new Long(4);
t.set(0, b);
size = new BagSize();
msg = "[Testing BagSize on input type: Bag]";
assertTrue(msg, expected.equals(size.exec(t)));
// Tuple size
Tuple suspect = Util.createTuple(new String[]{"key1", "str1"});
size = new TupleSize();
msg = "[Testing TupleSize on input type: Tuple]";
expected = new Long(2);
Tuple suspectStuffer = TupleFactory.getInstance().newTuple(1);
suspectStuffer.set(0, suspect);
assertTrue(msg, expected.equals(size.exec(suspectStuffer)));
// Tuple size again
int expectedSize = 4;
Tuple suspect2 = TupleFactory.getInstance().newTuple(expectedSize);
suspect2.set(0, a);
suspect2.set(1, s);
suspect2.set(2, b);
suspect2.set(3, suspect);
expected = new Long(expectedSize);
size = new TupleSize();
msg = "[Testing TupleSize on input type: Tuple]";
suspectStuffer.set(0, suspect2);
assertTrue(msg, expected.equals(size.exec(suspectStuffer)));
// Test for ARITY function.
// It is depricated but we still need to make sure it works
ARITY arrity = new ARITY();