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 org.testng.annotations.Test;
27 public class FormatTest
29 @Test(groups = "Functional")
30 public void testAppendPercentage()
32 StringBuilder sb = new StringBuilder();
33 Format.appendPercentage(sb, 123.436f, 0);
34 assertEquals(sb.toString(), "123");
37 Format.appendPercentage(sb, 123.536f, 0);
38 assertEquals(sb.toString(), "124");
41 Format.appendPercentage(sb, 799.536f, 0);
42 assertEquals(sb.toString(), "800");
45 Format.appendPercentage(sb, 123.436f, 1);
46 assertEquals(sb.toString(), "123.4");
49 Format.appendPercentage(sb, 123.436f, 2);
50 assertEquals(sb.toString(), "123.44");
53 Format.appendPercentage(sb, 123.436f, 3);
54 assertEquals(sb.toString(), "123.436");
57 Format.appendPercentage(sb, 123.436f, 4);
58 assertEquals(sb.toString(), "123.4360");
61 @Test(groups = "Functional")
62 public void testForm_float()
64 Format f = new Format("%3.2f");
65 assertEquals(f.form(123f), "123.00");
66 assertEquals(f.form(123.1f), "123.10");
67 assertEquals(f.form(123.12f), "123.12");
68 assertEquals(f.form(123.124f), "123.12");
69 assertEquals(f.form(123.125f), "123.13");
70 assertEquals(f.form(123.126f), "123.13");
72 f = new Format("%3.0f");
73 assertEquals(f.form(123f), "123.");
74 assertEquals(f.form(12f), "12.");
75 assertEquals(f.form(123.4f), "123.");
76 assertEquals(f.form(123.5f), "124.");
77 assertEquals(f.form(123.6f), "124.");
78 assertEquals(f.form(129.6f), "130.");
81 @Test(groups = "Functional")
82 public void testRepeat()
84 assertEquals(Format.repeat('a', 3), "aaa");
85 assertEquals(Format.repeat('b', 0), "");
86 assertEquals(Format.repeat('c', -1), "");