MCPcopy Create free account
hub / github.com/apache/pig / testSIZE

Method testSIZE

test/org/apache/pig/test/TestBuiltin.java:2506–2578  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2504 }
2505
2506 @Test
2507 public void testSIZE() throws Exception {
2508
2509 // DataByteArray size
2510 byte[] a = {1,2,3};
2511 DataByteArray dba = new DataByteArray(a);
2512 Long expected = new Long(3);
2513 Tuple t = TupleFactory.getInstance().newTuple(1);
2514 t.set(0, dba);
2515 EvalFunc<Long> size = new SIZE();
2516 String msg = "[Testing SIZE on input type: bytearray]";
2517 assertTrue(msg, expected.equals(size.exec(t)));
2518
2519 // String size
2520 String s = "Unit test case";
2521 expected = new Long(14);
2522 t.set(0, s);
2523 size = new StringSize();
2524 msg = "[Testing StringSize on input type: String]";
2525 assertTrue(msg, expected.equals(size.exec(t)));
2526
2527 // Map size
2528 String[] mapContents = new String[]{"key1", "value1", "key2", "value2"};
2529 Map<String, Object> map = Util.createMap(mapContents);
2530 expected = new Long(2);
2531 t.set(0, map);
2532 size = new MapSize();
2533 msg = "[Testing MapSize on input type: Map]";
2534 assertTrue(msg, expected.equals(size.exec(t)));
2535
2536 // Bag size
2537 Tuple t1 = Util.createTuple(new String[]{"a", "b", "c"});
2538 Tuple t2 = Util.createTuple(new String[]{"d", "e", "f"});
2539 Tuple t3 = Util.createTuple(new String[]{"g", "h", "i"});
2540 Tuple t4 = Util.createTuple(new String[]{"j", "k", "l"});
2541 DataBag b = Util.createBag(new Tuple[]{t1, t2, t3, t4});
2542 expected = new Long(4);
2543 t.set(0, b);
2544 size = new BagSize();
2545 msg = "[Testing BagSize on input type: Bag]";
2546 assertTrue(msg, expected.equals(size.exec(t)));
2547
2548
2549 // Tuple size
2550 Tuple suspect = Util.createTuple(new String[]{"key1", "str1"});
2551 size = new TupleSize();
2552 msg = "[Testing TupleSize on input type: Tuple]";
2553 expected = new Long(2);
2554 Tuple suspectStuffer = TupleFactory.getInstance().newTuple(1);
2555 suspectStuffer.set(0, suspect);
2556 assertTrue(msg, expected.equals(size.exec(suspectStuffer)));
2557
2558 // Tuple size again
2559 int expectedSize = 4;
2560 Tuple suspect2 = TupleFactory.getInstance().newTuple(expectedSize);
2561 suspect2.set(0, a);
2562 suspect2.set(1, s);
2563 suspect2.set(2, b);

Callers

nothing calls this directly

Calls 9

getInstanceMethod · 0.95
setMethod · 0.95
execMethod · 0.95
createMapMethod · 0.95
createTupleMethod · 0.95
createBagMethod · 0.95
execMethod · 0.95
newTupleMethod · 0.65
equalsMethod · 0.45

Tested by

no test coverage detected