From: Niki Roo Date: Fri, 12 Apr 2019 08:01:50 +0000 (+0200) Subject: new tests (wip) for from/to number X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=00b43c19e0563e0916c1cc9d5ffd573bfc92693d;p=fanfix-jexer.git new tests (wip) for from/to number --- diff --git a/src/be/nikiroo/utils/test/StringUtilsTest.java b/src/be/nikiroo/utils/test/StringUtilsTest.java index e35be4f..5280181 100644 --- a/src/be/nikiroo/utils/test/StringUtilsTest.java +++ b/src/be/nikiroo/utils/test/StringUtilsTest.java @@ -228,6 +228,35 @@ class StringUtilsTest extends TestLauncher { assertEquals(orig, unzipped); } }); + + addTest(new TestCase("from/toNumber") { + @Override + public void test() throws Exception { + assertEquals(StringUtils.toNumber("263"), 263l); + assertEquals(StringUtils.toNumber("21200"), 21200l); + assertEquals(StringUtils.toNumber("0"), 0l); + assertEquals(StringUtils.formatNumber(263l), "263"); + assertEquals(StringUtils.formatNumber(21000l), "21k"); + assertEquals(StringUtils.formatNumber(0l), "0"); + + assertEquals(StringUtils.formatNumber(1287l, false), "1287"); + assertEquals(StringUtils.formatNumber(6056l, false), "6k"); + + assertEquals(StringUtils.toNumber("263k"), 263000l); + assertEquals(StringUtils.toNumber("42k"), 42000l); + assertEquals(StringUtils.toNumber("12M"), 12000000l); + assertEquals(StringUtils.formatNumber(263012l), "263k"); + assertEquals(StringUtils.formatNumber(42012l), "42k"); + assertEquals(StringUtils.formatNumber(12012121212l), "12M"); + + assertEquals(StringUtils.toNumber("263.2k"), 263200l); + assertEquals(StringUtils.toNumber("1.2k"), 1200l); + assertEquals(StringUtils.toNumber("42.7M"), 42700000000l); + assertEquals(StringUtils.formatNumber(263202l), "263.2k"); + assertEquals(StringUtils.formatNumber(1267l), "1.2k"); + assertEquals(StringUtils.formatNumber(42712121212l), "42.7M"); + } + }); } static private void addValue(