KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > util > stringification > PrettyPrintUtilsTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.util.stringification;
5
6 import com.tc.test.TCTestCase;
7
8 /**
9  * Unit test for {@link PrettyPrintUtils}.
10  */

11 public class PrettyPrintUtilsTest extends TCTestCase {
12
13   public void testPluralize() throws Exception JavaDoc {
14     assertEquals("foos", PrettyPrintUtils.pluralize("foo", -20));
15     assertEquals("foos", PrettyPrintUtils.pluralize("foo", -1));
16     assertEquals("foos", PrettyPrintUtils.pluralize("foo", 0));
17     assertEquals("foo", PrettyPrintUtils.pluralize("foo", 1));
18     assertEquals("foos", PrettyPrintUtils.pluralize("foo", 2));
19     assertEquals("foos", PrettyPrintUtils.pluralize("foo", 20));
20
21     assertEquals("grasses", PrettyPrintUtils.pluralize("grass", -20));
22     assertEquals("grasses", PrettyPrintUtils.pluralize("grass", -1));
23     assertEquals("grasses", PrettyPrintUtils.pluralize("grass", 0));
24     assertEquals("grass", PrettyPrintUtils.pluralize("grass", 1));
25     assertEquals("grasses", PrettyPrintUtils.pluralize("grass", 2));
26     assertEquals("grasses", PrettyPrintUtils.pluralize("grass", 20));
27   }
28
29   public void testQuantity() throws Exception JavaDoc {
30     assertEquals("-20 foos", PrettyPrintUtils.quantity("foo", -20));
31     assertEquals("-1 foos", PrettyPrintUtils.quantity("foo", -1));
32     assertEquals("0 foos", PrettyPrintUtils.quantity("foo", 0));
33     assertEquals("1 foo", PrettyPrintUtils.quantity("foo", 1));
34     assertEquals("2 foos", PrettyPrintUtils.quantity("foo", 2));
35     assertEquals("20 foos", PrettyPrintUtils.quantity("foo", 20));
36
37     assertEquals("-20 grasses", PrettyPrintUtils.quantity("grass", -20));
38     assertEquals("-1 grasses", PrettyPrintUtils.quantity("grass", -1));
39     assertEquals("0 grasses", PrettyPrintUtils.quantity("grass", 0));
40     assertEquals("1 grass", PrettyPrintUtils.quantity("grass", 1));
41     assertEquals("2 grasses", PrettyPrintUtils.quantity("grass", 2));
42     assertEquals("20 grasses", PrettyPrintUtils.quantity("grass", 20));
43   }
44
45   public void testPercentage() throws Exception JavaDoc {
46     assertEquals("0.0000000000%", PrettyPrintUtils.percentage(0.0, 10));
47     assertEquals("0.00%", PrettyPrintUtils.percentage(0.0, 2));
48     assertEquals("0.0%", PrettyPrintUtils.percentage(0.0, 1));
49     assertEquals("0%", PrettyPrintUtils.percentage(0.0, 0));
50     assertEquals("12.34%", PrettyPrintUtils.percentage(0.12341234, 2));
51     assertEquals("12.35%", PrettyPrintUtils.percentage(0.12351234, 2));
52     assertEquals("12.35%", PrettyPrintUtils.percentage(0.12349, 2));
53     assertEquals("12.35%", PrettyPrintUtils.percentage(0.1235, 2));
54     assertEquals("12%", PrettyPrintUtils.percentage(0.12345234, 0));
55     assertEquals("13%", PrettyPrintUtils.percentage(0.126, 0));
56     assertEquals("9%", PrettyPrintUtils.percentage(0.09, 0));
57     assertEquals("9.02%", PrettyPrintUtils.percentage(0.0902, 2));
58     assertEquals("-1%", PrettyPrintUtils.percentage(-0.01, 0));
59     assertEquals("-1.01%", PrettyPrintUtils.percentage(-0.0101, 2));
60     assertEquals("-1.48%", PrettyPrintUtils.percentage(-0.0148, 2));
61     assertEquals("-1%", PrettyPrintUtils.percentage(-0.0148, 0));
62     assertEquals("-1%", PrettyPrintUtils.percentage(-0.015, 0));
63     assertEquals("-2%", PrettyPrintUtils.percentage(-0.016, 0));
64     assertEquals("-2%", PrettyPrintUtils.percentage(-0.019, 0));
65     assertEquals("-2%", PrettyPrintUtils.percentage(-0.025, 0));
66   }
67
68 }
69
Popular Tags