Files
MycLib/Test/TestDataPOD.pas
T
Michael Schimmel 3ed5a4011f DataFeed Refactoring
2025-12-10 22:30:53 +01:00

83 lines
2.7 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);
[Test]
procedure TestScalarTuple;
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;
procedure TTestPOD.TestScalarTuple;
var
tuple: TScalarTuple;
begin
// A tuple is a heterogeneous array of TScalar
SetLength(tuple, 3);
tuple[0] := TScalar.FromInt64(123);
tuple[1] := TScalar.FromDouble(3.14);
tuple[2] := TScalar.FromInt64(-456);
Assert.AreEqual(Int64(3), Length(tuple), 'Tuple length mismatch');
Assert.AreEqual(TScalar.TKind.Ordinal, tuple[0].Kind, 'Tuple item 0 kind mismatch');
Assert.AreEqual(Int64(123), tuple[0].Value.AsInt64, 'Tuple item 0 value mismatch');
Assert.AreEqual(TScalar.TKind.Float, tuple[1].Kind, 'Tuple item 1 kind mismatch');
Assert.AreEqual(3.14, tuple[1].Value.AsDouble, 1E-12, 'Tuple item 1 value mismatch');
Assert.AreEqual(TScalar.TKind.Ordinal, tuple[2].Kind, 'Tuple item 2 kind mismatch');
Assert.AreEqual(Int64(-456), tuple[2].Value.AsInt64, 'Tuple item 2 value mismatch');
end;
initialization
FormatSettings.DecimalSeparator := '.';
TDUnitX.RegisterTestFixture(TTestPOD);
end.