use of android.icu.dev.test.format.IntlTestDecimalFormatAPIC.FieldContainer in project j2objc by google.
the class NumberFormatTest method CompareAttributedCharacterFormatOutput.
private void CompareAttributedCharacterFormatOutput(AttributedCharacterIterator iterator, List<FieldContainer> expected, String formattedOutput) {
List<FieldContainer> result = new ArrayList<FieldContainer>();
while (iterator.getIndex() != iterator.getEndIndex()) {
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);
result.add(new FieldContainer(start, end, attribute, value));
iterator.setIndex(end);
}
assertEquals("Comparing vector length for " + formattedOutput, expected.size(), result.size());
if (!expected.containsAll(result)) {
// Print information on the differences.
for (int i = 0; i < expected.size(); i++) {
System.out.println(" expected[" + i + "] =" + expected.get(i).start + " " + expected.get(i).end + " " + expected.get(i).attribute + " " + expected.get(i).value);
System.out.println(" result[" + i + "] =" + result.get(i).start + " " + result.get(i).end + " " + result.get(i).attribute + " " + result.get(i).value);
}
}
// TODO: restore when #11914 is fixed.
// assertTrue("Comparing vector results for " + formattedOutput,
// expected.containsAll(result));
}
use of android.icu.dev.test.format.IntlTestDecimalFormatAPIC.FieldContainer in project j2objc by google.
the class NumberFormatTest method TestNPEIssue11914.
// Testing for Issue 11914, missing FieldPositions for some field types.
@Test
public void TestNPEIssue11914() {
// 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);
v2.add(new FieldContainer(0, 1, NumberFormat.Field.INTEGER));
v2.add(new FieldContainer(1, 2, NumberFormat.Field.DECIMAL_SEPARATOR));
v2.add(new FieldContainer(2, 5, NumberFormat.Field.FRACTION));
v2.add(new FieldContainer(5, 6, NumberFormat.Field.EXPONENT_SYMBOL));
v2.add(new FieldContainer(6, 7, NumberFormat.Field.EXPONENT_SIGN));
v2.add(new FieldContainer(7, 8, NumberFormat.Field.EXPONENT));
DecimalFormat fmt2 = new DecimalFormat("0.###E+0", US);
numFmtted = fmt2.format(number);
iterator = fmt2.formatToCharacterIterator(number);
CompareAttributedCharacterFormatOutput(iterator, v2, numFmtted);
// Third test. BigInteger with grouping separators.
List<FieldContainer> v3 = new ArrayList<FieldContainer>(7);
v3.add(new FieldContainer(0, 1, NumberFormat.Field.SIGN));
v3.add(new FieldContainer(1, 2, NumberFormat.Field.INTEGER));
v3.add(new FieldContainer(2, 3, NumberFormat.Field.GROUPING_SEPARATOR));
v3.add(new FieldContainer(3, 6, NumberFormat.Field.INTEGER));
v3.add(new FieldContainer(6, 7, NumberFormat.Field.GROUPING_SEPARATOR));
v3.add(new FieldContainer(7, 10, NumberFormat.Field.INTEGER));
v3.add(new FieldContainer(10, 11, NumberFormat.Field.GROUPING_SEPARATOR));
v3.add(new FieldContainer(11, 14, NumberFormat.Field.INTEGER));
v3.add(new FieldContainer(14, 15, NumberFormat.Field.GROUPING_SEPARATOR));
v3.add(new FieldContainer(15, 18, NumberFormat.Field.INTEGER));
v3.add(new FieldContainer(18, 19, NumberFormat.Field.GROUPING_SEPARATOR));
v3.add(new FieldContainer(19, 22, NumberFormat.Field.INTEGER));
v3.add(new FieldContainer(22, 23, NumberFormat.Field.GROUPING_SEPARATOR));
v3.add(new FieldContainer(23, 26, NumberFormat.Field.INTEGER));
BigInteger bigNumberInt = new BigInteger("-1234567890246813579");
String fmtNumberBigInt = outFmt.format(bigNumberInt);
iterator = outFmt.formatToCharacterIterator(bigNumberInt);
CompareAttributedCharacterFormatOutput(iterator, v3, fmtNumberBigInt);
// Fourth test: BigDecimal with exponential formatting.
List<FieldContainer> v4 = new ArrayList<FieldContainer>(7);
v4.add(new FieldContainer(0, 1, NumberFormat.Field.SIGN));
v4.add(new FieldContainer(1, 2, NumberFormat.Field.INTEGER));
v4.add(new FieldContainer(2, 3, NumberFormat.Field.DECIMAL_SEPARATOR));
v4.add(new FieldContainer(3, 6, NumberFormat.Field.FRACTION));
v4.add(new FieldContainer(6, 7, NumberFormat.Field.EXPONENT_SYMBOL));
v4.add(new FieldContainer(7, 8, NumberFormat.Field.EXPONENT_SIGN));
v4.add(new FieldContainer(8, 9, NumberFormat.Field.EXPONENT));
java.math.BigDecimal numberBigD = new java.math.BigDecimal(-123456789);
String fmtNumberBigDExp = fmt2.format(numberBigD);
iterator = fmt2.formatToCharacterIterator(numberBigD);
CompareAttributedCharacterFormatOutput(iterator, v4, fmtNumberBigDExp);
}
Aggregations