ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/Test21.pas
(Generate patch)

Comparing ibx/trunk/fbintf/testsuite/Test21.pas (file contents):
Revision 353 by tony, Sat Oct 23 14:11:37 2021 UTC vs.
Revision 402 by tony, Mon Aug 1 10:07:24 2022 UTC

# Line 52 | Line 52 | type
52    private
53      procedure UpdateDatabase(Attachment: IAttachment);
54      procedure QueryDatabase(Attachment: IAttachment);
55 +    procedure ValidateStrToNumeric;
56 +    procedure ValidateNumericInterface;
57    public
58      function TestTitle: AnsiString; override;
59      procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
# Line 61 | Line 63 | type
63  
64   implementation
65  
66 + uses FBNumeric, FmtBCD;
67 +
68   const
69    sqlCreateTable =
70      'Create Table TestData ('+
# Line 142 | Line 146 | begin
146    except on E: Exception do
147      writeln(Outfile,'Expected Error - ',E.Message);
148    end;
149 <
149 >  writeln(OutFile,'Test Numeric Type');
150 >  with Statement.GetSQLParams do
151 >  begin
152 >    Clear;
153 >    Params[0].AsInteger := 7;
154 >    Params[1].AsNumeric := DoubleToNumeric(1.0);
155 >    Params[2].AsVariant := 1234567;
156 >    Params[3].AsNumeric := DoubleToNumeric(StrToFloat('2.3E-2'));
157 >    Params[4].AsNumeric := StrToNumeric('11e-4');
158 >    Params[5].AsVariant := 1234.25;
159 >  end;
160 >  Statement.Execute;
161   end;
162  
163   procedure TTest21.QueryDatabase(Attachment: IAttachment);
# Line 154 | Line 169 | begin
169    ReportResults(Statement);
170   end;
171  
172 + procedure TTest21.ValidateStrToNumeric;
173 + const
174 +  TestValues: array of string = ['1234.567','-765.4321','0.1','0.01','+123',
175 +                                 '1.23456E308','-1.2e-02','10.','.12', '0.12',
176 +                                 '1.2E1.2', '1,000', '1e1e1', '1.2+3']; {bad syntax}
177 + var
178 +  i: integer;
179 +  aValue: Int64;
180 +  aScale: integer;
181 + begin
182 +  for i := 0 to Length(TestValues) - 1 do
183 +  begin
184 +    if TryStrToNumeric(TestValues[i],aValue,aScale) then
185 +    begin
186 +      writeln(Outfile,TestValues[i],' parsed to ',aValue,' scale = ',aScale);
187 +      writeln(Outfile,'As Float = ',NumericToDouble(aValue,aScale));
188 +    end
189 +    else
190 +      writeln(Outfile,'Parsing of ',TestValues[i],' failed');
191 +  end;
192 + end;
193 +
194 + procedure TTest21.ValidateNumericInterface;
195 + var numeric: IFBNumeric;
196 + begin
197 +  writeln(Outfile,'Validating Numeric Interface - IFBNumeric');
198 +  numeric := CurrToNumeric(StrToCurr('9999.123456780'));
199 +  writeln(Outfile,'Value from Currency = ',numeric.getAsString);
200 +  writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale);
201 +  numeric := CurrToNumeric(StrToCurr('9999.123456780')).AdjustScaleTo(-2);
202 +  writeln(Outfile,'Value from Currency(rescaled) = ',numeric.getAsString);
203 +  writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale);
204 +  numeric := DoubleToNumeric(StrToFloat('9999.123456780'));
205 +  writeln(Outfile,'Value from Double = ',numeric.getAsString);
206 +  writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale);
207 +  numeric := IntToNumeric(StrToInt64('9223372036854775807'));
208 +  writeln(Outfile,'Value from Integer = ',numeric.getAsString);
209 +  writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale);
210 +  numeric := StrToNumeric('9223372036854775807');
211 +  writeln(Outfile,'Value from string = ',numeric.getAsString);
212 +  writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale);
213 +  numeric := StrToNumeric('9999.123456780');
214 +  writeln(Outfile,'Value from string = ',numeric.getAsString);
215 +  writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale);
216 +  numeric := StrToNumeric('-1.2e-02');
217 +  writeln(Outfile,'Value from string = ',numeric.getAsString);
218 +  writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale);
219 +  try
220 +    numeric := BCDToNumeric(StrToBCD('9999.123456780'));
221 +    writeln(Outfile,'Value from BCD = ',numeric.getAsString);
222 +    writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale);
223 +  except on E:Exception do
224 +    writeln(OutFile,'Delphi has a problem with this number: ',E.Message);
225 +  end;
226 +  numeric := NumericFromRawValues(9999123456780,-6);
227 +  writeln(Outfile,'Value from Raw Data = ',numeric.getAsString);
228 +  writeln(Outfile,'Raw Value = ',numeric.getRawValue,' Scale = ',numeric.getScale);
229 +
230 +  writeln(outfile,'Numeric Operations');
231 +  writeln(Outfile,'Add 2.23 + 24.12345 = ',NumericAdd(StrToNumeric('2.23'),StrToNumeric('24.12345')).GetAsString);
232 +  writeln(Outfile,'Add Double 2.23 + 24.12645 = ',NumericAdd(StrToNumeric('2.23'),24.12645).GetAsString);
233 +  writeln(Outfile,'Add integer 2.23 + 2412345 = ',NumericAdd(StrToNumeric('2.23'),2412345).GetAsString);
234 +  writeln(Outfile,'Subtract 2.23 - 24.12345 = ',NumericSubtract(StrToNumeric('2.23'),StrToNumeric('24.12345')).GetAsString);
235 +  writeln(Outfile,'Subtract Double 24.12645 - 2.23 = ',NumericSubtract(StrToNumeric('24.12645'),2.23).GetAsString);
236 +  writeln(Outfile,'Subtract integer 24123.45 - 223 = ',NumericSubtract(StrToNumeric('24123.45'),223).GetAsString);
237 +  writeln(Outfile,'Multiply 2.23 * 24.12345 = ',NumericMultiply(StrToNumeric('2.23'),StrToNumeric('24.12345')).GetAsString);
238 +  writeln(Outfile,'Multiply Double 24.12645 * 2.23 = ',NumericMultiply(StrToNumeric('24.12645'),2.23).GetAsString);
239 +  writeln(Outfile,'Multiply integer 241.2345 * 223 = ',NumericMultiply(StrToNumeric('241.2345'),223).GetAsString);
240 +  writeln(Outfile,'Divide 24.12345 / 2.23 = ',NumericDivide(StrToNumeric('24.12345'),StrToNumeric('2.23')).GetAsString);
241 +  writeln(Outfile,'Divide Double 2.23 / 24.12645 = ',NumericDivide(StrToNumeric('2.23'),24.12645).GetAsString);
242 +  writeln(Outfile,'Divide integer 241.2345 / 223 = ',NumericDivide(StrToNumeric('241.2345'),223).GetAsString);
243 +  writeln(Outfile,'Compare 2.23, -24.12345 = ',NumericCompare(StrToNumeric('2.23'),DoubleToNumeric(-24.12645)));
244 +  writeln(Outfile,'Compare integer 2.23, 3 = ',NumericCompare(StrToNumeric('2.23'),3));
245 +  writeln(Outfile,'Compare Double 2.23, 2.23 = ',NumericCompare(StrToNumeric('2.23'),2.23));
246 +  writeln(Outfile,'Negate 24.12345 = ',NegateNumeric(StrToNumeric('24.12345')).GetAsString);
247 + end;
248 +
249   function TTest21.TestTitle: AnsiString;
250   begin
251    Result := 'Test 21: Exercise setting and getting of numeric data types';
# Line 171 | Line 263 | begin
263    Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB);
264    try
265      Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateTable);
266 +    ValidateStrToNumeric;
267 +    ValidateNumericInterface;
268      SetFloatTemplate('#,###.00000000');
269      UpdateDatabase(Attachment);
270      QueryDatabase(Attachment);

Comparing ibx/trunk/fbintf/testsuite/Test21.pas (property svn:eol-style):
Revision 353 by tony, Sat Oct 23 14:11:37 2021 UTC vs.
Revision 402 by tony, Mon Aug 1 10:07:24 2022 UTC

# Line 0 | Line 1
1 + native

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines