public void testAppendPercentage()
{
StringBuilder sb = new StringBuilder();
- Format.appendPercentage(sb, 123.456f, 0);
+ Format.appendPercentage(sb, 123.436f, 0);
assertEquals(sb.toString(), "123");
sb.setLength(0);
- Format.appendPercentage(sb, 123.456f, 1);
+ Format.appendPercentage(sb, 123.536f, 0);
+ assertEquals(sb.toString(), "124");
+
+ sb.setLength(0);
+ Format.appendPercentage(sb, 799.536f, 0);
+ assertEquals(sb.toString(), "800");
+
+ sb.setLength(0);
+ Format.appendPercentage(sb, 123.436f, 1);
assertEquals(sb.toString(), "123.4");
sb.setLength(0);
- Format.appendPercentage(sb, 123.456f, 2);
- assertEquals(sb.toString(), "123.45");
+ Format.appendPercentage(sb, 123.436f, 2);
+ assertEquals(sb.toString(), "123.44");
sb.setLength(0);
- Format.appendPercentage(sb, 123.456f, 3);
- assertEquals(sb.toString(), "123.456");
+ Format.appendPercentage(sb, 123.436f, 3);
+ assertEquals(sb.toString(), "123.436");
sb.setLength(0);
- Format.appendPercentage(sb, 123.456f, 4);
- assertEquals(sb.toString(), "123.4560");
+ Format.appendPercentage(sb, 123.436f, 4);
+ assertEquals(sb.toString(), "123.4360");
+ }
+
+ @Test(groups = "Functional")
+ public void testForm_float()
+ {
+ Format f = new Format("%3.2f");
+ assertEquals(f.form(123f), "123.00");
+ assertEquals(f.form(123.1f), "123.10");
+ assertEquals(f.form(123.12f), "123.12");
+ assertEquals(f.form(123.124f), "123.12");
+ assertEquals(f.form(123.125f), "123.13");
+ assertEquals(f.form(123.126f), "123.13");
+
+ f = new Format("%3.0f");
+ assertEquals(f.form(123f), "123.");
+ assertEquals(f.form(12f), "12.");
+ assertEquals(f.form(123.4f), "123.");
+ assertEquals(f.form(123.5f), "124.");
+ assertEquals(f.form(123.6f), "124.");
+ assertEquals(f.form(129.6f), "130.");
}
}