Merge several bug tests into one file
[poi.git] / src / scratchpad / testcases / org / apache / poi / hssf / record / formula / functions / TestAverage.java
blob4f0e5fff2cf93d95cb199630ec4e333286969d04
1 /* ====================================================================
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 ==================================================================== */
18 package org.apache.poi.hssf.record.formula.functions;
20 import junit.framework.TestCase;
22 import org.apache.poi.hssf.record.formula.eval.BlankEval;
23 import org.apache.poi.hssf.record.formula.eval.BoolEval;
24 import org.apache.poi.hssf.record.formula.eval.ErrorEval;
25 import org.apache.poi.hssf.record.formula.eval.Eval;
26 import org.apache.poi.hssf.record.formula.eval.NumberEval;
27 import org.apache.poi.hssf.record.formula.eval.ValueEval;
28 /**
29 * Tests for Excel function AVERAGE()
31 * @author Josh Micich
33 public final class TestAverage extends TestCase {
36 private static Eval invokeAverage(Eval[] args) {
37 return new Average().evaluate(args, -1, (short)-1);
40 private void confirmAverage(Eval[] args, double expected) {
41 Eval result = invokeAverage(args);
42 assertEquals(NumberEval.class, result.getClass());
43 assertEquals(expected, ((NumberEval)result).getNumberValue(), 0);
46 private void confirmAverage(Eval[] args, ErrorEval expectedError) {
47 Eval result = invokeAverage(args);
48 assertEquals(ErrorEval.class, result.getClass());
49 assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
52 public void testBasic() {
54 ValueEval[] values = {
55 new NumberEval(1),
56 new NumberEval(2),
57 new NumberEval(3),
58 new NumberEval(4),
61 confirmAverage(values, 2.5);
63 values = new ValueEval[] {
64 new NumberEval(1),
65 new NumberEval(2),
66 BlankEval.INSTANCE,
67 new NumberEval(3),
68 BlankEval.INSTANCE,
69 new NumberEval(4),
70 BlankEval.INSTANCE,
73 confirmAverage(values, 2.5);
76 /**
77 * Valid cases where values are not pure numbers
79 public void testUnusualArgs() {
80 ValueEval[] values = {
81 new NumberEval(1),
82 new NumberEval(2),
83 BoolEval.TRUE,
84 BoolEval.FALSE,
87 confirmAverage(values, 1.0);
91 // currently disabled because MultiOperandNumericFunction.getNumberArray(Eval[], int, short)
92 // does not handle error values properly yet
93 public void XtestErrors() {
94 ValueEval[] values = {
95 new NumberEval(1),
96 ErrorEval.NAME_INVALID,
97 new NumberEval(3),
98 ErrorEval.DIV_ZERO,
100 confirmAverage(values, ErrorEval.NAME_INVALID);