2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static org.testng.Assert.assertEquals;
25 import jalview.gui.JvOptionPane;
27 import org.testng.annotations.BeforeClass;
28 import org.testng.annotations.Test;
30 public class FormatTest
33 @BeforeClass(alwaysRun = true)
34 public void setUpJvOptionPane()
36 JvOptionPane.setInteractiveMode(false);
37 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
40 @Test(groups = "Functional")
41 public void testAppendPercentage()
43 StringBuilder sb = new StringBuilder();
44 Format.appendPercentage(sb, 123.436f, 0);
45 assertEquals(sb.toString(), "123");
48 Format.appendPercentage(sb, 123.536f, 0);
49 assertEquals(sb.toString(), "124");
52 Format.appendPercentage(sb, 799.536f, 0);
53 assertEquals(sb.toString(), "800");
56 Format.appendPercentage(sb, 123.436f, 1);
57 assertEquals(sb.toString(), "123.4");
60 Format.appendPercentage(sb, 123.436f, 2);
61 assertEquals(sb.toString(), "123.44");
64 Format.appendPercentage(sb, 123.436f, 3);
65 assertEquals(sb.toString(), "123.436");
68 Format.appendPercentage(sb, 123.436f, 4);
69 assertEquals(sb.toString(), "123.4360");
72 @Test(groups = "Functional")
73 public void testForm_float()
75 Format f = new Format("%3.2f");
76 assertEquals(f.form(123f), "123.00");
77 assertEquals(f.form(123.1f), "123.10");
78 assertEquals(f.form(123.12f), "123.12");
79 assertEquals(f.form(123.124f), "123.12");
80 assertEquals(f.form(123.125f), "123.13");
81 assertEquals(f.form(123.126f), "123.13");
83 f = new Format("%3.0f");
84 assertEquals(f.form(123f), "123.");
85 assertEquals(f.form(12f), "12.");
86 assertEquals(f.form(123.4f), "123.");
87 assertEquals(f.form(123.5f), "124.");
88 assertEquals(f.form(123.6f), "124.");
89 assertEquals(f.form(129.6f), "130.");
92 @Test(groups = "Functional")
93 public void testRepeat()
95 assertEquals(Format.repeat('a', 3), "aaa");
96 assertEquals(Format.repeat('b', 0), "");
97 assertEquals(Format.repeat('c', -1), "");