mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 13:50:06 +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;
|
const AExpected, AActual: array of Double; ADelta: Double = 0.0); overload;
|
||||||
class procedure AssertEquals(
|
class procedure AssertEquals(
|
||||||
const AExpected, AActual: array of Double; ADelta: Double = 0.0); overload;
|
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;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -22,13 +26,23 @@ implementation
|
|||||||
uses
|
uses
|
||||||
SysUtils;
|
SysUtils;
|
||||||
|
|
||||||
function DoubleArrayToStr(const AData: array of Double): String;
|
function BooleanArrayEqual(const AA, AB: array of Boolean): Boolean;
|
||||||
var
|
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
|
begin
|
||||||
Result := '';
|
Result := '';
|
||||||
for a in AData do
|
for b in AData do
|
||||||
Result += Format('%g,', [a]);
|
Result += BoolToStr(b, 'true,', 'false,');
|
||||||
Delete(Result, Length(Result), 1);
|
Delete(Result, Length(Result), 1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -42,14 +56,41 @@ begin
|
|||||||
Result := true;
|
Result := true;
|
||||||
end;
|
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 }
|
{ TAssertHelper }
|
||||||
|
|
||||||
|
class procedure TAssertHelper.AssertEquals(
|
||||||
|
const AExpected, AActual: array of Boolean);
|
||||||
|
begin
|
||||||
|
AssertEquals('', AExpected, AActual);
|
||||||
|
end;
|
||||||
|
|
||||||
class procedure TAssertHelper.AssertEquals(
|
class procedure TAssertHelper.AssertEquals(
|
||||||
const AExpected, AActual: array of Double; ADelta: Double);
|
const AExpected, AActual: array of Double; ADelta: Double);
|
||||||
begin
|
begin
|
||||||
AssertEquals('', AExpected, AActual, ADelta);
|
AssertEquals('', AExpected, AActual, ADelta);
|
||||||
end;
|
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(
|
class procedure TAssertHelper.AssertEquals(
|
||||||
const AMessage: String; const AExpected, AActual: array of Double;
|
const AMessage: String; const AExpected, AActual: array of Double;
|
||||||
ADelta: Double);
|
ADelta: Double);
|
||||||
@ -59,8 +100,12 @@ begin
|
|||||||
if DoubleArrayEqual(AExpected, AActual, ADelta) then exit;
|
if DoubleArrayEqual(AExpected, AActual, ADelta) then exit;
|
||||||
expectedStr := DoubleArrayToStr(AExpected);
|
expectedStr := DoubleArrayToStr(AExpected);
|
||||||
actualStr := DoubleArrayToStr(AActual);
|
actualStr := DoubleArrayToStr(AActual);
|
||||||
Fail(AMessage + Format(SCompare, [expectedStr, actualStr]));
|
Fail(AMessage + ComparisonMsg(expectedStr, actualStr));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
initialization
|
||||||
|
Random; // Workaround for issue #21808.
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ type
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Math, TAGeometry, TAMath;
|
Math, TAGeometry, TAMath, AssertHelpers;
|
||||||
|
|
||||||
{ TIntervalListTest }
|
{ TIntervalListTest }
|
||||||
|
|
||||||
@ -407,30 +407,9 @@ end;
|
|||||||
|
|
||||||
procedure TPublishedIntegerSetTest.TestAsBooleans;
|
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);
|
procedure AssertBooleans(const AExpected: array of Boolean; ACount: Integer);
|
||||||
var
|
|
||||||
actual: array of Boolean;
|
|
||||||
len: Integer;
|
|
||||||
begin
|
begin
|
||||||
actual := FISet.AsBooleans(ACount);
|
AssertEquals(AExpected, 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)));
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user