01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.util.stringification;
05:
06: import com.tc.test.TCTestCase;
07:
08: /**
09: * Unit test for {@link PrettyPrintUtils}.
10: */
11: public class PrettyPrintUtilsTest extends TCTestCase {
12:
13: public void testPluralize() throws Exception {
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
22: .pluralize("grass", -20));
23: assertEquals("grasses", PrettyPrintUtils.pluralize("grass", -1));
24: assertEquals("grasses", PrettyPrintUtils.pluralize("grass", 0));
25: assertEquals("grass", PrettyPrintUtils.pluralize("grass", 1));
26: assertEquals("grasses", PrettyPrintUtils.pluralize("grass", 2));
27: assertEquals("grasses", PrettyPrintUtils.pluralize("grass", 20));
28: }
29:
30: public void testQuantity() throws Exception {
31: assertEquals("-20 foos", PrettyPrintUtils.quantity("foo", -20));
32: assertEquals("-1 foos", PrettyPrintUtils.quantity("foo", -1));
33: assertEquals("0 foos", PrettyPrintUtils.quantity("foo", 0));
34: assertEquals("1 foo", PrettyPrintUtils.quantity("foo", 1));
35: assertEquals("2 foos", PrettyPrintUtils.quantity("foo", 2));
36: assertEquals("20 foos", PrettyPrintUtils.quantity("foo", 20));
37:
38: assertEquals("-20 grasses", PrettyPrintUtils.quantity("grass",
39: -20));
40: assertEquals("-1 grasses", PrettyPrintUtils.quantity("grass",
41: -1));
42: assertEquals("0 grasses", PrettyPrintUtils.quantity("grass", 0));
43: assertEquals("1 grass", PrettyPrintUtils.quantity("grass", 1));
44: assertEquals("2 grasses", PrettyPrintUtils.quantity("grass", 2));
45: assertEquals("20 grasses", PrettyPrintUtils.quantity("grass",
46: 20));
47: }
48:
49: public void testPercentage() throws Exception {
50: assertEquals("0.0000000000%", PrettyPrintUtils.percentage(0.0,
51: 10));
52: assertEquals("0.00%", PrettyPrintUtils.percentage(0.0, 2));
53: assertEquals("0.0%", PrettyPrintUtils.percentage(0.0, 1));
54: assertEquals("0%", PrettyPrintUtils.percentage(0.0, 0));
55: assertEquals("12.34%", PrettyPrintUtils.percentage(0.12341234,
56: 2));
57: assertEquals("12.35%", PrettyPrintUtils.percentage(0.12351234,
58: 2));
59: assertEquals("12.35%", PrettyPrintUtils.percentage(0.12349, 2));
60: assertEquals("12.35%", PrettyPrintUtils.percentage(0.1235, 2));
61: assertEquals("12%", PrettyPrintUtils.percentage(0.12345234, 0));
62: assertEquals("13%", PrettyPrintUtils.percentage(0.126, 0));
63: assertEquals("9%", PrettyPrintUtils.percentage(0.09, 0));
64: assertEquals("9.02%", PrettyPrintUtils.percentage(0.0902, 2));
65: assertEquals("-1%", PrettyPrintUtils.percentage(-0.01, 0));
66: assertEquals("-1.01%", PrettyPrintUtils.percentage(-0.0101, 2));
67: assertEquals("-1.48%", PrettyPrintUtils.percentage(-0.0148, 2));
68: assertEquals("-1%", PrettyPrintUtils.percentage(-0.0148, 0));
69: assertEquals("-1%", PrettyPrintUtils.percentage(-0.015, 0));
70: assertEquals("-2%", PrettyPrintUtils.percentage(-0.016, 0));
71: assertEquals("-2%", PrettyPrintUtils.percentage(-0.019, 0));
72: assertEquals("-2%", PrettyPrintUtils.percentage(-0.025, 0));
73: }
74:
75: }
|