aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/ss
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2015-08-29 14:41:12 +0000
committerAndreas Beeker <kiwiwings@apache.org>2015-08-29 14:41:12 +0000
commitebdbe8b97ab92fd16bbd687b2b3662d252ef57d6 (patch)
tree90f352484ed4d1bdff0755c8c33f6bcce9d46ec2 /src/testcases/org/apache/poi/ss
parent7b5bd4a7f67ce324620153ead02d7bfc90348806 (diff)
downloadpoi-ebdbe8b97ab92fd16bbd687b2b3662d252ef57d6.tar.gz
poi-ebdbe8b97ab92fd16bbd687b2b3662d252ef57d6.zip
- reworked HexDump class - unified array dumps and usage of standard java calls for hex format
- fixed a few findbugs DM_DEFAULT_ENCODING issues - removed a few System.out/.err calls - instead the poilogger is used - closed a few left open resource instances git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1700040 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/ss')
-rw-r--r--src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java2
-rw-r--r--src/testcases/org/apache/poi/ss/util/NumberComparingSpreadsheetGenerator.java4
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java19
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestNumberComparer.java27
4 files changed, 28 insertions, 24 deletions
diff --git a/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java b/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java
index 1ee9b45a8c..7500be57e4 100644
--- a/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java
+++ b/src/testcases/org/apache/poi/ss/formula/eval/TestMinusZeroResult.java
@@ -142,7 +142,7 @@ public final class TestMinusZeroResult extends TestCase {
long bitsB = Double.doubleToLongBits(b);
if (bitsA != bitsB) {
throw new ComparisonFailure("value different to expected",
- new String(HexDump.longToHex(bitsA)), new String(HexDump.longToHex(bitsB)));
+ HexDump.longToHex(bitsA), HexDump.longToHex(bitsB));
}
}
}
diff --git a/src/testcases/org/apache/poi/ss/util/NumberComparingSpreadsheetGenerator.java b/src/testcases/org/apache/poi/ss/util/NumberComparingSpreadsheetGenerator.java
index d04bf402ec..d4f1ebb92f 100644
--- a/src/testcases/org/apache/poi/ss/util/NumberComparingSpreadsheetGenerator.java
+++ b/src/testcases/org/apache/poi/ss/util/NumberComparingSpreadsheetGenerator.java
@@ -125,9 +125,7 @@ public class NumberComparingSpreadsheetGenerator {
private static String formatDoubleAsHex(double d) {
long l = Double.doubleToLongBits(d);
- StringBuilder sb = new StringBuilder(20);
- sb.append(HexDump.longToHex(l)).append('L');
- return sb.toString();
+ return HexDump.longToHex(l)+'L';
}
public static void main(String[] args) {
diff --git a/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java b/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java
index dd524fdb86..d4d63192d0 100644
--- a/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java
+++ b/src/testcases/org/apache/poi/ss/util/TestExpandedDouble.java
@@ -17,21 +17,24 @@
package org.apache.poi.ss.util;
+import static org.junit.Assert.assertEquals;
+
import java.math.BigDecimal;
import java.math.BigInteger;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
import org.apache.poi.util.HexDump;
+import org.junit.Test;
+
+import junit.framework.AssertionFailedError;
/**
* Tests for {@link ExpandedDouble}
*
* @author Josh Micich
*/
-public final class TestExpandedDouble extends TestCase {
+public final class TestExpandedDouble {
private static final BigInteger BIG_POW_10 = BigInteger.valueOf(1000000000);
+ @Test
public void testNegative() {
ExpandedDouble hd = new ExpandedDouble(0xC010000000000000L);
@@ -44,6 +47,7 @@ public final class TestExpandedDouble extends TestCase {
assertEquals(1, frac.bitCount());
}
+ @Test
public void testSubnormal() {
ExpandedDouble hd = new ExpandedDouble(0x0000000000000001L);
@@ -59,6 +63,7 @@ public final class TestExpandedDouble extends TestCase {
/**
* Tests specific values for conversion from {@link ExpandedDouble} to {@link NormalisedDecimal} and back
*/
+ @Test
public void testRoundTripShifting() {
long[] rawValues = {
0x4010000000000004L,
@@ -87,6 +92,7 @@ public final class TestExpandedDouble extends TestCase {
throw new AssertionFailedError("One or more test examples failed. See stderr.");
}
}
+
public static boolean confirmRoundTrip(int i, long rawBitsA) {
double a = Double.longBitsToDouble(rawBitsA);
if (a == 0.0) {
@@ -150,6 +156,7 @@ public final class TestExpandedDouble extends TestCase {
}
return bd.unscaledValue().toString();
}
+
public static BigInteger getNearby(NormalisedDecimal md, int offset) {
BigInteger frac = md.composeFrac();
int be = frac.bitLength() - 24 - 1;
@@ -218,8 +225,6 @@ public final class TestExpandedDouble extends TestCase {
private static String formatDoubleAsHex(double d) {
long l = Double.doubleToLongBits(d);
- StringBuilder sb = new StringBuilder(20);
- sb.append(HexDump.longToHex(l)).append('L');
- return sb.toString();
+ return HexDump.longToHex(l)+'L';
}
}
diff --git a/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java b/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java
index 7c3d87e99a..506df67494 100644
--- a/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java
+++ b/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java
@@ -17,18 +17,21 @@
package org.apache.poi.ss.util;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import org.apache.poi.ss.util.NumberComparisonExamples.ComparisonExample;
import org.apache.poi.util.HexDump;
+import org.junit.Test;
/**
* Tests for {@link NumberComparer}
*
* @author Josh Micich
*/
-public final class TestNumberComparer extends TestCase {
+public final class TestNumberComparer {
+ @Test
public void testAllComparisonExamples() {
ComparisonExample[] examples = NumberComparisonExamples.getComparisonExamples();
boolean success = true;
@@ -40,11 +43,11 @@ public final class TestNumberComparer extends TestCase {
success &= confirm(i, ce.getNegA(), ce.getNegB(), -ce.getExpectedResult());
success &= confirm(i, ce.getNegB(), ce.getNegA(), +ce.getExpectedResult());
}
- if (!success) {
- throw new AssertionFailedError("One or more cases failed. See stderr");
- }
+
+ assertTrue("One or more cases failed. See stderr", success);
}
+ @Test
public void testRoundTripOnComparisonExamples() {
ComparisonExample[] examples = NumberComparisonExamples.getComparisonExamples();
boolean success = true;
@@ -55,10 +58,8 @@ public final class TestNumberComparer extends TestCase {
success &= confirmRoundTrip(i, ce.getB());
success &= confirmRoundTrip(i, ce.getNegB());
}
- if (!success) {
- throw new AssertionFailedError("One or more cases failed. See stderr");
- }
-
+
+ assertTrue("One or more cases failed. See stderr", success);
}
private boolean confirmRoundTrip(int i, double a) {
@@ -68,6 +69,7 @@ public final class TestNumberComparer extends TestCase {
/**
* The actual example from bug 47598
*/
+ @Test
public void testSpecificExampleA() {
double a = 0.06-0.01;
double b = 0.05;
@@ -78,6 +80,7 @@ public final class TestNumberComparer extends TestCase {
/**
* The example from the nabble posting
*/
+ @Test
public void testSpecificExampleB() {
double a = 1+1.0028-0.9973;
double b = 1.0055;
@@ -99,8 +102,6 @@ public final class TestNumberComparer extends TestCase {
}
private static String formatDoubleAsHex(double d) {
long l = Double.doubleToLongBits(d);
- StringBuilder sb = new StringBuilder(20);
- sb.append(HexDump.longToHex(l)).append('L');
- return sb.toString();
+ return HexDump.longToHex(l)+'L';
}
}