more tests in fcl-stl

git-svn-id: trunk@17315 -
This commit is contained in:
vladob 2011-04-13 10:14:24 +00:00
parent 16b2db1b8f
commit 9781c0d051
5 changed files with 104 additions and 11 deletions

1
.gitattributes vendored
View File

@ -2329,6 +2329,7 @@ packages/fcl-stl/src/gutil.pp svneol=native#text/plain
packages/fcl-stl/src/gvector.pp svneol=native#text/plain
packages/fcl-stl/tests/clean svneol=native#text/plain
packages/fcl-stl/tests/garrayutilstest.pp svneol=native#text/plain
packages/fcl-stl/tests/gcompositetest.pp svneol=native#text/plain
packages/fcl-stl/tests/gdequetest.pp svneol=native#text/plain
packages/fcl-stl/tests/ghashmaptest.pp svneol=native#text/plain
packages/fcl-stl/tests/ghashsettest.pp svneol=native#text/plain

View File

@ -28,7 +28,7 @@ type
var
FData:TContainer;
procedure PushUp(position:SizeUInt);
procedure PushUp();
function Left(a:SizeUInt):SizeUInt;inline;
function Right(a:SizeUInt):SizeUInt;inline;
procedure Heapify(position:SizeUInt);
@ -79,9 +79,10 @@ begin
end;
end;
procedure TPriorityQueue.PushUp(position:SizeUInt);
var np:SizeUInt; temp:T;
procedure TPriorityQueue.PushUp();
var position,np:SizeUInt; temp:T;
begin
position:=FData.Size-1;
while(position>0) do
begin
np := Parent(position);
@ -99,7 +100,7 @@ end;
procedure TPriorityQueue.Push(value:T);inline;
begin
FData.PushBack(value);
PushUp(FData.Size-1);
PushUp();
end;
function TPriorityQueue.Left(a:SizeUInt):SizeUInt;inline;

View File

@ -0,0 +1,90 @@
{$mode objfpc}
unit gcompositetest;
interface
uses fpcunit, testregistry, gvector, gset;
type vectorlli=specialize TVector<longint>;
matrix = specialize TVector<vectorlli>;
vectorcmp = class
class function c(a,b:vectorlli):boolean;
end;
setvectorlli = specialize TSet<vectorlli, vectorcmp>;
type TGCompositeTest = class(TTestCase)
Published
procedure MatrixTest;
procedure SetVectorTest;
public
procedure Setup;override;
private
data:matrix;
end;
implementation
class function vectorcmp.c(a,b:vectorlli):boolean;
var i:SizeUInt;
begin
if (a.size < b.size) then exit(true);
if (a.size > b.size) then exit(false);
i:=0;
while i < a.size do begin
if (a[i] < b[i]) then exit(true);
inc(i);
end;
exit(false);
end;
procedure TGCompositeTest.SetVectorTest;
var sv:setvectorlli;
v:vectorlli;
begin
sv:=setvectorlli.create;
v:=vectorlli.create;
v.pushback(5);
v.pushback(7);
sv.insert(v);
if sv.find(v) = nil then
Fail('stuff not found');
v:=vectorlli.create;
v.pushback(5);
v.pushback(7);
if sv.find(v) = nil then
Fail('equal stuff not found');
v.pushback(9);
if sv.find(v) <> nil then
Fail('not equal stuff found');
end;
procedure TGCompositeTest.MatrixTest;
var i,j:longint;
begin
data.resize(1000);
for i:=0 to 999 do begin
data[i] := vectorlli.create;
data[i].resize(1000);
data[i][0] := 1;
data[0][i] := 1;
end;
for i:=1 to 999 do begin
for j:=1 to 999 do begin
data[i][j] := (data[i-1][j]+data[i][j-1]) mod 1000000009;
end;
end;
AssertEquals('bad val 5 1', 6, data[5][1]);
AssertEquals('bad val 5 2', 21, data[5][2]);
AssertEquals('bad val 5 5', 252, data[5][5]);
AssertEquals('bad val 50 50', 933591892, data[50][50]);
end;
procedure TGCompositeTest.Setup;
begin
data:=matrix.create;
end;
initialization
RegisterTest(TGCompositeTest);
end.

View File

@ -6,8 +6,8 @@ interface
uses fpcunit, testregistry, gpriorityqueue, gutil;
{type lesslli=specialize TLess<longint>;
queuelli=specialize TPriorityQueue<longint,lesslli>;}
type lesslli=specialize TLess<longint>;
queuelli=specialize TPriorityQueue<longint,lesslli>;
type TGPQueueTest = class(TTestCase)
Published
@ -15,7 +15,7 @@ type TGPQueueTest = class(TTestCase)
public
procedure Setup;override;
private
{ data:queuelli;}
data:queuelli;
end;
implementation
@ -23,7 +23,7 @@ implementation
procedure TGPQueueTest.QueueTest;
var i,last:longint;
begin
{ AssertEquals('Not IsEmpty', true, data.IsEmpty);
AssertEquals('Not IsEmpty', true, data.IsEmpty);
for i:=0 to 10 do
data.push(random(10000));
last:=data.top;
@ -34,12 +34,12 @@ begin
last:=data.top;
data.pop;
end;
AssertEquals('Not IsEmpty', true, data.IsEmpty);}
AssertEquals('Not IsEmpty', true, data.IsEmpty);
end;
procedure TGPQueueTest.Setup;
begin
{ data:=queuelli.create;}
data:=queuelli.create;
end;
initialization

View File

@ -20,7 +20,8 @@ interface
uses
gvectortest, gstacktest, gqueuetest, gdequetest, garrayutilstest,
gsettest, gmaptest, ghashsettest, ghashmaptest;
gsettest, gmaptest, ghashsettest, ghashmaptest, gpriorityqueuetest,
gcompositetest;
implementation