001: package jfb.tst.tools.activitymgr.core.util;
002:
003: import jfb.tools.activitymgr.core.util.StringFormatException;
004: import jfb.tools.activitymgr.core.util.StringHelper;
005: import junit.framework.TestCase;
006:
007: public class StringHelperTest extends TestCase {
008:
009: public static void main(String[] args) {
010: junit.swingui.TestRunner.run(StringHelperTest.class);
011: }
012:
013: public void test0() {
014: assertEquals("00", StringHelper.toHex((byte) 0));
015: }
016:
017: public void test10() {
018: assertEquals("0A", StringHelper.toHex((byte) 10));
019: }
020:
021: public void test255() {
022: assertEquals("FF", StringHelper.toHex((byte) 255));
023: }
024:
025: public void test0x00() {
026: assertEquals((byte) 0, StringHelper.toByte("0"));
027: }
028:
029: public void test0x10() {
030: assertEquals((byte) 10, StringHelper.toByte("0A"));
031: }
032:
033: public void test0xFF() {
034: assertEquals((byte) 255, StringHelper.toByte("FF"));
035: }
036:
037: public void test1ToEntry() {
038: assertEquals("0.01", StringHelper.hundredthToEntry(1));
039: }
040:
041: public void test10ToEntry() {
042: assertEquals("0.10", StringHelper.hundredthToEntry(10));
043: }
044:
045: public void test100ToEntry() {
046: assertEquals("1.00", StringHelper.hundredthToEntry(100));
047: }
048:
049: public void test123ToEntry() {
050: assertEquals("1.23", StringHelper.hundredthToEntry(123));
051: }
052:
053: public void test1234567890ToEntry() {
054: assertEquals("12345678.90", StringHelper
055: .hundredthToEntry(1234567890));
056: }
057:
058: public void test0_00ToHundredth() throws StringFormatException {
059: assertEquals(0, StringHelper.entryToHundredth("0.00"));
060: }
061:
062: public void test0_01ToHundredth() throws StringFormatException {
063: assertEquals(1, StringHelper.entryToHundredth("0.01"));
064: }
065:
066: public void test0_10ToHundredth() throws StringFormatException {
067: assertEquals(10, StringHelper.entryToHundredth("0.10"));
068: assertEquals(10, StringHelper.entryToHundredth("0.1"));
069: }
070:
071: public void test1_00ToHundredth() throws StringFormatException {
072: assertEquals(100, StringHelper.entryToHundredth("1.00"));
073: assertEquals(100, StringHelper.entryToHundredth("1.0"));
074: assertEquals(100, StringHelper.entryToHundredth("1"));
075: }
076:
077: public void test01_00ToHundredth() throws StringFormatException {
078: assertEquals(100, StringHelper.entryToHundredth("01.00"));
079: assertEquals(100, StringHelper.entryToHundredth("01.0"));
080: assertEquals(100, StringHelper.entryToHundredth("01"));
081: }
082:
083: public void test1_23ToHundredth() throws StringFormatException {
084: assertEquals(123, StringHelper.entryToHundredth("1.23"));
085: }
086:
087: public void test12345678_90ToHundredth()
088: throws StringFormatException {
089: assertEquals(1234567890, StringHelper
090: .entryToHundredth("12345678.90"));
091: assertEquals(1234567890, StringHelper
092: .entryToHundredth("12345678.9"));
093: }
094:
095: public void test0_001ToHundredth() {
096: try {
097: StringHelper.entryToHundredth("0.001");
098: fail("3 digits is supposed to be too much");
099: } catch (StringFormatException ignored) {
100: }
101: }
102:
103: public void test1_234ToHundredth() {
104: try {
105: StringHelper.entryToHundredth("1.234");
106: fail("3 digits is supposed to be too much");
107: } catch (StringFormatException ignored) {
108: }
109: }
110:
111: }
|