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
;
29 * Tests for Excel function AVERAGE()
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
= {
61 confirmAverage(values
, 2.5);
63 values
= new ValueEval
[] {
73 confirmAverage(values
, 2.5);
77 * Valid cases where values are not pure numbers
79 public void testUnusualArgs() {
80 ValueEval
[] values
= {
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
= {
96 ErrorEval
.NAME_INVALID
,
100 confirmAverage(values
, ErrorEval
.NAME_INVALID
);