-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathDouble_Parse.pas
141 lines (110 loc) · 4.41 KB
/
Double_Parse.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
namespace Island.Tests.Shared;
uses
RemObjects.Elements.EUnit;
type
Double_Parse = public class(Test)
private
fLocale : Locale;
method doTest(aValue: Double);
begin
Assert.AreEqual(aValue.ToString(fLocale), Double.Parse(aValue.ToString(fLocale), fLocale).ToString(fLocale));
// Check.AreEqual(aValue.ToString, Double.Parse(aValue.ToString).ToString);
end;
method doTest2(aStrValue: String;aValue: Double);
begin
Assert.AreEqual(aValue.ToString(Locale.Invariant), Double.Parse(aStrValue, Locale.Invariant).ToString(Locale.Invariant));
end;
method doTest3(aValue: Double);
begin
var res: Double;
Assert.AreEqual(false, Double.TryParse(aValue.ToString(fLocale), fLocale, out res));
end;
public
method SetupTest; override;
begin
//fLocale := new Locale(Locale.Invariant.PlatformLocale);
fLocale := new Locale(Locale.Current.PlatformLocale);
end;
method TestStd;
begin
doTest(123456);
doTest(-123456);
doTest(123.456);
doTest(-123.456E-10);
doTest(123.456E+10);
doTest2('+12345E-2',+12345E-2);
doTest2('+12345E+2',+12345E+2);
doTest2('-12345E2',-12345E2);
doTest2('-1234567890123456789012345678901234567890123456789012345678901234567890.123456789012345678901234567890E10',
-1234567890123456789012345678901234567890123456789012345678901234567890.123456789012345678901234567890E10);
doTest2('-1234567890123456789012345678901234567890123456789012345678901234567890.123456789012345678901234567890E-10',
-1234567890123456789012345678901234567890123456789012345678901234567890.123456789012345678901234567890E-10);
doTest2('-1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.0',
-1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.0);
doTest2('-1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890E-40',
-1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890E-40);
doTest2('1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890E40',
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890E40);
end;
method TestOverflow;
begin
doTest3(Double.MaxValue);
doTest3(Double.MinValue);
doTest3(Double.PositiveInfinity);
doTest3(Double.NegativeInfinity);
doTest3(Double.NaN);
end;
end;
Single_Parse = public class(Test)
private
fLocale : Locale;
method doTest(aValue: Single);
begin
Assert.AreEqual(aValue.ToString(fLocale), Single.Parse(aValue.ToString(fLocale), fLocale).ToString(fLocale));
end;
method doTest2(aStrValue: String;aValue: Single);
begin
Assert.AreEqual(aValue.ToString(Locale.Invariant), Single.Parse(aStrValue, Locale.Invariant).ToString(Locale.Invariant));
end;
method doTest3(aValue: Single);
begin
var res: Single;
Assert.AreEqual(false, Single.TryParse(aValue.ToString(fLocale), fLocale, out res));
end;
public
method SetupTest; override;
begin
// fLocale := new Locale(Locale.Invariant.PlatformLocale);
fLocale := new Locale(Locale.Current.PlatformLocale);
end;
method TestStd;
begin
doTest(123456);
doTest(-123456);
doTest(123.456);
doTest(-123.456E-10);
doTest(123.456E+10);
doTest(Single.MaxValue);
doTest(Single.MinValue);
doTest(Single.MaxValue);
doTest(Single.MinValue);
doTest2('+12345E-2',+12345E-2);
doTest2('+12345E+2',+12345E+2);
doTest2('-12345E2',-12345E2);
doTest2( '-123456789012345678.90123456789e1',
Single(-123456789012345678.90123456789e1));
doTest2( '-12345678901234567890123456789.0',
Single(-12345678901234567890123456789.0));
doTest2( '-12345678901234567890123456789E-2',
Single(-12345678901234567890123456789E-2));
doTest2( '123456789012345678901234567890E9',
Single(123456789012345678901234567890E9));
end;
method TestOverflow;
begin
doTest3(Single.PositiveInfinity);
doTest3(Single.NegativeInfinity);
doTest3(Single.NaN);
end;
end;
end.