Files
MycLib/Test/TestDataPOD.pas
2025-12-11 14:22:09 +01:00

62 lines
1.8 KiB
ObjectPascal

unit TestDataPOD;
interface
uses
System.SysUtils,
Myc.Data.Scalar,
Myc.Data.Decimal,
Myc.Data.Series,
DUnitX.TestFramework;
type
[TestFixture]
TTestPOD = class
public
// Tests the TScalar factory methods using a wide range of values.
[TestCase('Ordinal_Zero', '0,Ordinal')]
[TestCase('Ordinal_Positive', '9876543210,Ordinal')]
[TestCase('Ordinal_Negative', '-1234567890,Ordinal')]
[TestCase('Ordinal_Max', '9223372036854775807,Ordinal')]
[TestCase('Float_Zero', '0.0,Float')]
[TestCase('Float_Positive', '1.23,Float')]
[TestCase('Float_Negative', '-3.1415926535,Float')]
procedure TestScalarCreation(const AValueStr: string; AExpectedKind: TScalar.TKind);
end;
implementation
uses
System.Variants;
{ TTestPOD }
procedure TTestPOD.TestScalarCreation(const AValueStr: string; AExpectedKind: TScalar.TKind);
var
scalar: TScalar;
begin
case AExpectedKind of
TScalar.TKind.Ordinal:
begin
scalar := TScalar.FromInt64(StrToInt64(AValueStr));
Assert.AreEqual(AExpectedKind, scalar.Kind, 'Kind should be Ordinal');
Assert.AreEqual(StrToInt64(AValueStr), scalar.Value.AsInt64, 'Value mismatch for AsInt64');
end;
TScalar.TKind.Float:
begin
scalar := TScalar.FromDouble(StrToFloat(AValueStr));
Assert.AreEqual(AExpectedKind, scalar.Kind, 'Kind should be Float');
Assert.AreEqual(StrToFloat(AValueStr), scalar.Value.AsDouble, 1E-12, 'Value mismatch for AsDouble');
end;
else
Assert.Fail('Unhandled TScalar.TKind in test');
end;
end;
initialization
FormatSettings.DecimalSeparator := '.';
TDUnitX.RegisterTestFixture(TTestPOD);
end.