TAChart: Add IsEquivalent utility function

git-svn-id: trunk@38811 -
This commit is contained in:
ask 2012-09-24 14:37:53 +00:00
parent 685097901a
commit 4b2fe13853
2 changed files with 17 additions and 0 deletions

View File

@ -293,6 +293,7 @@ function FormatIfNotEmpty(AFormat, AStr: String): String; inline;
function IfThen(ACond: Boolean; ATrue, AFalse: TObject): TObject; overload;
function InterpolateRGB(AColor1, AColor2: Integer; ACoeff: Double): Integer;
function IntToColorHex(AColor: Integer): String; inline;
function IsEquivalent(const A1, A2: Double): Boolean; inline;
function IsNan(const APoint: TDoublePoint): Boolean; overload; inline;
function NumberOr(ANum: Double; ADefault: Double = 0.0): Double; inline;
@ -424,6 +425,11 @@ begin
Result := '$' + IntToHex(AColor, 6);
end;
function IsEquivalent(const A1, A2: Double): Boolean;
begin
Result := CompareDWord(A1, A2, SizeOf(A1) div SizeOf(DWord)) = 0;
end;
function IsNan(const APoint: TDoublePoint): Boolean;
begin
Result := IsNan(APoint.X) or IsNan(APoint.Y);

View File

@ -40,6 +40,7 @@ type
TMathTest = class(TTestCase)
published
procedure CumulNurmDistrTest;
procedure TestIsEquivalent;
end;
TGeometryTest = class(TTestCase)
@ -172,6 +173,16 @@ begin
AssertEquals(p, InvCumulNormDistr(CumulNormDistr(p)));
end;
procedure TMathTest.TestIsEquivalent;
begin
AssertTrue(IsEquivalent(1.2345, 1.2345));
AssertTrue(IsEquivalent(SafeNaN, SafeNaN));
AssertTrue(IsEquivalent(1e100, 1e100+1));
AssertFalse(IsEquivalent(1e10, 1e10+1));
AssertFalse(IsEquivalent(5, SafeNaN));
AssertFalse(IsEquivalent(SafeNaN, 5));
end;
{ TGeometryTest }
procedure TGeometryTest.AssertEquals(const Expected, Actual: TDoublePoint);