Line 0
Link Here
|
|
|
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 |
8 |
|
9 |
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 |
package org.apache.poi.ss.formula.eval; |
19 |
|
20 |
import org.apache.poi.ss.usermodel.ArrayFormulaTestHelper; |
21 |
|
22 |
import junit.framework.TestCase; |
23 |
|
24 |
public abstract class BaseTestArrayFormulaEvaluation extends TestCase { |
25 |
|
26 |
protected abstract ArrayFormulaTestHelper th(); |
27 |
private ArrayFormulaTestHelper _th; |
28 |
|
29 |
protected void setUp() { |
30 |
_th = th(); |
31 |
} |
32 |
|
33 |
public final void testNumericSquareArrayFormula() { |
34 |
// Clean cell's values before calculation |
35 |
_th.setNumericValue("C4", 0); |
36 |
_th.setNumericValue("D4", 0); |
37 |
_th.setNumericValue("C5", 0); |
38 |
_th.setNumericValue("D5", 0); |
39 |
|
40 |
assertEquals("C4-F4",_th.getNumericValue("F4"), _th.calculateNumericFormula("C4"), 0); |
41 |
assertEquals("D4-G4",_th.getNumericValue("G4"), _th.calculateNumericFormula("D4"), 0); |
42 |
assertEquals("C5-F5",_th.getNumericValue("F5"), _th.calculateNumericFormula("C5"), 0); |
43 |
assertEquals("D5-G5",_th.getNumericValue("G5"), _th.calculateNumericFormula("D5"), 0); |
44 |
} |
45 |
|
46 |
public final void testNumericArrayFormulaWORange() { |
47 |
|
48 |
// Clean cell's values before calculation |
49 |
_th.setNumericValue("C7", 0); |
50 |
|
51 |
assertEquals("C7-F7",_th.getNumericValue("F7"), _th.calculateNumericFormula("C7"), 0); |
52 |
} |
53 |
|
54 |
public final void testNumericArrayFormulaFullRow() { |
55 |
|
56 |
// Clean cell's values before calculation |
57 |
_th.setNumericValue("A9", 0); |
58 |
_th.setNumericValue("B9", 0); |
59 |
_th.setNumericValue("C9", 0); |
60 |
assertEquals("A9-F9",_th.getNumericValue("F9"), _th.calculateNumericFormula("A9"), 0); |
61 |
assertEquals("B9-G9",_th.getNumericValue("G9"), _th.calculateNumericFormula("B9"), 0); |
62 |
assertEquals("C9-H9",_th.getNumericValue("H9"), _th.calculateNumericFormula("C9"), 0); |
63 |
} |
64 |
|
65 |
public final void testNumericArrayFormulaSmallRow() { |
66 |
|
67 |
// Clean cell's values before calculation |
68 |
_th.setNumericValue("A11", 0); |
69 |
_th.setNumericValue("B11", 0); |
70 |
assertEquals("A11-F11",_th.getNumericValue("F11"), _th.calculateNumericFormula("A11"), 0); |
71 |
assertEquals("B11-G11",_th.getNumericValue("G11"), _th.calculateNumericFormula("B11"), 0); |
72 |
} |
73 |
|
74 |
public final void testNumericArrayFormulaBigRow() { |
75 |
|
76 |
// Clean cell's values before calculation |
77 |
_th.setNumericValue("A13", 0); |
78 |
_th.setNumericValue("B13", 0); |
79 |
_th.setNumericValue("C13", 0); |
80 |
|
81 |
assertEquals("A13-F13",_th.getNumericValue("F13"), _th.calculateNumericFormula("A13"), 0); |
82 |
assertEquals("B13-G13",_th.getNumericValue("G13"), _th.calculateNumericFormula("B13"), 0); |
83 |
assertEquals("C13-H13",_th.getNumericValue("H13"), _th.calculateNumericFormula("C13"), 0); |
84 |
assertEquals("D3-I13",_th.getErrorValue("I13"), _th.calculateNumericFormulaWithError("D13").getString()); |
85 |
} |
86 |
|
87 |
public final void testNumericArrayFormulaFewerRows() { |
88 |
|
89 |
// Clean cell's values before calculation |
90 |
_th.setNumericValue("A16", 0); |
91 |
_th.setNumericValue("B16", 0); |
92 |
_th.setNumericValue("A17", 0); |
93 |
_th.setNumericValue("B17", 0); |
94 |
|
95 |
assertEquals("A16-F16",_th.getNumericValue("F16"), _th.calculateNumericFormula("A16"), 0); |
96 |
assertEquals("B16-G16",_th.getNumericValue("G16"), _th.calculateNumericFormula("B16"), 0); |
97 |
assertEquals("A17-F17",_th.getNumericValue("F17"), _th.calculateNumericFormula("A17"), 0); |
98 |
assertEquals("B17-G17",_th.getNumericValue("G17"), _th.calculateNumericFormula("B17"), 0); |
99 |
} |
100 |
|
101 |
public final void testNumericArrayFormulaDataExceed() { |
102 |
// Clean cell's values before calculation |
103 |
_th.setNumericValue("A19", 0); |
104 |
_th.setNumericValue("B19", 0); |
105 |
_th.setNumericValue("A20", 0); |
106 |
_th.setNumericValue("B20", 0); |
107 |
|
108 |
assertEquals("A19-F19",_th.getNumericValue("F19"), _th.calculateNumericFormula("A19"), 0); |
109 |
assertEquals("B19-G19",_th.getNumericValue("G19"), _th.calculateNumericFormula("B19"), 0); |
110 |
assertEquals("A20-F20",_th.getNumericValue("F20"), _th.calculateNumericFormula("A20"), 0); |
111 |
assertEquals("B20-G20",_th.getNumericValue("G20"), _th.calculateNumericFormula("B20"), 0); |
112 |
} |
113 |
|
114 |
public final void testNumericArrayFormulaCol4Row() { |
115 |
|
116 |
// Clean cell's values before calculation |
117 |
_th.setNumericValue("A22", 0); |
118 |
_th.setNumericValue("A23", 0); |
119 |
_th.setNumericValue("A24", 0); |
120 |
_th.setNumericValue("A25", 0); |
121 |
|
122 |
assertEquals("A22-F22",_th.getNumericValue("F22"), _th.calculateNumericFormula("A22"), 0); |
123 |
assertEquals("A23-F23",_th.getNumericValue("F23"), _th.calculateNumericFormula("A23"), 0); |
124 |
assertEquals("A24-F24",_th.getNumericValue("F24"), _th.calculateNumericFormula("A24"), 0); |
125 |
assertEquals("A25-F25",_th.getNumericValue("F25"), _th.calculateNumericFormula("A25"), 0); |
126 |
} |
127 |
|
128 |
public final void testNumericArrayFormulaRow4Col() { |
129 |
|
130 |
// Clean cell's values before calculation |
131 |
_th.setNumericValue("A27", 0); |
132 |
_th.setNumericValue("B27", 0); |
133 |
_th.setNumericValue("C27", 0); |
134 |
_th.setNumericValue("D27", 0); |
135 |
|
136 |
assertEquals("A27-F27",_th.getNumericValue("F27"), _th.calculateNumericFormula("A27"), 0); |
137 |
assertEquals("B27-G27",_th.getNumericValue("G27"), _th.calculateNumericFormula("B27"), 0); |
138 |
assertEquals("C27-H27",_th.getNumericValue("H27"), _th.calculateNumericFormula("C27"), 0); |
139 |
assertEquals("D27-I27",_th.getNumericValue("I27"), _th.calculateNumericFormula("D27"), 0); |
140 |
} |
141 |
|
142 |
public final void testNumericArrayFormulaDataRow4Col() { |
143 |
|
144 |
// Clean cell's values before calculation |
145 |
_th.setNumericValue("A27", 0); |
146 |
_th.setNumericValue("B27", 0); |
147 |
_th.setNumericValue("C27", 0); |
148 |
_th.setNumericValue("D27", 0); |
149 |
|
150 |
assertEquals("A27-F27",_th.getNumericValue("F27"), _th.calculateNumericFormula("A27"), 0); |
151 |
assertEquals("B27-G27",_th.getNumericValue("G27"), _th.calculateNumericFormula("B27"), 0); |
152 |
assertEquals("C27-H27",_th.getNumericValue("H27"), _th.calculateNumericFormula("C27"), 0); |
153 |
assertEquals("D27-I27",_th.getNumericValue("I27"), _th.calculateNumericFormula("D27"), 0); |
154 |
} |
155 |
|
156 |
public final void testNumericArrayFormulaDataShortage() { |
157 |
|
158 |
// Clean cell's values before calculation |
159 |
_th.setNumericValue("B30", 0); |
160 |
_th.setNumericValue("C30", 0); |
161 |
_th.setNumericValue("D30", 0); |
162 |
_th.setNumericValue("B31", 0); |
163 |
_th.setNumericValue("C31", 0); |
164 |
_th.setNumericValue("D31", 0); |
165 |
_th.setNumericValue("B32", 0); |
166 |
_th.setNumericValue("C32", 0); |
167 |
_th.setNumericValue("D32", 0); |
168 |
|
169 |
assertEquals("C30-G30",_th.getNumericValue("G30"), _th.calculateNumericFormula("C30"), 0); |
170 |
assertEquals("B30-F30",_th.getNumericValue("F30"), _th.calculateNumericFormula("B30"), 0); |
171 |
if (false) { // TODO - fix this |
172 |
assertEquals("C30-G30", _th.getNumericValue("G30"), _th.getNumericValue("C30"), 0); |
173 |
} |
174 |
assertEquals("B31-G30",_th.getNumericValue("F31"), _th.calculateNumericFormula("B31"), 0); |
175 |
assertEquals("C31-G31",_th.getNumericValue("G31"), _th.calculateNumericFormula("C31"), 0); |
176 |
assertEquals("D30-H30",_th.getErrorValue("H30"), _th.calculateNumericFormulaWithError("D30").getString()); |
177 |
assertEquals("D31-H31",_th.getErrorValue("H31"), _th.calculateNumericFormulaWithError("D31").getString()); |
178 |
|
179 |
assertEquals("B32-F32",_th.getErrorValue("F32"), _th.calculateNumericFormulaWithError("B32").getString()); |
180 |
assertEquals("C32-G32",_th.getErrorValue("G32"), _th.calculateNumericFormulaWithError("C32").getString()); |
181 |
assertEquals("D32-H32",_th.getErrorValue("H32"), _th.calculateNumericFormulaWithError("D32").getString()); |
182 |
} |
183 |
|
184 |
public final void testNumericArrayFormulaRefArguments() { |
185 |
|
186 |
// Clean cell's values before calculation |
187 |
_th.setNumericValue("A37", 0); |
188 |
_th.setNumericValue("B37", 0); |
189 |
_th.setNumericValue("C37", 0); |
190 |
|
191 |
assertEquals("A37-F37",_th.getNumericValue("F37"), _th.calculateNumericFormula("A37"), 0); |
192 |
assertEquals("B37-G37",_th.getNumericValue("G37"), _th.calculateNumericFormula("B37"), 0); |
193 |
assertEquals("C37-H37",_th.getNumericValue("H37"), _th.calculateNumericFormula("C37"), 0); |
194 |
} |
195 |
|
196 |
public final void testNumericArrayFormulasRefArguments() { |
197 |
|
198 |
// Clean cell's values before calculation |
199 |
_th.setNumericValue("A40", 0); |
200 |
_th.setNumericValue("B40", 0); |
201 |
_th.setNumericValue("C40", 0); |
202 |
|
203 |
assertEquals("A40-F40",_th.getNumericValue("F40"), _th.calculateNumericFormula("A40"), 0); |
204 |
assertEquals("B40-G40",_th.getNumericValue("G40"), _th.calculateNumericFormula("B40"), 0); |
205 |
assertEquals("C40-H40",_th.getNumericValue("H40"), _th.calculateNumericFormula("C40"), 0); |
206 |
} |
207 |
|
208 |
public final void testNumericOperation4Range() { |
209 |
|
210 |
// Clean cell's values before calculation |
211 |
_th.setNumericValue("C43", 0); |
212 |
_th.setNumericValue("C44", 0); |
213 |
_th.setNumericValue("C45", 0); |
214 |
_th.setNumericValue("C46", 0); |
215 |
|
216 |
assertEquals("C43-F43",_th.getNumericValue("F43"), _th.calculateNumericFormula("C43"), 0); |
217 |
assertEquals("C44-F44",_th.getNumericValue("F44"), _th.calculateNumericFormula("C44"), 0); |
218 |
assertEquals("C45-F45",_th.getNumericValue("F45"), _th.calculateNumericFormula("C45"), 0); |
219 |
assertEquals("C46-F46",_th.getNumericValue("F46"), _th.calculateNumericFormula("C46"), 0); |
220 |
} |
221 |
|
222 |
public final void testNumericOperation4DiffRanges() { |
223 |
|
224 |
// Clean cell's values before calculation |
225 |
_th.setNumericValue("C48", 0); |
226 |
_th.setNumericValue("C49", 0); |
227 |
_th.setNumericValue("C50", 0); |
228 |
_th.setNumericValue("C51", 0); |
229 |
|
230 |
assertEquals("C48-F48",_th.getNumericValue("F48"), _th.calculateNumericFormula("C48"), 0); |
231 |
assertEquals("C49-F49",_th.getNumericValue("F49"), _th.calculateNumericFormula("C49"), 0); |
232 |
assertEquals("C50-F50",_th.getNumericValue("F50"), _th.calculateNumericFormula("C50"), 0); |
233 |
assertEquals("C51-F51",_th.getNumericValue("F51"), _th.calculateNumericFormula("C51"), 0); |
234 |
if (false) { // TODO - fix these |
235 |
assertEquals("C50-F50", _th.getErrorValue("F50"), _th.getErrorValue("C50")); |
236 |
assertEquals("C51-F51",_th.getErrorValue("F51"), _th.getErrorValue("C51")); |
237 |
} |
238 |
} |
239 |
|
240 |
public final void testNumericArrayChangeRefArguments() { |
241 |
|
242 |
// Clean cell's values before calculation |
243 |
_th.setNumericValue("A40", 0); |
244 |
_th.setNumericValue("B40", 0); |
245 |
_th.setNumericValue("C40", 0); |
246 |
|
247 |
assertEquals("A40-F40", _th.getNumericValue("F40"), _th.calculateNumericFormula("A40"), 0); |
248 |
assertEquals("B40-G40", _th.getNumericValue("G40"), _th.calculateNumericFormula("B40"), 0); |
249 |
assertEquals("C40-H40", _th.getNumericValue("H40"), _th.calculateNumericFormula("C40"), 0); |
250 |
|
251 |
_th.setNumericValue("A41", 0.4); |
252 |
_th.setNumericValue("B41", 0.5); |
253 |
_th.setNumericValue("C41", 0.6); |
254 |
|
255 |
assertEquals("B40-G40", Math.cos(Math.sin(0.5)), _th.calculateNumericFormula("B40"), 0); |
256 |
assertEquals("A40-F40", Math.cos(Math.sin(0.4)), _th.calculateNumericFormula("A40"), 0); |
257 |
assertEquals("C40-H40", Math.cos(Math.sin(0.6)), _th.calculateNumericFormula("C40"), 0); |
258 |
} |
259 |
|
260 |
public final void testNumericArrayDifTypeArguments() { |
261 |
|
262 |
// Clean cell's values before calculation |
263 |
_th.setNumericValue("A54", 0); |
264 |
_th.setNumericValue("B54", 0); |
265 |
_th.setNumericValue("C54", 0); |
266 |
_th.setNumericValue("A55", 0); |
267 |
_th.setNumericValue("B55", 0); |
268 |
_th.setNumericValue("C55", 0); |
269 |
|
270 |
assertEquals("A54-F54",_th.getNumericValue("F54"), _th.calculateNumericFormula("A54"), 0); |
271 |
assertEquals("B54-G54",_th.getNumericValue("G54"), _th.calculateNumericFormula("B54"), 0); |
272 |
assertEquals("C54-H54",_th.getNumericValue("H54"), _th.calculateNumericFormula("C54"), 0); |
273 |
assertEquals("A55-F55",_th.getNumericValue("F55"), _th.calculateNumericFormula("A55"), 0); |
274 |
assertEquals("B55-G55",_th.getNumericValue("G55"), _th.calculateNumericFormula("B55"), 0); |
275 |
assertEquals("C55-H55",_th.getNumericValue("H55"), _th.calculateNumericFormula("C55"), 0); |
276 |
} |
277 |
} |