ICU-11914 Refactor tests to simplify.
X-SVN-Rev: 38442
This commit is contained in:
parent
93256d3f9e
commit
653ca5409d
@ -4382,27 +4382,10 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
|||||||
fmt.parseCurrency("53.45", ppos), null);
|
fmt.parseCurrency("53.45", ppos), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing for Issue 11914, missing FieldPositions for some field types.
|
private void CompareAttributedCharacterFormatOutput(AttributedCharacterIterator iterator,
|
||||||
public void TestNPEIssue11914() {
|
List<FieldContainer> expected, String formattedOutput) {
|
||||||
List<FieldContainer> v1 = new ArrayList<FieldContainer>(7);
|
|
||||||
v1.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
|
|
||||||
v1.add(new FieldContainer(3, 4, NumberFormat.Field.GROUPING_SEPARATOR));
|
|
||||||
v1.add(new FieldContainer(4, 7, NumberFormat.Field.INTEGER));
|
|
||||||
v1.add(new FieldContainer(7, 8, NumberFormat.Field.GROUPING_SEPARATOR));
|
|
||||||
v1.add(new FieldContainer(8, 11, NumberFormat.Field.INTEGER));
|
|
||||||
v1.add(new FieldContainer(11, 12, NumberFormat.Field.DECIMAL_SEPARATOR));
|
|
||||||
v1.add(new FieldContainer(12, 15, NumberFormat.Field.FRACTION));
|
|
||||||
|
|
||||||
List<FieldContainer> result = new ArrayList<FieldContainer>();
|
List<FieldContainer> result = new ArrayList<FieldContainer>();
|
||||||
|
|
||||||
Number number = new Double(123456789.9753);
|
|
||||||
ULocale usLoc = new ULocale("en-US");
|
|
||||||
DecimalFormatSymbols US = new DecimalFormatSymbols(usLoc);
|
|
||||||
|
|
||||||
DecimalFormat outFmt = new DecimalFormat();
|
|
||||||
String numFmtted = outFmt.format(number);
|
|
||||||
AttributedCharacterIterator iterator =
|
|
||||||
outFmt.formatToCharacterIterator(number);
|
|
||||||
while (iterator.getIndex() != iterator.getEndIndex()) {
|
while (iterator.getIndex() != iterator.getEndIndex()) {
|
||||||
int start = iterator.getRunStart();
|
int start = iterator.getRunStart();
|
||||||
int end = iterator.getRunLimit();
|
int end = iterator.getRunLimit();
|
||||||
@ -4412,16 +4395,17 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
|||||||
result.add(new FieldContainer(start, end, attribute, value));
|
result.add(new FieldContainer(start, end, attribute, value));
|
||||||
iterator.setIndex(end);
|
iterator.setIndex(end);
|
||||||
}
|
}
|
||||||
assertEquals("Comparing vector length for " + numFmtted,
|
assertEquals("Comparing vector length for " + formattedOutput,
|
||||||
v1.size(), result.size());
|
expected.size(), result.size());
|
||||||
if (!v1.containsAll(result)) {
|
|
||||||
|
if (!expected.containsAll(result)) {
|
||||||
// Print information on the differences.
|
// Print information on the differences.
|
||||||
for (int i = 0; i < v1.size(); i++) {
|
for (int i = 0; i < expected.size(); i++) {
|
||||||
System.out.println(" v1[" + i + "] =" +
|
System.out.println(" expected[" + i + "] =" +
|
||||||
v1.get(i).start + " " +
|
expected.get(i).start + " " +
|
||||||
v1.get(i).end + " " +
|
expected.get(i).end + " " +
|
||||||
v1.get(i).attribute + " " +
|
expected.get(i).attribute + " " +
|
||||||
v1.get(i).value);
|
expected.get(i).value);
|
||||||
System.out.println(" result[" + i + "] =" +
|
System.out.println(" result[" + i + "] =" +
|
||||||
result.get(i).start + " " +
|
result.get(i).start + " " +
|
||||||
result.get(i).end + " " +
|
result.get(i).end + " " +
|
||||||
@ -4430,15 +4414,33 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: restore when #11914 is fixed.
|
// TODO: restore when #11914 is fixed.
|
||||||
/*
|
assertTrue("Comparing vector results for " + formattedOutput,
|
||||||
assertTrue("Comparing vector results for " + numFmtted,
|
expected.containsAll(result));
|
||||||
v1.containsAll(result));
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
Set<AttributedCharacterIterator.Attribute> resultUS = iterator.getAllAttributeKeys();
|
// Testing for Issue 11914, missing FieldPositions for some field types.
|
||||||
assertEquals("comparing vector sizes for " + numFmtted,
|
public void TestNPEIssue11914() {
|
||||||
4, resultUS.size());
|
// First test: Double value with grouping separators.
|
||||||
|
List<FieldContainer> v1 = new ArrayList<FieldContainer>(7);
|
||||||
|
v1.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
|
||||||
|
v1.add(new FieldContainer(3, 4, NumberFormat.Field.GROUPING_SEPARATOR));
|
||||||
|
v1.add(new FieldContainer(4, 7, NumberFormat.Field.INTEGER));
|
||||||
|
v1.add(new FieldContainer(7, 8, NumberFormat.Field.GROUPING_SEPARATOR));
|
||||||
|
v1.add(new FieldContainer(8, 11, NumberFormat.Field.INTEGER));
|
||||||
|
v1.add(new FieldContainer(11, 12, NumberFormat.Field.DECIMAL_SEPARATOR));
|
||||||
|
v1.add(new FieldContainer(12, 15, NumberFormat.Field.FRACTION));
|
||||||
|
|
||||||
|
Number number = new Double(123456789.9753);
|
||||||
|
ULocale usLoc = new ULocale("en-US");
|
||||||
|
DecimalFormatSymbols US = new DecimalFormatSymbols(usLoc);
|
||||||
|
|
||||||
|
NumberFormat outFmt = NumberFormat.getNumberInstance(usLoc);
|
||||||
|
String numFmtted = outFmt.format(number);
|
||||||
|
AttributedCharacterIterator iterator =
|
||||||
|
outFmt.formatToCharacterIterator(number);
|
||||||
|
CompareAttributedCharacterFormatOutput(iterator, v1, numFmtted);
|
||||||
|
|
||||||
|
// Second test: Double with scientific notation formatting.
|
||||||
List<FieldContainer> v2 = new ArrayList<FieldContainer>(7);
|
List<FieldContainer> v2 = new ArrayList<FieldContainer>(7);
|
||||||
v2.add(new FieldContainer(0, 1, NumberFormat.Field.INTEGER));
|
v2.add(new FieldContainer(0, 1, NumberFormat.Field.INTEGER));
|
||||||
v2.add(new FieldContainer(1, 2, NumberFormat.Field.DECIMAL_SEPARATOR));
|
v2.add(new FieldContainer(1, 2, NumberFormat.Field.DECIMAL_SEPARATOR));
|
||||||
@ -4448,21 +4450,11 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
|||||||
v2.add(new FieldContainer(7, 8, NumberFormat.Field.EXPONENT));
|
v2.add(new FieldContainer(7, 8, NumberFormat.Field.EXPONENT));
|
||||||
DecimalFormat fmt2 = new DecimalFormat("0.###E+0", US);
|
DecimalFormat fmt2 = new DecimalFormat("0.###E+0", US);
|
||||||
|
|
||||||
List<FieldContainer> result2 = new ArrayList<FieldContainer>();
|
|
||||||
|
|
||||||
numFmtted = fmt2.format(number);
|
numFmtted = fmt2.format(number);
|
||||||
iterator = fmt2.formatToCharacterIterator(number);
|
iterator = fmt2.formatToCharacterIterator(number);
|
||||||
while (iterator.getIndex() != iterator.getEndIndex()) {
|
CompareAttributedCharacterFormatOutput(iterator, v2, numFmtted);
|
||||||
int start = iterator.getRunStart();
|
|
||||||
int end = iterator.getRunLimit();
|
|
||||||
Iterator it = iterator.getAttributes().keySet().iterator();
|
|
||||||
AttributedCharacterIterator.Attribute attribute = (AttributedCharacterIterator.Attribute) it.next();
|
|
||||||
Object value = iterator.getAttribute(attribute);
|
|
||||||
result2.add(new FieldContainer(start, end, attribute, value));
|
|
||||||
iterator.setIndex(end);
|
|
||||||
}
|
|
||||||
assertTrue("Comparing vector results", v2.size() == result2.size() && v2.containsAll(result2));
|
|
||||||
|
|
||||||
|
// Third test. BigInteger with grouping separators.
|
||||||
List<FieldContainer> v3 = new ArrayList<FieldContainer>(7);
|
List<FieldContainer> v3 = new ArrayList<FieldContainer>(7);
|
||||||
v3.add(new FieldContainer(0, 1, NumberFormat.Field.SIGN));
|
v3.add(new FieldContainer(0, 1, NumberFormat.Field.SIGN));
|
||||||
v3.add(new FieldContainer(1, 2, NumberFormat.Field.INTEGER));
|
v3.add(new FieldContainer(1, 2, NumberFormat.Field.INTEGER));
|
||||||
@ -4479,41 +4471,12 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
|||||||
v3.add(new FieldContainer(22, 23, NumberFormat.Field.GROUPING_SEPARATOR));
|
v3.add(new FieldContainer(22, 23, NumberFormat.Field.GROUPING_SEPARATOR));
|
||||||
v3.add(new FieldContainer(23, 26, NumberFormat.Field.INTEGER));
|
v3.add(new FieldContainer(23, 26, NumberFormat.Field.INTEGER));
|
||||||
BigInteger bigNumberInt = new BigInteger("-1234567890246813579");
|
BigInteger bigNumberInt = new BigInteger("-1234567890246813579");
|
||||||
String fmtNumberBigIntExp = fmt2.format(bigNumberInt);
|
|
||||||
String fmtNumberBigInt = outFmt.format(bigNumberInt);
|
String fmtNumberBigInt = outFmt.format(bigNumberInt);
|
||||||
|
|
||||||
List<FieldContainer> result3 = new ArrayList<FieldContainer>();
|
|
||||||
iterator = outFmt.formatToCharacterIterator(bigNumberInt);
|
iterator = outFmt.formatToCharacterIterator(bigNumberInt);
|
||||||
while (iterator.getIndex() != iterator.getEndIndex()) {
|
CompareAttributedCharacterFormatOutput(iterator, v3, fmtNumberBigInt);
|
||||||
int start = iterator.getRunStart();
|
|
||||||
int end = iterator.getRunLimit();
|
|
||||||
Iterator it = iterator.getAttributes().keySet().iterator();
|
|
||||||
AttributedCharacterIterator.Attribute attribute = (AttributedCharacterIterator.Attribute) it.next();
|
|
||||||
Object value = iterator.getAttribute(attribute);
|
|
||||||
result3.add(new FieldContainer(start, end, attribute, value));
|
|
||||||
iterator.setIndex(end);
|
|
||||||
}
|
|
||||||
assertEquals("Comparing vector results for " + fmtNumberBigInt, v3.size() ,result3.size());
|
|
||||||
if (!v3.containsAll(result)) {
|
|
||||||
// Print information on the differences.
|
|
||||||
for (int i = 0; i < v1.size(); i++) {
|
|
||||||
System.out.println(" v3[" + i + "] =" +
|
|
||||||
v3.get(i).start + " " +
|
|
||||||
v3.get(i).end + " " +
|
|
||||||
v3.get(i).attribute + " " +
|
|
||||||
v3.get(i).value);
|
|
||||||
System.out.println(" result3[" + i + "] =" +
|
|
||||||
result3.get(i).start + " " +
|
|
||||||
result3.get(i).end + " " +
|
|
||||||
result3.get(i).attribute + " " +
|
|
||||||
result3.get(i).value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: restore when #11914 is fixed.
|
|
||||||
/*
|
|
||||||
assertTrue("Comparing vector results for " + fmtNumberBigInt, v3.containsAll(result3));
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
// Fourth test: BigDecimal with exponential formatting.
|
||||||
List<FieldContainer> v4 = new ArrayList<FieldContainer>(7);
|
List<FieldContainer> v4 = new ArrayList<FieldContainer>(7);
|
||||||
v4.add(new FieldContainer(0, 1, NumberFormat.Field.SIGN));
|
v4.add(new FieldContainer(0, 1, NumberFormat.Field.SIGN));
|
||||||
v4.add(new FieldContainer(1, 2, NumberFormat.Field.INTEGER));
|
v4.add(new FieldContainer(1, 2, NumberFormat.Field.INTEGER));
|
||||||
@ -4525,20 +4488,9 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
|||||||
|
|
||||||
java.math.BigDecimal numberBigD = new java.math.BigDecimal(-123456789);
|
java.math.BigDecimal numberBigD = new java.math.BigDecimal(-123456789);
|
||||||
String fmtNumberBigDExp = fmt2.format(numberBigD);
|
String fmtNumberBigDExp = fmt2.format(numberBigD);
|
||||||
String fmtNumberBigD = outFmt.format(numberBigD);
|
|
||||||
|
|
||||||
List<FieldContainer> result4 = new ArrayList<FieldContainer>();
|
|
||||||
iterator = fmt2.formatToCharacterIterator(numberBigD);
|
iterator = fmt2.formatToCharacterIterator(numberBigD);
|
||||||
while (iterator.getIndex() != iterator.getEndIndex()) {
|
CompareAttributedCharacterFormatOutput(iterator, v4, fmtNumberBigDExp);
|
||||||
int start = iterator.getRunStart();
|
|
||||||
int end = iterator.getRunLimit();
|
|
||||||
Iterator it = iterator.getAttributes().keySet().iterator();
|
|
||||||
AttributedCharacterIterator.Attribute attribute = (AttributedCharacterIterator.Attribute) it.next();
|
|
||||||
Object value = iterator.getAttribute(attribute);
|
|
||||||
result4.add(new FieldContainer(start, end, attribute, value));
|
|
||||||
iterator.setIndex(end);
|
|
||||||
}
|
|
||||||
assertTrue("Comparing vector results for " + fmtNumberBigDExp,
|
|
||||||
v4.size() == result4.size() && v4.containsAll(result4));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user