X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2FFormatTest.java;fp=test%2Fjalview%2Futil%2FFormatTest.java;h=d957b7c9344e8e676aeb6ffaf5e1e97df37e7817;hb=7d67fb613ec026dc9a265e351e7fab542e3f1d61;hp=0000000000000000000000000000000000000000;hpb=02e38bb826828ab2991584cf4b737c0138cb6c44;p=jalview.git diff --git a/test/jalview/util/FormatTest.java b/test/jalview/util/FormatTest.java new file mode 100644 index 0000000..d957b7c --- /dev/null +++ b/test/jalview/util/FormatTest.java @@ -0,0 +1,88 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.util; + +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +public class FormatTest +{ + @Test(groups = "Functional") + public void testAppendPercentage() + { + StringBuilder sb = new StringBuilder(); + Format.appendPercentage(sb, 123.436f, 0); + assertEquals(sb.toString(), "123"); + + sb.setLength(0); + Format.appendPercentage(sb, 123.536f, 0); + assertEquals(sb.toString(), "124"); + + sb.setLength(0); + Format.appendPercentage(sb, 799.536f, 0); + assertEquals(sb.toString(), "800"); + + sb.setLength(0); + Format.appendPercentage(sb, 123.436f, 1); + assertEquals(sb.toString(), "123.4"); + + sb.setLength(0); + Format.appendPercentage(sb, 123.436f, 2); + assertEquals(sb.toString(), "123.44"); + + sb.setLength(0); + Format.appendPercentage(sb, 123.436f, 3); + assertEquals(sb.toString(), "123.436"); + + sb.setLength(0); + Format.appendPercentage(sb, 123.436f, 4); + assertEquals(sb.toString(), "123.4360"); + } + + @Test(groups = "Functional") + public void testForm_float() + { + Format f = new Format("%3.2f"); + assertEquals(f.form(123f), "123.00"); + assertEquals(f.form(123.1f), "123.10"); + assertEquals(f.form(123.12f), "123.12"); + assertEquals(f.form(123.124f), "123.12"); + assertEquals(f.form(123.125f), "123.13"); + assertEquals(f.form(123.126f), "123.13"); + + f = new Format("%3.0f"); + assertEquals(f.form(123f), "123."); + assertEquals(f.form(12f), "12."); + assertEquals(f.form(123.4f), "123."); + assertEquals(f.form(123.5f), "124."); + assertEquals(f.form(123.6f), "124."); + assertEquals(f.form(129.6f), "130."); + } + + @Test(groups = "Functional") + public void testRepeat() + { + assertEquals(Format.repeat('a', 3), "aaa"); + assertEquals(Format.repeat('b', 0), ""); + assertEquals(Format.repeat('c', -1), ""); + } +}