package omino.utilities; import junit.framework.TestCase; public class TestOmStrings extends TestCase { public void testToBoolean() { checkBool("",false); checkBool("true",true); checkBool("tRue",true); checkBool("FAlse",false); checkBool("no",false); checkBool("0",false); checkBool("0.1",true); checkBool(null,false); } private void checkBool(String s,boolean expected) { boolean b = OmStrings.toBoolean(s); assertEquals("OmStrings.toBool of " + s,expected,b); } public void testIsDouble() { checkIsDbl("3",true); checkIsDbl("3.5",true); checkIsDbl("3.5e8",true); checkIsDbl("fish",false); checkIsDbl(null,false); checkIsDbl("",false); } private void checkIsDbl(String s,boolean expected) { boolean b = OmStrings.isDouble(s); assertEquals("OmStrings.isDouble of " + s,expected,b); } public void testIsInt() { checkIsInt("3",true); checkIsInt("0x23",true); checkIsInt(null,false); checkIsInt("",false); checkIsInt("fish",false); checkIsInt("1e4",true); } private void checkIsInt(String s,boolean expected) { boolean b = OmStrings.isInt(s); assertEquals("OmStrings.isInt of " + s,expected,b); } public void testTo0xHexString() { assertEquals("0x04",OmStrings.longTo0xHexString(4, 2)); } public void testToDouble() { assertEquals(20d,OmStrings.toDouble("20")); assertEquals(20d,OmStrings.toDouble("20 and a fish")); } }