mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 03:35:57 +02:00
TAChart: Add and use AssertEquals overload for arrays of Boolean
git-svn-id: trunk@37585 -
This commit is contained in:
parent
3d09ebb4ca
commit
d44288d1e0
@ -15,6 +15,10 @@ type
|
||||
const AExpected, AActual: array of Double; ADelta: Double = 0.0); overload;
|
||||
class procedure AssertEquals(
|
||||
const AExpected, AActual: array of Double; ADelta: Double = 0.0); overload;
|
||||
class procedure AssertEquals(
|
||||
const AMessage: String; const AExpected, AActual: array of Boolean); overload;
|
||||
class procedure AssertEquals(
|
||||
const AExpected, AActual: array of Boolean); overload;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -22,13 +26,23 @@ implementation
|
||||
uses
|
||||
SysUtils;
|
||||
|
||||
function DoubleArrayToStr(const AData: array of Double): String;
|
||||
function BooleanArrayEqual(const AA, AB: array of Boolean): Boolean;
|
||||
var
|
||||
a: Double;
|
||||
len: Integer;
|
||||
begin
|
||||
len := Length(AA);
|
||||
if len <> Length(AB) then exit(false);
|
||||
if len = 0 then exit(true);
|
||||
Result := CompareByte(AA[0], AB[0], len) = 0;
|
||||
end;
|
||||
|
||||
function BooleanArrayToStr(const AData: array of Boolean): String;
|
||||
var
|
||||
b: Boolean;
|
||||
begin
|
||||
Result := '';
|
||||
for a in AData do
|
||||
Result += Format('%g,', [a]);
|
||||
for b in AData do
|
||||
Result += BoolToStr(b, 'true,', 'false,');
|
||||
Delete(Result, Length(Result), 1);
|
||||
end;
|
||||
|
||||
@ -42,14 +56,41 @@ begin
|
||||
Result := true;
|
||||
end;
|
||||
|
||||
function DoubleArrayToStr(const AData: array of Double): String;
|
||||
var
|
||||
a: Double;
|
||||
begin
|
||||
Result := '';
|
||||
for a in AData do
|
||||
Result += Format('%g,', [a]);
|
||||
Delete(Result, Length(Result), 1);
|
||||
end;
|
||||
|
||||
{ TAssertHelper }
|
||||
|
||||
class procedure TAssertHelper.AssertEquals(
|
||||
const AExpected, AActual: array of Boolean);
|
||||
begin
|
||||
AssertEquals('', AExpected, AActual);
|
||||
end;
|
||||
|
||||
class procedure TAssertHelper.AssertEquals(
|
||||
const AExpected, AActual: array of Double; ADelta: Double);
|
||||
begin
|
||||
AssertEquals('', AExpected, AActual, ADelta);
|
||||
end;
|
||||
|
||||
class procedure TAssertHelper.AssertEquals(
|
||||
const AMessage: String; const AExpected, AActual: array of Boolean);
|
||||
var
|
||||
expectedStr, actualStr: String;
|
||||
begin
|
||||
if BooleanArrayEqual(AExpected, AActual) then exit;
|
||||
expectedStr := BooleanArrayToStr(AExpected);
|
||||
actualStr := BooleanArrayToStr(AActual);
|
||||
Fail(AMessage + ComparisonMsg(expectedStr, actualStr));
|
||||
end;
|
||||
|
||||
class procedure TAssertHelper.AssertEquals(
|
||||
const AMessage: String; const AExpected, AActual: array of Double;
|
||||
ADelta: Double);
|
||||
@ -59,8 +100,12 @@ begin
|
||||
if DoubleArrayEqual(AExpected, AActual, ADelta) then exit;
|
||||
expectedStr := DoubleArrayToStr(AExpected);
|
||||
actualStr := DoubleArrayToStr(AActual);
|
||||
Fail(AMessage + Format(SCompare, [expectedStr, actualStr]));
|
||||
Fail(AMessage + ComparisonMsg(expectedStr, actualStr));
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
Random; // Workaround for issue #21808.
|
||||
|
||||
end.
|
||||
|
||||
|
@ -83,7 +83,7 @@ type
|
||||
implementation
|
||||
|
||||
uses
|
||||
Math, TAGeometry, TAMath;
|
||||
Math, TAGeometry, TAMath, AssertHelpers;
|
||||
|
||||
{ TIntervalListTest }
|
||||
|
||||
@ -407,30 +407,9 @@ end;
|
||||
|
||||
procedure TPublishedIntegerSetTest.TestAsBooleans;
|
||||
|
||||
function BooleansToStr(const A: array of Boolean): String;
|
||||
var
|
||||
b: Boolean;
|
||||
begin
|
||||
Result := '';
|
||||
for b in A do begin
|
||||
if Result <> '' then
|
||||
Result += ',';
|
||||
Result += BoolToStr(b, 'true', 'false');
|
||||
end;
|
||||
Result := '[' + Result + ']';
|
||||
end;
|
||||
|
||||
procedure AssertBooleans(const AExpected: array of Boolean; ACount: Integer);
|
||||
var
|
||||
actual: array of Boolean;
|
||||
len: Integer;
|
||||
begin
|
||||
actual := FISet.AsBooleans(ACount);
|
||||
len := Length(actual);
|
||||
AssertTrue(
|
||||
BooleansToStr(actual) + ' = ' + BooleansToStr(AExpected),
|
||||
(len = Length(AExpected)) and
|
||||
((len = 0) or (CompareByte(actual[0], AExpected[0], len) = 0)));
|
||||
AssertEquals(AExpected, FISet.AsBooleans(ACount));
|
||||
end;
|
||||
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user