|
7 | 7 |
|
8 | 8 | public class SuffixFormatterTest { |
9 | 9 |
|
10 | | - @Test |
11 | | - public void testParseBinaryKi() { |
12 | | - final BaseExponent baseExponent = new SuffixFormatter().parse("Ki"); |
13 | | - assertThat(baseExponent.getBase(), is(2)); |
14 | | - assertThat(baseExponent.getExponent(), is(10)); |
15 | | - assertThat(baseExponent.getFormat(), is(Quantity.Format.BINARY_SI)); |
16 | | - } |
17 | | - |
18 | | - @Test |
19 | | - public void testParseDecimalZero() { |
20 | | - final BaseExponent baseExponent = new SuffixFormatter().parse(""); |
21 | | - assertThat(baseExponent.getBase(), is(10)); |
22 | | - assertThat(baseExponent.getExponent(), is(0)); |
23 | | - assertThat(baseExponent.getFormat(), is(Quantity.Format.DECIMAL_SI)); |
24 | | - } |
25 | | - |
26 | | - @Test |
27 | | - public void testParseDecimalK() { |
28 | | - final BaseExponent baseExponent = new SuffixFormatter().parse("k"); |
29 | | - assertThat(baseExponent.getBase(), is(10)); |
30 | | - assertThat(baseExponent.getExponent(), is(3)); |
31 | | - assertThat(baseExponent.getFormat(), is(Quantity.Format.DECIMAL_SI)); |
32 | | - } |
33 | | - |
34 | | - @Test |
35 | | - public void testParseDecimalExponent() { |
36 | | - final BaseExponent baseExponent = new SuffixFormatter().parse("E2"); |
37 | | - assertThat(baseExponent.getBase(), is(10)); |
38 | | - assertThat(baseExponent.getExponent(), is(2)); |
39 | | - assertThat(baseExponent.getFormat(), is(Quantity.Format.DECIMAL_EXPONENT)); |
40 | | - } |
41 | | - |
42 | | - @Test |
43 | | - public void testParseDecimalExponentPositive() { |
44 | | - final BaseExponent baseExponent = new SuffixFormatter().parse("e+3"); |
45 | | - assertThat(baseExponent.getBase(), is(10)); |
46 | | - assertThat(baseExponent.getExponent(), is(3)); |
47 | | - assertThat(baseExponent.getFormat(), is(Quantity.Format.DECIMAL_EXPONENT)); |
48 | | - } |
49 | | - |
50 | | - @Test |
51 | | - public void testParseDecimalExponentNegative() { |
52 | | - final BaseExponent baseExponent = new SuffixFormatter().parse("e-3"); |
53 | | - assertThat(baseExponent.getBase(), is(10)); |
54 | | - assertThat(baseExponent.getExponent(), is(-3)); |
55 | | - assertThat(baseExponent.getFormat(), is(Quantity.Format.DECIMAL_EXPONENT)); |
56 | | - } |
57 | | - |
58 | | - @Test(expected = QuantityFormatException.class) |
59 | | - public void testParseBad() { |
60 | | - new SuffixFormatter().parse("eKi"); |
61 | | - } |
62 | | - |
63 | | - @Test |
64 | | - public void testFormatZeroDecimalExponent() { |
65 | | - final String formattedString = new SuffixFormatter().format(Quantity.Format.DECIMAL_EXPONENT, 0); |
66 | | - assertThat(formattedString, is("")); |
67 | | - } |
68 | | - |
69 | | - @Test |
70 | | - public void testFormatDecimalExponent() { |
71 | | - final String formattedString = new SuffixFormatter().format(Quantity.Format.DECIMAL_EXPONENT, 3); |
72 | | - assertThat(formattedString, is("e3")); |
73 | | - } |
74 | | - |
75 | | - @Test |
76 | | - public void testFormatZeroDecimalSi() { |
77 | | - final String formattedString = new SuffixFormatter().format(Quantity.Format.DECIMAL_SI, 0); |
78 | | - assertThat(formattedString, is("")); |
79 | | - } |
80 | | - |
81 | | - @Test(expected = IllegalArgumentException.class) |
82 | | - public void testFormatBadDecimalSi() { |
83 | | - new SuffixFormatter().format(Quantity.Format.DECIMAL_SI, 2); |
84 | | - } |
85 | | - |
86 | | - @Test |
87 | | - public void testFormatDecimalSi() { |
88 | | - final String formattedString = new SuffixFormatter().format(Quantity.Format.DECIMAL_SI, 3); |
89 | | - assertThat(formattedString, is("k")); |
90 | | - } |
91 | | - |
92 | | - @Test |
93 | | - public void testFormatNegativeDecimalSi() { |
94 | | - final String formattedString = new SuffixFormatter().format(Quantity.Format.DECIMAL_SI, -6); |
95 | | - assertThat(formattedString, is("u")); |
96 | | - } |
97 | | - |
98 | | - @Test |
99 | | - public void testFormatBinarySi() { |
100 | | - final String formattedString = new SuffixFormatter().format(Quantity.Format.BINARY_SI, 10); |
101 | | - assertThat(formattedString, is("Ki")); |
102 | | - } |
103 | | - |
104 | | - @Test |
105 | | - public void testFormatNoExponentBinarySi() { |
106 | | - final String formattedString = new SuffixFormatter().format(Quantity.Format.BINARY_SI, 0); |
107 | | - assertThat(formattedString, is("")); |
108 | | - } |
109 | | - |
110 | | - @Test(expected = IllegalArgumentException.class) |
111 | | - public void testFormatBadBinarySi() { |
112 | | - new SuffixFormatter().format(Quantity.Format.BINARY_SI, 4); |
113 | | - } |
| 10 | + @Test |
| 11 | + public void testParseBinaryKi() { |
| 12 | + final BaseExponent baseExponent = new SuffixFormatter().parse("Ki"); |
| 13 | + assertThat(baseExponent.getBase(), is(2)); |
| 14 | + assertThat(baseExponent.getExponent(), is(10)); |
| 15 | + assertThat(baseExponent.getFormat(), is(Quantity.Format.BINARY_SI)); |
| 16 | + } |
| 17 | + |
| 18 | + @Test |
| 19 | + public void testParseDecimalZero() { |
| 20 | + final BaseExponent baseExponent = new SuffixFormatter().parse(""); |
| 21 | + assertThat(baseExponent.getBase(), is(10)); |
| 22 | + assertThat(baseExponent.getExponent(), is(0)); |
| 23 | + assertThat(baseExponent.getFormat(), is(Quantity.Format.DECIMAL_SI)); |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + public void testParseDecimalK() { |
| 28 | + final BaseExponent baseExponent = new SuffixFormatter().parse("k"); |
| 29 | + assertThat(baseExponent.getBase(), is(10)); |
| 30 | + assertThat(baseExponent.getExponent(), is(3)); |
| 31 | + assertThat(baseExponent.getFormat(), is(Quantity.Format.DECIMAL_SI)); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void testParseDecimalExponent() { |
| 36 | + final BaseExponent baseExponent = new SuffixFormatter().parse("E2"); |
| 37 | + assertThat(baseExponent.getBase(), is(10)); |
| 38 | + assertThat(baseExponent.getExponent(), is(2)); |
| 39 | + assertThat(baseExponent.getFormat(), is(Quantity.Format.DECIMAL_EXPONENT)); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void testParseDecimalExponentPositive() { |
| 44 | + final BaseExponent baseExponent = new SuffixFormatter().parse("e+3"); |
| 45 | + assertThat(baseExponent.getBase(), is(10)); |
| 46 | + assertThat(baseExponent.getExponent(), is(3)); |
| 47 | + assertThat(baseExponent.getFormat(), is(Quantity.Format.DECIMAL_EXPONENT)); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testParseDecimalExponentNegative() { |
| 52 | + final BaseExponent baseExponent = new SuffixFormatter().parse("e-3"); |
| 53 | + assertThat(baseExponent.getBase(), is(10)); |
| 54 | + assertThat(baseExponent.getExponent(), is(-3)); |
| 55 | + assertThat(baseExponent.getFormat(), is(Quantity.Format.DECIMAL_EXPONENT)); |
| 56 | + } |
| 57 | + |
| 58 | + @Test(expected = QuantityFormatException.class) |
| 59 | + public void testParseBad() { |
| 60 | + new SuffixFormatter().parse("eKi"); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void testFormatZeroDecimalExponent() { |
| 65 | + final String formattedString = new SuffixFormatter().format(Quantity.Format.DECIMAL_EXPONENT, 0); |
| 66 | + assertThat(formattedString, is("")); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void testFormatDecimalExponent() { |
| 71 | + final String formattedString = new SuffixFormatter().format(Quantity.Format.DECIMAL_EXPONENT, 3); |
| 72 | + assertThat(formattedString, is("e3")); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testFormatZeroDecimalSi() { |
| 77 | + final String formattedString = new SuffixFormatter().format(Quantity.Format.DECIMAL_SI, 0); |
| 78 | + assertThat(formattedString, is("")); |
| 79 | + } |
| 80 | + |
| 81 | + @Test(expected = IllegalArgumentException.class) |
| 82 | + public void testFormatBadDecimalSi() { |
| 83 | + new SuffixFormatter().format(Quantity.Format.DECIMAL_SI, 2); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void testFormatDecimalSi() { |
| 88 | + final String formattedString = new SuffixFormatter().format(Quantity.Format.DECIMAL_SI, 3); |
| 89 | + assertThat(formattedString, is("k")); |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + public void testFormatNegativeDecimalSi() { |
| 94 | + final String formattedString = new SuffixFormatter().format(Quantity.Format.DECIMAL_SI, -6); |
| 95 | + assertThat(formattedString, is("u")); |
| 96 | + } |
| 97 | + |
| 98 | + @Test |
| 99 | + public void testFormatBinarySi() { |
| 100 | + final String formattedString = new SuffixFormatter().format(Quantity.Format.BINARY_SI, 10); |
| 101 | + assertThat(formattedString, is("Ki")); |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + public void testFormatNoExponentBinarySi() { |
| 106 | + final String formattedString = new SuffixFormatter().format(Quantity.Format.BINARY_SI, 0); |
| 107 | + assertThat(formattedString, is("")); |
| 108 | + } |
| 109 | + |
| 110 | + @Test(expected = IllegalArgumentException.class) |
| 111 | + public void testFormatBadBinarySi() { |
| 112 | + new SuffixFormatter().format(Quantity.Format.BINARY_SI, 4); |
| 113 | + } |
114 | 114 |
|
115 | 115 | } |
0 commit comments