bug 61727: CellRangeUtil Merge cell ranges broken. Thanks for Sven Rieckhoff for the patch
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1814432 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ba7c278a0e
commit
047dcc60ca
@ -118,6 +118,7 @@ public final class CellRangeUtil {
|
||||
}
|
||||
somethingGotMerged = true;
|
||||
// overwrite range1 with first result
|
||||
range1 = mergeResult[0];
|
||||
cellRangeList.set(i, mergeResult[0]);
|
||||
// remove range2
|
||||
cellRangeList.remove(j--);
|
||||
|
69
src/testcases/org/apache/poi/ss/util/TestCellRangeUtil.java
Normal file
69
src/testcases/org/apache/poi/ss/util/TestCellRangeUtil.java
Normal file
@ -0,0 +1,69 @@
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.ss.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
/**
|
||||
* Tests CellRangeUtil.
|
||||
*
|
||||
* @see org.apache.poi.ss.util.CellRangeUtil
|
||||
*/
|
||||
public final class TestCellRangeUtil {
|
||||
|
||||
private static final CellRangeAddress A1 = new CellRangeAddress(0, 0, 0, 0);
|
||||
private static final CellRangeAddress B1 = new CellRangeAddress(0, 0, 1, 1);
|
||||
private static final CellRangeAddress A2 = new CellRangeAddress(1, 1, 0, 0);
|
||||
private static final CellRangeAddress B2 = new CellRangeAddress(1, 1, 1, 1);
|
||||
|
||||
@Test
|
||||
public void testMergeCellRanges() {
|
||||
testMergeCellRange(asArray(A1, B1, A2, B2), 1);
|
||||
// suboptimal result for permuted arguments (2 ranges instead of one)
|
||||
testMergeCellRange(asArray(A1, B2, A2, A1), 2);
|
||||
|
||||
testMergeCellRange(asArray(A1, B1, A2), 2);
|
||||
testMergeCellRange(asArray(A2, A1, B1), 2);
|
||||
testMergeCellRange(asArray(B1, A2, A1), 2);
|
||||
|
||||
testMergeCellRange(asArray(A1, B2), 2);
|
||||
testMergeCellRange(asArray(B2, A1), 2);
|
||||
}
|
||||
|
||||
private void testMergeCellRange(CellRangeAddress[] input, int expectedResultRangeLength) {
|
||||
CellRangeAddress[] result = CellRangeUtil.mergeCellRanges( input );
|
||||
assertEquals( expectedResultRangeLength, result.length );
|
||||
assertResultExactlyContainsInput(result, result);
|
||||
}
|
||||
|
||||
private static void assertResultExactlyContainsInput(CellRangeAddress[] result, CellRangeAddress[] input) {
|
||||
for(CellRangeAddress inputEntry: input) {
|
||||
boolean isInResultRange = false;
|
||||
for(CellRangeAddress resultEntry: result) {
|
||||
isInResultRange |= resultEntry.intersects(inputEntry);
|
||||
}
|
||||
assumeTrue(isInResultRange);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> T[] asArray(T...ts) {
|
||||
return ts;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user