()
| 1049 | } |
| 1050 | |
| 1051 | @Test |
| 1052 | public void testAVGFinal() throws Exception { |
| 1053 | String[] avgTypes = {"AVGFinal", "DoubleAvgFinal", "LongAvgFinal", "IntAvgFinal", "FloatAvgFinal", "BigDecimalAvgFinal", "BigIntegerAvgFinal"}; |
| 1054 | String[] avgIntermediateTypes = {"AVGIntermediate", "DoubleAvgIntermediate", "LongAvgIntermediate", "IntAvgIntermediate", "FloatAvgIntermediate", |
| 1055 | "BigDecimalAvgIntermediate", "BigIntegerAvgIntermediate"}; |
| 1056 | for (int k = 0; k < avgTypes.length; k++) { |
| 1057 | EvalFunc<?> avg = evalFuncMap.get(avgTypes[k]); |
| 1058 | Tuple tup = inputMap.get(getInputType(avgTypes[k])); |
| 1059 | |
| 1060 | // To test AVGFinal, AVGIntermediate should first be called and |
| 1061 | // the output of AVGIntermediate should be supplied as input to |
| 1062 | // AVGFinal. To simulate this, we will call Intermediate twice |
| 1063 | // on the above tuple and collect the outputs and pass it to |
| 1064 | // Final. |
| 1065 | |
| 1066 | // get the right "Intermediate" EvalFunc |
| 1067 | EvalFunc<?> avgIntermediate = evalFuncMap.get(avgIntermediateTypes[k]); |
| 1068 | // The tuple we got above has a bag with input |
| 1069 | // values. Input to the Intermediate.exec() however comes |
| 1070 | // from the map which would put each value and a count of |
| 1071 | // 1 in a tuple and send it down. So lets create a bag with |
| 1072 | // tuples that have two fields - the value and a count 1. |
| 1073 | // The input has 10 values - lets put the first five of them |
| 1074 | // in the input to the first call of AVGIntermediate and the |
| 1075 | // remaining five in the second call. |
| 1076 | DataBag bg = (DataBag) tup.get(0); |
| 1077 | DataBag bg1 = bagFactory.newDefaultBag(); |
| 1078 | DataBag bg2 = bagFactory.newDefaultBag(); |
| 1079 | int i = 0; |
| 1080 | for (Tuple t: bg) { |
| 1081 | Tuple newTuple = tupleFactory.newTuple(2); |
| 1082 | newTuple.set(0, t.get(0)); |
| 1083 | if ( t.get(0) == null) { |
| 1084 | if (getInputType(avgTypes[k]) == "BigDecimal") { |
| 1085 | newTuple.set(1, BigDecimal.ZERO); |
| 1086 | } else if (getInputType(avgTypes[k]) == "BigInteger") { |
| 1087 | newTuple.set(1, BigInteger.ZERO); |
| 1088 | } else { |
| 1089 | newTuple.set(1, new Long(0)); |
| 1090 | } |
| 1091 | } else { |
| 1092 | if (getInputType(avgTypes[k]) == "BigDecimal") { |
| 1093 | newTuple.set(1, BigDecimal.ONE); |
| 1094 | } else if (getInputType(avgTypes[k]) == "BigInteger") { |
| 1095 | newTuple.set(1, BigInteger.ONE); |
| 1096 | } else { |
| 1097 | newTuple.set(1, new Long(1)); |
| 1098 | } |
| 1099 | } |
| 1100 | if (i < 5) { |
| 1101 | bg1.add(newTuple); |
| 1102 | } else { |
| 1103 | bg2.add(newTuple); |
| 1104 | } |
| 1105 | i++; |
| 1106 | } |
| 1107 | Tuple intermediateInput1 = tupleFactory.newTuple(); |
| 1108 | intermediateInput1.append(bg1); |
nothing calls this directly
no test coverage detected