source: trunk/TestCase/SimpleTestCase/SPrintFTest.ab@ 374

Last change on this file since 374 was 371, checked in by dai, 17 years ago

ActiveBasic.Strings.SPrintFクラスを標準ライブラリに含めた

File size: 5.0 KB
Line 
1'--------------------------------------------------------------------
2' Test case of SPrintF Function and etc...
3'--------------------------------------------------------------------
4
5Imports ActiveBasic.Strings
6Imports ActiveBasic.Strings.Detail
7
8Namespace SPrintFTest
9
10Sub TestMain()
11 Dim s = Nothing As String, e As Long, sign As Boolean
12
13 s = FloatToChars(1., e, sign)
14 UnitTest("FloatToChars(1)", s = "10000000000000000" And e = 0 And sign = False)
15 s = FloatToChars(-93.75e-3, e, sign)
16 UnitTest("FloatToChars(-93.75e-3)", s = "93750000000000000" And e = 1 - 3 And sign = True)
17 s = FloatToChars(.0, e, sign)
18 UnitTest("FloatToChars(0)", s = "00000000000000000" And e = 0 And sign = False)
19
20 s = FormatFloatE(9.876543e021, 6, 0, None)
21 UnitTest("FormatFloatE(9876543e+21)", s = "9.876543e+21")
22 s = FormatFloatE(7.81250000E-03, 8, 0, Cap)
23 UnitTest("FormatFloatE(7.81250000E-03)", s = "7.81250000E-03")
24
25 s = FormatFloatE(1.2345e67, 4, 15, 0)
26 UnitTest("FormatFloatE(1.2345e+67, field width = 15)", s = " 1.2345e+67")
27 s = FormatFloatE(1.2345e67, 4, 15, Zero)
28 UnitTest("FormatFloatE(1.2345e+67, field width = 15, Zero)", s = "000001.2345e+67")
29 s = FormatFloatE(-1.2345e67, 4, 15, 0)
30 UnitTest("FormatFloatE(-1.2345e+67, field width = 15)", s = " -1.2345e+67")
31 s = FormatFloatE(-1.2345e67, 4, 15, Zero)
32 UnitTest("FormatFloatE(-1.2345e+67, field width = 15, Zero)", s = "-00001.2345e+67")
33 s = FormatFloatE(1.2345e67, 4, 15, Sign)
34 UnitTest("FormatFloatE(1.2345e+67, field width = 15, Sign)", s = " +1.2345e+67")
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")
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")
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")
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")
43
44 s = FormatFloatE(1.2345e+67, 4, 0, Cap)
45 UnitTest("FormatFloatE(1.2345E+67, Cap)", s = "1.2345E+67")
46 s = FormatFloatE(1.2345e67, 3, 0, None)
47 UnitTest("FormatFloatE(1.2345e+67, precision = 3)", s = "1.234e+67")
48
49
50 s = FormatIntegerU(777, 0, 0, None)
51 UnitTest("FormatIntegerU(777)", s = "777")
52 s = FormatIntegerU(513, 0, 5, None)
53 UnitTest("FormatIntegerU(513, field width = 5)", s = " 513")
54
55 s = FormatIntegerD(-3, 2, 0, Sign)
56 UnitTest("FormatIntegerD(-3, precision = 2)", s = "-03")
57 s = FormatIntegerD(3, 0, 5, Sign)
58 UnitTest("FormatIntegerD(+3, field width = 5)", s = " +3")
59
60 s = FormatIntegerO(&o1234567, DWORD_MAX, 0, None)
61 UnitTest("FormatIntegerO(&o1234567)", s = "1234567")
62 s = FormatIntegerO(&o1234567, DWORD_MAX, 0, Alt)
63 UnitTest("FormatIntegerO(&o1234567, Alt)", s = "01234567")
64 s = FormatIntegerO(0, DWORD_MAX, 0, Alt)
65 UnitTest("FormatIntegerO(0, Alt)", s = "0")
66
67 s = FormatIntegerX(&hffff, DWORD_MAX, 0, None)
68 UnitTest("FormatIntegerX(&hffff)", s = "ffff")
69 s = FormatIntegerX(&hffff, DWORD_MAX, 0, Cap)
70 UnitTest("FormatIntegerX(&hffff, Cap)", s = "FFFF")
71 s = FormatIntegerX(&h12345678, DWORD_MAX, 0, Alt)
72 UnitTest("FormatIntegerX(&h12345678, Alt)", s = "0x12345678")
73 s = FormatIntegerX(1, 2, 0, Alt Or Cap)
74 UnitTest("FormatIntegerX(1, precision = 2, Alt, Cap)", s = "0X01")
75 s = FormatIntegerX(0, 4, 0, Alt)
76 UnitTest("FormatIntegerX(0, precision = 4, Alt)", s = "0000")
77
78 s = FormatFloatF(1, 2, 0, None)
79 UnitTest("FormatFloatF(1.00, precision = 2)", s = "1.00")
80 s = FormatFloatF(123.456, 3, 0, None)
81 UnitTest("FormatFloatF(123.456, precision = 3)", s = "123.456")
82 s = FormatFloatF(2., 0, 0, Alt)
83 UnitTest("FormatFloatF(2., precision = 0, Alt", s = "2.")
84 s = FormatFloatF(-1.234e-1, 3, 0, None)
85 UnitTest("FormatFloatF(-1.234e-1, precision = 3) = -0.123", s = "-0.123")
86 s = FormatFloatF(-1.234e-2, 3, 0, None)
87 UnitTest("FormatFloatF(-1.234e-2, precision = 3) = -0.012", s = "-0.012")
88 s = FormatFloatF(-1.234e-3, 3, 0, None)
89 UnitTest("FormatFloatF(-1.234e-3, precision = 3) = -0.001", s = "-0.001")
90 s = FormatFloatF(-1.234e-4, 3, 0, None)
91 UnitTest("FormatFloatF(-1.234e-4, precision = 3) = -0.000", s = "-0.000")
92 '現状では末尾の桁の誤差を制御しきれないので、文字列全体の一致比較を避けている。
93 s = FormatFloatF(12345678901234567e3, 2, 0, None)
94 UnitTest("FormatFloatF(1.00, precision = 2)", Right$(s, 6) = "000.00")
95
96 s = FormatIntegerLO(&hFFFFFFFFFFFFFFFF, 0, 0, Alt)
97 UnitTest("FormatIntegerLO(&hFFFFFFFFFFFFFFFF, Alt) = 01777777777777777777777", s = "01777777777777777777777")
98 s = FormatIntegerLX(&h123456789abcdef0, 0, 0, None)
99 UnitTest("FormatIntegerLX(&h123456789abcdef0)", s = "123456789abcdef0")
100 s = FormatIntegerLU(8589934590 As QWord, DWORD_MAX, 0, None)
101 UnitTest("FormatIntegerLU(8589934590)", s = "8589934590")
102 s = FormatIntegerLD(-8589934590, DWORD_MAX, 0, None)
103 UnitTest("FormatIntegerLD(-8589934590)", s = "-8589934590")
104End Sub
105
106End Namespace 'SPrintFTest
107
108SPrintFTest.TestMain()
Note: See TracBrowser for help on using the repository browser.