01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
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: */
17: /*
18: * Created on May 29, 2005
19: *
20: */
21: package org.apache.poi.hssf.record.formula.functions;
22:
23: import junit.framework.TestCase;
24:
25: /**
26: * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
27: *
28: */
29: public abstract class AbstractNumericTestCase extends TestCase {
30:
31: public static final double POS_ZERO = 1E-4;
32: public static final double DIFF_TOLERANCE_FACTOR = 1E-8;
33:
34: public void setUp() {
35: }
36:
37: public void tearDown() {
38: }
39:
40: /**
41: * Why doesnt JUnit have a method like this for doubles?
42: * The current impl (3.8.1) of Junit has a retar*** method
43: * for comparing doubles. DO NOT use that.
44: * TODO: This class should really be in an abstract super class
45: * to avoid code duplication across this project.
46: * @param message
47: * @param baseval
48: * @param checkval
49: */
50: public static void assertEquals(String message, double baseval,
51: double checkval, double almostZero,
52: double diffToleranceFactor) {
53: double posZero = Math.abs(almostZero);
54: double negZero = -1 * posZero;
55: if (Double.isNaN(baseval)) {
56: assertTrue(message + ": Expected " + baseval + " but was "
57: + checkval, Double.isNaN(baseval));
58: } else if (Double.isInfinite(baseval)) {
59: assertTrue(message + ": Expected " + baseval + " but was "
60: + checkval, Double.isInfinite(baseval)
61: && ((baseval < 0) == (checkval < 0)));
62: } else {
63: assertTrue(message + ": Expected " + baseval + " but was "
64: + checkval, baseval != 0 ? Math.abs(baseval
65: - checkval) <= Math.abs(diffToleranceFactor
66: * baseval) : checkval < posZero
67: && checkval > negZero);
68: }
69: }
70:
71: public static void assertEquals(String msg, double baseval,
72: double checkval) {
73: assertEquals(msg, baseval, checkval, POS_ZERO,
74: DIFF_TOLERANCE_FACTOR);
75: }
76:
77: }
|