Changeset 383 for trunk/TestCase/SimpleTestCase/SPrintFTest.ab
- Timestamp:
- Nov 17, 2007, 9:34:36 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/TestCase/SimpleTestCase/SPrintFTest.ab
r371 r383 1 1 '-------------------------------------------------------------------- 2 ' Test case of SPrint FFunction and etc...2 ' Test case of SPrintf Function and etc... 3 3 '-------------------------------------------------------------------- 4 4 … … 8 8 Namespace SPrintFTest 9 9 10 Sub TestMain()10 Sub FormatTest() 11 11 Dim s = Nothing As String, e As Long, sign As Boolean 12 12 … … 19 19 20 20 s = FormatFloatE(9.876543e021, 6, 0, None) 21 UnitTest("FormatFloatE(9876543e+21)", s ="9.876543e+21")21 UnitTest("FormatFloatE(9876543e+21)", s, "9.876543e+21") 22 22 s = FormatFloatE(7.81250000E-03, 8, 0, Cap) 23 UnitTest("FormatFloatE(7.81250000E-03)", s ="7.81250000E-03")23 UnitTest("FormatFloatE(7.81250000E-03)", s, "7.81250000E-03") 24 24 25 25 s = FormatFloatE(1.2345e67, 4, 15, 0) 26 UnitTest("FormatFloatE(1.2345e+67, field width = 15)", s =" 1.2345e+67")26 UnitTest("FormatFloatE(1.2345e+67, field width = 15)", s, " 1.2345e+67") 27 27 s = FormatFloatE(1.2345e67, 4, 15, Zero) 28 UnitTest("FormatFloatE(1.2345e+67, field width = 15, Zero)", s ="000001.2345e+67")28 UnitTest("FormatFloatE(1.2345e+67, field width = 15, Zero)", s, "000001.2345e+67") 29 29 s = FormatFloatE(-1.2345e67, 4, 15, 0) 30 UnitTest("FormatFloatE(-1.2345e+67, field width = 15)", s =" -1.2345e+67")30 UnitTest("FormatFloatE(-1.2345e+67, field width = 15)", s, " -1.2345e+67") 31 31 s = FormatFloatE(-1.2345e67, 4, 15, Zero) 32 UnitTest("FormatFloatE(-1.2345e+67, field width = 15, Zero)", s ="-00001.2345e+67")32 UnitTest("FormatFloatE(-1.2345e+67, field width = 15, Zero)", s, "-00001.2345e+67") 33 33 s = FormatFloatE(1.2345e67, 4, 15, Sign) 34 UnitTest("FormatFloatE(1.2345e+67, field width = 15, Sign)", s =" +1.2345e+67")34 UnitTest("FormatFloatE(1.2345e+67, field width = 15, Sign)", s, " +1.2345e+67") 35 35 s = FormatFloatE(1.2345e67, 4, 15, Zero Or Sign) 36 UnitTest("FormatFloatE(1.2345e+67, field width = 15, Zero Or Sign)", s ="+00001.2345e+67")36 UnitTest("FormatFloatE(1.2345e+67, field width = 15, Zero Or Sign)", s, "+00001.2345e+67") 37 37 s = FormatFloatE(1.2345e67, 4, 15, Zero Or Blank) 38 UnitTest("FormatFloatE(1.2345e+67, field width = 15, Zero Or Blank)", s =" 00001.2345e+67")38 UnitTest("FormatFloatE(1.2345e+67, field width = 15, Zero Or Blank)", s, " 00001.2345e+67") 39 39 s = FormatFloatE(-1.2345e67, 4, 15, Zero Or Sign) 40 UnitTest("FormatFloatE(-1.2345e+67, field width = 15, Zero Or Sign)", s ="-00001.2345e+67")40 UnitTest("FormatFloatE(-1.2345e+67, field width = 15, Zero Or Sign)", s, "-00001.2345e+67") 41 41 s = FormatFloatE(-1.2345e67, 4, 15, Zero Or Blank) 42 UnitTest("FormatFloatE(-1.2345e+67, field width = 15, Zero Or Blank)", s ="-00001.2345e+67")42 UnitTest("FormatFloatE(-1.2345e+67, field width = 15, Zero Or Blank)", s, "-00001.2345e+67") 43 43 44 44 s = FormatFloatE(1.2345e+67, 4, 0, Cap) 45 UnitTest("FormatFloatE(1.2345E+67, Cap)", s ="1.2345E+67")45 UnitTest("FormatFloatE(1.2345E+67, Cap)", s, "1.2345E+67") 46 46 s = FormatFloatE(1.2345e67, 3, 0, None) 47 UnitTest("FormatFloatE(1.2345e+67, precision = 3)", s = "1.234e+67") 48 47 UnitTest("FormatFloatE(1.2345e+67, precision = 3)", s, "1.234e+67") 49 48 50 49 s = FormatIntegerU(777, 0, 0, None) 51 UnitTest("FormatIntegerU(777)", s ="777")50 UnitTest("FormatIntegerU(777)", s, "777") 52 51 s = FormatIntegerU(513, 0, 5, None) 53 UnitTest("FormatIntegerU(513, field width = 5)", s =" 513")52 UnitTest("FormatIntegerU(513, field width = 5)", s, " 513") 54 53 55 54 s = FormatIntegerD(-3, 2, 0, Sign) 56 UnitTest("FormatIntegerD(-3, precision = 2)", s ="-03")55 UnitTest("FormatIntegerD(-3, precision = 2)", s, "-03") 57 56 s = FormatIntegerD(3, 0, 5, Sign) 58 UnitTest("FormatIntegerD(+3, field width = 5)", s =" +3")57 UnitTest("FormatIntegerD(+3, field width = 5)", s, " +3") 59 58 60 59 s = FormatIntegerO(&o1234567, DWORD_MAX, 0, None) 61 UnitTest("FormatIntegerO(&o1234567)", s ="1234567")60 UnitTest("FormatIntegerO(&o1234567)", s, "1234567") 62 61 s = FormatIntegerO(&o1234567, DWORD_MAX, 0, Alt) 63 UnitTest("FormatIntegerO(&o1234567, Alt)", s ="01234567")62 UnitTest("FormatIntegerO(&o1234567, Alt)", s, "01234567") 64 63 s = FormatIntegerO(0, DWORD_MAX, 0, Alt) 65 UnitTest("FormatIntegerO(0, Alt)", s ="0")64 UnitTest("FormatIntegerO(0, Alt)", s, "0") 66 65 67 66 s = FormatIntegerX(&hffff, DWORD_MAX, 0, None) 68 UnitTest("FormatIntegerX(&hffff)", s ="ffff")67 UnitTest("FormatIntegerX(&hffff)", s, "ffff") 69 68 s = FormatIntegerX(&hffff, DWORD_MAX, 0, Cap) 70 UnitTest("FormatIntegerX(&hffff, Cap)", s ="FFFF")69 UnitTest("FormatIntegerX(&hffff, Cap)", s, "FFFF") 71 70 s = FormatIntegerX(&h12345678, DWORD_MAX, 0, Alt) 72 UnitTest("FormatIntegerX(&h12345678, Alt)", s ="0x12345678")71 UnitTest("FormatIntegerX(&h12345678, Alt)", s, "0x12345678") 73 72 s = FormatIntegerX(1, 2, 0, Alt Or Cap) 74 UnitTest("FormatIntegerX(1, precision = 2, Alt, Cap)", s ="0X01")73 UnitTest("FormatIntegerX(1, precision = 2, Alt, Cap)", s, "0X01") 75 74 s = FormatIntegerX(0, 4, 0, Alt) 76 UnitTest("FormatIntegerX(0, precision = 4, Alt)", s ="0000")75 UnitTest("FormatIntegerX(0, precision = 4, Alt)", s, "0000") 77 76 78 77 s = FormatFloatF(1, 2, 0, None) 79 UnitTest("FormatFloatF(1.00, precision = 2)", s ="1.00")78 UnitTest("FormatFloatF(1.00, precision = 2)", s, "1.00") 80 79 s = FormatFloatF(123.456, 3, 0, None) 81 UnitTest("FormatFloatF(123.456, precision = 3)", s ="123.456")80 UnitTest("FormatFloatF(123.456, precision = 3)", s, "123.456") 82 81 s = FormatFloatF(2., 0, 0, Alt) 83 UnitTest("FormatFloatF(2., precision = 0, Alt", s ="2.")82 UnitTest("FormatFloatF(2., precision = 0, Alt", s, "2.") 84 83 s = FormatFloatF(-1.234e-1, 3, 0, None) 85 UnitTest("FormatFloatF(-1.234e-1, precision = 3) = -0.123", s ="-0.123")84 UnitTest("FormatFloatF(-1.234e-1, precision = 3) = -0.123", s, "-0.123") 86 85 s = FormatFloatF(-1.234e-2, 3, 0, None) 87 UnitTest("FormatFloatF(-1.234e-2, precision = 3) = -0.012", s ="-0.012")86 UnitTest("FormatFloatF(-1.234e-2, precision = 3) = -0.012", s, "-0.012") 88 87 s = FormatFloatF(-1.234e-3, 3, 0, None) 89 UnitTest("FormatFloatF(-1.234e-3, precision = 3) = -0.001", s ="-0.001")88 UnitTest("FormatFloatF(-1.234e-3, precision = 3) = -0.001", s, "-0.001") 90 89 s = FormatFloatF(-1.234e-4, 3, 0, None) 91 UnitTest("FormatFloatF(-1.234e-4, precision = 3) = -0.000", s ="-0.000")90 UnitTest("FormatFloatF(-1.234e-4, precision = 3) = -0.000", s, "-0.000") 92 91 '現状では末尾の桁の誤差を制御しきれないので、文字列全体の一致比較を避けている。 93 92 s = FormatFloatF(12345678901234567e3, 2, 0, None) … … 95 94 96 95 s = FormatIntegerLO(&hFFFFFFFFFFFFFFFF, 0, 0, Alt) 97 UnitTest("FormatIntegerLO(&hFFFFFFFFFFFFFFFF, Alt) = 01777777777777777777777", s ="01777777777777777777777")96 UnitTest("FormatIntegerLO(&hFFFFFFFFFFFFFFFF, Alt) = 01777777777777777777777", s, "01777777777777777777777") 98 97 s = FormatIntegerLX(&h123456789abcdef0, 0, 0, None) 99 UnitTest("FormatIntegerLX(&h123456789abcdef0)", s ="123456789abcdef0")98 UnitTest("FormatIntegerLX(&h123456789abcdef0)", s, "123456789abcdef0") 100 99 s = FormatIntegerLU(8589934590 As QWord, DWORD_MAX, 0, None) 101 UnitTest("FormatIntegerLU(8589934590)", s ="8589934590")100 UnitTest("FormatIntegerLU(8589934590)", s, "8589934590") 102 101 s = FormatIntegerLD(-8589934590, DWORD_MAX, 0, None) 103 UnitTest("FormatIntegerLD(-8589934590)", s = "-8589934590") 102 UnitTest("FormatIntegerLD(-8589934590)", s, "-8589934590") 103 104 s = FormatFloatG(1.25, DWORD_MAX, 0, None) 105 UnitTest("FormatFloatG(1.25)", s, "1.25") 106 s = FormatFloatG(0.1, 2, 0, None) 107 UnitTest("FormatFloatG(0.1, precision = 2)", s, "0.1") 108 s = FormatFloatG(1.2e+60, DWORD_MAX, 0, None) 109 UnitTest("FormatFloatG(1.2e+60)", s, "1.2e+60") 110 s = FormatFloatG(1.2e-60, DWORD_MAX, 0, None) 111 UnitTest("FormatFloatG(1.2e-60)", s, "1.2e-60") 112 s = FormatFloatG(1.0, 2, 0, Alt) 113 UnitTest("FormatFloatG(1.0, precision = 2, Alt)", s, "1.0") 114 s = FormatFloatG(0.01, 2, 0, Alt) 115 UnitTest("FormatFloatG(0.01, precision = 2, Alt)", s, "0.010") 116 s = FormatFloatG(0.000123456, 4, 0, None) 117 UnitTest("FormatFloatG(0.000123456, precision = 4) = 0.0001234", s, "0.0001234") 118 s = FormatFloatG(0.0000123456, 4, 0, None) 119 UnitTest("FormatFloatG(0.0000123456, precision = 4) = 1.234e-05", s, "1.234e-05") 120 121 s = FormatFloatA(1, DWORD_MAX, 0, None) 122 UnitTest("FormatFloatA(1)", s, "0x1p+0") 123 s = FormatFloatA(2.2250738585072014e-308, DWORD_MAX, 0, None) 124 UnitTest("FormatFloatA(2.2250738585072014e-308) = 0x1p-1022", s, "0x1p-1022") 125 s = FormatFloatA(1.11253692925360070e-308, DWORD_MAX, 0, None) 126 UnitTest("FormatFloatA(1.11253692925360070e-308) = 0x0.fp-1022", s, "0x0.8p-1022") 127 s = FormatFloatA(3.1415926535897932384626433832795, DWORD_MAX, 0, None) 128 UnitTest("FormatFloatA(π) = 0x1.921fb54442d18p+1", s, "0x1.921fb54442d18p+1") 129 s = FormatFloatA(0, DWORD_MAX, 0, None) 130 UnitTest("FormatFloatA(0)", s, "0x0p+0") 131 132 s = FormatString("123456", DWORD_MAX, 0, None) 133 UnitTest(Ex"FormatString(\q123456\q)", s, "123456") 134 s = FormatString("123456", 3, 0, None) 135 UnitTest(Ex"FormatString(\q123456\q, precision = 3) = \q123\q", s, "123") 136 s = FormatString("123456", 3, 6, None) 137 UnitTest(Ex"FormatString(\q123456\q, precision = 3, field width = 6) = \q 123\q", 138 s, " 123") 139 140 s = FormatCharacter(Asc("Y"), DWORD_MAX, 0, None) 141 UnitTest(Ex"FormatCharacter(\qY\q)", s, "Y") 142 s = FormatCharacter(Asc("I"), DWORD_MAX, 3, Left) 143 UnitTest(Ex"FormatCharacter(\qI\q, Left)", s, "I ") 104 144 End Sub 105 145 146 Sub TestMain() 147 FormatTest() 148 149 Imports System 150 151 UnitTest(Ex"SPrintf(\q123\q)", ActiveBasic.Strings.Detail.SPrintf("'123'", 0, 0), "'123'") 152 UnitTest(Ex"%s, \qhello\q", SPrintf("'%s'", "hello"), "'hello'") 153 UnitTest(Ex"%7s, \qhello\q", SPrintf("'%7s'", "hello"), "' hello'") 154 UnitTest(Ex"%*s, -7, \qhello\q", SPrintf("'%*s'", New Int32(-7), "hello"), "'hello '") 155 UnitTest(Ex"%.3s, \qhello\q", SPrintf("'%.3s'", "hello"), "'hel'") 156 UnitTest(Ex"%.*s, 4, \qhello\q", SPrintf("'%.*s'", New Int32(4), "hello"), "'hell'") 157 UnitTest(Ex"%-5.3s, \qhello\q", SPrintf("'%-5.3s'", "hello"), "'hel '") 158 UnitTest(Ex"%*.*s, 2, 1, \qhello\q", SPrintf("'%*.*s'", New Int32(2), New Int32(1), "hello"), "' h'") 159 #ifdef UNICODE 160 UnitTest(Ex"%c, '0'", SPrintf("'%c'", New System.UInt16(&h30)), "'0'") 161 #else 162 UnitTest(Ex"%c, '0'", SPrintf("'%c'", New System.SByte(&h30)), "'0'") 163 #endif 164 Dim i = Nothing As Object, mi = Nothing As Object 165 i = New Int32(10) 166 mi = New Int32(-10) 167 UnitTest(Ex"%d, 10", SPrintf("'%d'", i), "'10'") 168 UnitTest(Ex"%+d, 10", SPrintf("'%+d'", i), "'+10'") 169 UnitTest(Ex"% d, 10", SPrintf("'% d'", i), "' 10'") 170 UnitTest(Ex"%4d, 10", SPrintf("'%4d'", i), "' 10'") 171 UnitTest(Ex"%4d, -10", SPrintf("'%4d'", mi), "' -10'") 172 UnitTest(Ex"%04d, 10", SPrintf("'%04d'", i), "'0010'") 173 UnitTest(Ex"%04d, -10", SPrintf("'%04d'", mi), "'-010'") 174 UnitTest(Ex"%5.3d, 10", SPrintf("'%5.3d'", i), "' 010'") 175 176 UnitTest(Ex"%i, 10", SPrintf("'%i'", i), "'10'") 177 UnitTest(Ex"%ld, -4294967296", SPrintf("'%ld'", New System.Int64(-4294967296)), "'-4294967296'") 178 UnitTest(Ex"%li, -4294967296", SPrintf("'%li'", New System.Int64(-4294967296)), "'-4294967296'") 179 UnitTest(Ex"%u, 4294967295", SPrintf("'%u'", New UInt32(4294967295)), "'4294967295'") 180 UnitTest(Ex"%lu, 4294967296", SPrintf("'%lu'", New UInt64(4294967296)), "'4294967296'") 181 UnitTest(Ex"%x, ffffffff", SPrintf("'%x'", New UInt32(4294967295)), "'ffffffff'") 182 UnitTest(Ex"%#x, 0xffffffff", SPrintf("'%#x'", New UInt32(4294967295)), "'0xffffffff'") 183 UnitTest(Ex"%&x, &hffffffff", SPrintf("'%&x'", New UInt32(4294967295)), "'&hffffffff'") 184 UnitTest(Ex"%lx, 12345789abcdef", SPrintf("'%lx'", New UInt64(&h12345789abcdef)), "'12345789abcdef'") 185 UnitTest(Ex"%lX, 12345789ABCDEF", SPrintf("'%lX'", New UInt64(&h12345789abcdef)), "'12345789ABCDEF'") 186 Dim o777 = Nothing As Object 187 o777 = New UInt32(&o777) 188 UnitTest(Ex"%o, 777", SPrintf("'%o'", o777), "'777'") 189 UnitTest(Ex"%#o, 0777", SPrintf("'%#o'", o777), "'0777'") 190 UnitTest(Ex"%&o, &o777", SPrintf("'%&o'", o777), "'&o777'") 191 UnitTest(Ex"%&O, &O777", SPrintf("'%&O'", o777), "'&O777'") 192 UnitTest(Ex"%lo, 100000000000", SPrintf("'%lo'", New UInt64(&o100000000000)), "'100000000000'") 193 194 Dim d = Nothing As Object 195 d = New System.Double(123.25) 196 UnitTest(Ex"%g, 123.25", SPrintf("'%g'", d), "'123.25'") 197 UnitTest(Ex"%f, 123.25", SPrintf("'%f'", d), "'123.250000'") 198 UnitTest(Ex"%e, 123.25", SPrintf("'%e'", d), "'1.232500e+02'") 199 UnitTest(Ex"%a, 123.25", SPrintf("'%a'", d), "'0x1.edp+6'") 200 201 UnitTest(Ex"%%", SPrintf("'%%'", d), "'%'") 202 End Sub 203 106 204 End Namespace 'SPrintFTest 107 205
Note:
See TracChangeset
for help on using the changeset viewer.