| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.util; |
| 22 |
|
|
| 23 |
|
import static org.testng.Assert.assertEquals; |
| 24 |
|
import static org.testng.Assert.assertTrue; |
| 25 |
|
|
| 26 |
|
import jalview.gui.JvOptionPane; |
| 27 |
|
|
| 28 |
|
import org.testng.annotations.BeforeClass; |
| 29 |
|
import org.testng.annotations.Test; |
| 30 |
|
|
| |
|
| 72.7% |
Uncovered Elements: 21 (77) |
Complexity: 9 |
Complexity Density: 0.14 |
|
| 31 |
|
public class FormatTest |
| 32 |
|
{ |
| 33 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 34 |
1 |
@BeforeClass(alwaysRun = true)... |
| 35 |
|
public void setUpJvOptionPane() |
| 36 |
|
{ |
| 37 |
1 |
JvOptionPane.setInteractiveMode(false); |
| 38 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
| 39 |
|
} |
| 40 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
| 41 |
1 |
@Test(groups = "Functional")... |
| 42 |
|
public void testAppendPercentage() |
| 43 |
|
{ |
| 44 |
1 |
StringBuilder sb = new StringBuilder(); |
| 45 |
1 |
Format.appendPercentage(sb, 123.436f, 0); |
| 46 |
1 |
assertEquals(sb.toString(), "123"); |
| 47 |
|
|
| 48 |
1 |
sb.setLength(0); |
| 49 |
1 |
Format.appendPercentage(sb, 123.536f, 0); |
| 50 |
1 |
assertEquals(sb.toString(), "124"); |
| 51 |
|
|
| 52 |
1 |
sb.setLength(0); |
| 53 |
1 |
Format.appendPercentage(sb, 799.536f, 0); |
| 54 |
1 |
assertEquals(sb.toString(), "800"); |
| 55 |
|
|
| 56 |
1 |
sb.setLength(0); |
| 57 |
1 |
Format.appendPercentage(sb, 123.436f, 1); |
| 58 |
1 |
assertEquals(sb.toString(), "123.4"); |
| 59 |
|
|
| 60 |
1 |
sb.setLength(0); |
| 61 |
1 |
Format.appendPercentage(sb, 123.436f, 2); |
| 62 |
1 |
assertEquals(sb.toString(), "123.44"); |
| 63 |
|
|
| 64 |
1 |
sb.setLength(0); |
| 65 |
1 |
Format.appendPercentage(sb, 123.436f, 3); |
| 66 |
1 |
assertEquals(sb.toString(), "123.436"); |
| 67 |
|
|
| 68 |
1 |
sb.setLength(0); |
| 69 |
1 |
Format.appendPercentage(sb, 123.436f, 4); |
| 70 |
1 |
assertEquals(sb.toString(), "123.4360"); |
| 71 |
|
} |
| 72 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
| 73 |
1 |
@Test(groups = "Functional")... |
| 74 |
|
public void testForm_float() |
| 75 |
|
{ |
| 76 |
1 |
Format f = new Format("%3.2f"); |
| 77 |
1 |
assertEquals(f.form(123f), "123.00"); |
| 78 |
1 |
assertEquals(f.form(123.1f), "123.10"); |
| 79 |
1 |
assertEquals(f.form(123.12f), "123.12"); |
| 80 |
1 |
assertEquals(f.form(123.124f), "123.12"); |
| 81 |
1 |
assertEquals(f.form(123.125f), "123.13"); |
| 82 |
1 |
assertEquals(f.form(123.126f), "123.13"); |
| 83 |
|
|
| 84 |
1 |
f = new Format("%3.0f"); |
| 85 |
1 |
assertEquals(f.form(123f), "123."); |
| 86 |
1 |
assertEquals(f.form(12f), "12."); |
| 87 |
1 |
assertEquals(f.form(123.4f), "123."); |
| 88 |
1 |
assertEquals(f.form(123.5f), "124."); |
| 89 |
1 |
assertEquals(f.form(123.6f), "124."); |
| 90 |
1 |
assertEquals(f.form(129.6f), "130."); |
| 91 |
|
} |
| 92 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 93 |
1 |
@Test(groups = "Functional")... |
| 94 |
|
public void testRepeat() |
| 95 |
|
{ |
| 96 |
1 |
assertEquals(Format.repeat('a', 3), "aaa"); |
| 97 |
1 |
assertEquals(Format.repeat('b', 0), ""); |
| 98 |
1 |
assertEquals(Format.repeat('c', -1), ""); |
| 99 |
|
} |
| 100 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 101 |
1 |
@Test(groups = "Functional")... |
| 102 |
|
public void testFormat_scientific() |
| 103 |
|
{ |
| 104 |
1 |
Format f = new Format("%3.4e"); |
| 105 |
1 |
double d = 1d; |
| 106 |
1 |
assertEquals(f.form(d), "1.0000e+000"); |
| 107 |
1 |
assertEquals(String.format("%3.4e", d), "1.0000e+00"); |
| 108 |
|
|
| 109 |
1 |
d = 12345678.12345678d; |
| 110 |
1 |
assertEquals(f.form(d), "1.2346e+007"); |
| 111 |
1 |
assertEquals(String.format("%3.4e", d), "1.2346e+07"); |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 118 |
1 |
@Test(groups = "Functional", timeOut = 500)... |
| 119 |
|
public void testFormat_scientific_overflow() |
| 120 |
|
{ |
| 121 |
1 |
Format f = new Format("%3.4e"); |
| 122 |
1 |
double d = 1.12E-310; |
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 130 |
1 |
assertEquals(f.form(d), "1.1200e-310"); |
| 131 |
|
} |
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| |
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 3 |
Complexity Density: 0.19 |
1PASS
|
|
| 137 |
0 |
@Test(groups = "Timing")... |
| 138 |
|
public void testFormat_scientificTiming() |
| 139 |
|
{ |
| 140 |
0 |
Format f = new Format("%3.4e"); |
| 141 |
0 |
double d = 12345678.12345678d; |
| 142 |
|
|
| 143 |
0 |
int iterations = 1000; |
| 144 |
0 |
long start = System.currentTimeMillis(); |
| 145 |
0 |
for (int i = 0; i < iterations; i++) |
| 146 |
|
{ |
| 147 |
0 |
f.form(d); |
| 148 |
|
} |
| 149 |
0 |
long stop = System.currentTimeMillis(); |
| 150 |
0 |
long elapsed1 = stop - start; |
| 151 |
0 |
System.out |
| 152 |
|
.println(iterations + " x Format.form took " + elapsed1 + "ms"); |
| 153 |
|
|
| 154 |
0 |
start = System.currentTimeMillis(); |
| 155 |
0 |
for (int i = 0; i < iterations; i++) |
| 156 |
|
{ |
| 157 |
0 |
String.format("%3.4e", d); |
| 158 |
|
} |
| 159 |
0 |
stop = System.currentTimeMillis(); |
| 160 |
0 |
long elapsed2 = stop - start; |
| 161 |
0 |
System.out.println( |
| 162 |
|
iterations + " x String.format took " + elapsed2 + "ms"); |
| 163 |
0 |
assertTrue(elapsed2 > elapsed1); |
| 164 |
|
} |
| 165 |
|
} |