mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 13:39:11 +02:00
TAChart: Test THistory class
git-svn-id: trunk@38654 -
This commit is contained in:
parent
fcf539ce79
commit
1a0c213794
@ -80,6 +80,12 @@ type
|
|||||||
procedure TestIsSet;
|
procedure TestIsSet;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
type
|
||||||
|
THistoryTest = class(TTestCase)
|
||||||
|
published
|
||||||
|
procedure TestHistory;
|
||||||
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -452,11 +458,57 @@ begin
|
|||||||
AssertEquals(PUB_INT_SET_EMPTY, FISet.AsString);
|
AssertEquals(PUB_INT_SET_EMPTY, FISet.AsString);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// Workaround: FPC 2.6 fails if this type is made local to TestHistory.
|
||||||
|
type
|
||||||
|
TCharHistory = specialize THistory<Char>;
|
||||||
|
|
||||||
|
{ THistoryTest }
|
||||||
|
|
||||||
|
procedure THistoryTest.TestHistory;
|
||||||
|
var
|
||||||
|
h: TCharHistory;
|
||||||
|
|
||||||
|
procedure Check(AMessage, AExpected: String);
|
||||||
|
var
|
||||||
|
actual: String = '';
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i := 0 to h.Count - 1 do
|
||||||
|
actual += h.Item[i];
|
||||||
|
AssertEquals(AMessage, AExpected, actual);
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
h := TCharHistory.Create;
|
||||||
|
try
|
||||||
|
AssertEquals('Initial capacity', 0, h.Capacity);
|
||||||
|
Check('Initial state', '');
|
||||||
|
h.Add('a');
|
||||||
|
Check('Zero capacity', '');
|
||||||
|
h.Capacity := 3;
|
||||||
|
h.Add('a');
|
||||||
|
h.Add('b');
|
||||||
|
Check('Normal', 'ab');
|
||||||
|
h.Add('c');
|
||||||
|
h.Add('d');
|
||||||
|
Check('Overflow', 'bcd');
|
||||||
|
h.Capacity := 2;
|
||||||
|
Check('Reduce capacity 1', 'cd');
|
||||||
|
h.Add('e');
|
||||||
|
Check('Reduce capacity 2', 'de');
|
||||||
|
AssertEquals('Item[-1]', 'e', h[-1]);
|
||||||
|
AssertEquals('Pop', 'e', h.Pop);
|
||||||
|
Check('After pop', 'd');
|
||||||
|
finally
|
||||||
|
FreeAndNil(h);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
|
|
||||||
RegisterTests([
|
RegisterTests([
|
||||||
TIntervalListTest, TMathTest, TGeometryTest, TColorTest, TRTTITest,
|
TIntervalListTest, TMathTest, TGeometryTest, TColorTest, TRTTITest,
|
||||||
TPublishedIntegerSetTest]);
|
TPublishedIntegerSetTest, THistoryTest]);
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user