📄 testvector.pas
字号:
tmpVector.PushBack(Point(1,1));
tmpVector.Insert(tmpVector.ItBegin,FVector.ItBegin,FVector.ItEnd);
CheckEquals(FVector.Size,49);
CheckEquals(FVector.IndexOf(Point(3,3)),1);
CheckEquals(tmpVector.IndexOf(Point(1,1)),50-1);
Check(FVector.Items[2].x=(4));
FVector.Items[3]:=Point(17,17);
Check(FVector.Items[3].y=(17));
Check(not FVector.IsEquals(tmpVector));
FVector.Clear();
FVector.PushBack(tmpVector.ItBegin,tmpVector.ItEnd);
Check(FVector.IsEquals(tmpVector));
FVector.Clear();
for i:=0 to 50-1 do
FVector.PushBack(Point(i,i));
FVector.Items[4]:=Point(17,17);
CheckEquals(FVector.EraseValue(Point(17,17)),2);
CheckEquals(FVector.Size,48);
Check(FVector.Back.x=Point(49,49).x);
FVector.PopBack();
Check(FVector.Back.y=Point(48,48).y);
//
FVector.PushFront(Point(21,21));
Check(FVector.Front.y=(21));
FVector.PushFront(Point(13,13));
Check(FVector.Front.y=(13));
Check(FVector.Items[1].x=(21));
FVector.PopFront();
Check(FVector.Front.y=(21));
FVector.Assign(10,Point(5,5));
CheckEquals(FVector.size,10);
Check(FVector.Items[3].y=(5));
tmpVector.Assign(FVector.ItBegin,FVector.ItEnd);
CheckEquals(tmpVector.size,10);
Check(tmpVector.Items[3].x=(5));
CheckEquals(FVector.size,10);
FVector.Reserve(1000);
CheckEquals(FVector.size,10);
FVector.Resize(7);
CheckEquals(FVector.size,7);
FVector.Erase(FVector.ItBegin,FVector.ItEnd);
CheckEquals(FVector.size,0);
for i:=0 to 15-1 do
FVector.Insert(FVector.ItEnd,Point(i,i));
It0:=FVector.ItBegin;
It0.Next(5);
it1:=FVector.ItEnd;
It1.Next(-5);
FVector.Erase(It0,it1);
CheckEquals(FVector.size,10);
Check(FVector.Items[6].y=(11));
FVector.Erase(It0);
CheckEquals(FVector.size,9);
Check(FVector.Items[6].x=(12));
It0:=FVector.ItBegin.Clone(5);
FVector.Insert(It0,Point(31,31));
CheckEquals(FVector.size,10);
Check(FVector.Items[5].y=(31));
Check(FVector.Items[6].x=(11));
It0:=FVector.ItBegin.Clone(5);
FVector.Insert(It0,Point(32,32));
CheckEquals(FVector.size,11);
Check(FVector.Items[5].x=(32));
Check(FVector.Items[6].y=(31));
//
FVector.Clear();
FVector.PushFront(3,Point(12,12));
CheckEquals(FVector.size,3);
Check(FVector.Items[2].y=(12));
FVector.PushFront(5,Point(11,11));
CheckEquals(FVector.size,8);
Check(FVector.Items[0].x=(11));
Check(FVector.Items[4].x=(11));
Check(FVector.Items[5].y=(12));
Check(FVector.Items[7].x=(12));
//}
end;
procedure TTest_Vector.testStrIterator;
var
FVector : IStrVector;
i : integer;
It : IstrIterator;
tmpIt : IStrIterator;
begin
FVector :=TStrVector.Create(10,'3');
CheckEquals(FVector.size,10);
CheckEquals(FVector.items[5],'3');
FVector.Clear();
for i:=0 to 50-1 do
FVector.PushBack(inttostr(i));
It:=FVector.ItBegin;
It.Next();
CheckEquals(It.Value,'1');
It.Next(4);
CheckEquals((It.Value),'5');
CheckEquals(FVector.ItBegin.Distance(It),(5));
It:=FVector.ItEnd;
It.Previous();
CheckEquals((It.Value),'49');
It.Next(-2);
CheckEquals((It.Value),'47');
tmpIt:=It.Clone();
CheckEquals((tmpIt.Value),(It.Value));
Check(tmpIt.IsEqual(It));
tmpIt.Value:=inttostr(strtoint(It.Value)+1);
CheckEquals((tmpIt.Value),(It.Value));
tmpIt.Previous;
CheckNotEquals((tmpIt.Value),(It.Value));
it.Assign(tmpIt);
CheckEquals((tmpIt.Value),(It.Value));
tmpIt.Previous;
CheckNotEquals((tmpIt.Value),(It.Value));
end;
procedure TTest_Vector.testStrVector;
var
FVector : IStrVector;
tmpVector : IStrVector;
i : integer;
It0,It1 : IStrIterator;
begin
FVector :=TStrVector.Create();
Check(FVector.IsEmpty());
FVector.Insert(Fvector.ItBegin,'5');
CheckEquals(FVector.Size,1);
Check(FVector.Back='5');
Check(FVector.ItBegin.Value='5');
FVector.Clear();
Check(FVector.IsEmpty);
tmpVector:=IStrVector(FVector.Clone());
tmpVector.PushBack('13');
Check(FVector.IsEmpty);
Check(tmpVector.ItBegin.Value='13');
FVector.PushBack('31');
tmpVector:=TStrVector.Create(FVector.ItBegin,FVector.ItEnd);
Check(tmpVector.Back='31');
FVector.Clear();
for i:=2 to 50 do
FVector.PushBack(inttostr(i));
tmpVector.Clear();
tmpVector.PushBack('1');
tmpVector.Insert(tmpVector.ItBegin,FVector.ItBegin,FVector.ItEnd);
CheckEquals(FVector.Size,49);
CheckEquals(FVector.IndexOf('3'),1);
CheckEquals(tmpVector.IndexOf('1'),50-1);
Check(FVector.Items[2]='4');
FVector.Items[3]:='17';
Check(FVector.Items[3]='17');
Check(not FVector.IsEquals(tmpVector));
FVector.Clear();
FVector.PushBack(tmpVector.ItBegin,tmpVector.ItEnd);
Check(FVector.IsEquals(tmpVector));
FVector.Clear();
for i:=0 to 50-1 do
FVector.PushBack(inttostr(i));
FVector.Items[4]:='17';
CheckEquals(FVector.EraseValue('17'),2);
CheckEquals(FVector.Size,48);
Check(FVector.Back='49');
FVector.PopBack();
Check(FVector.Back='48');
//
FVector.PushFront('21');
Check(FVector.Front='21');
FVector.PushFront('13');
Check(FVector.Front='13');
Check(FVector.Items[1]='21');
FVector.PopFront();
Check(FVector.Front='21');
FVector.Assign(10,'5');
CheckEquals(FVector.size,10);
Check(FVector.Items[3]='5');
tmpVector.Assign(FVector.ItBegin,FVector.ItEnd);
CheckEquals(tmpVector.size,10);
Check(tmpVector.Items[3]='5');
CheckEquals(FVector.size,10);
FVector.Reserve(1000);
CheckEquals(FVector.size,10);
FVector.Resize(7);
CheckEquals(FVector.size,7);
FVector.Erase(FVector.ItBegin,FVector.ItEnd);
CheckEquals(FVector.size,0);
for i:=0 to 15-1 do
FVector.Insert(FVector.ItEnd,inttostr(i));
It0:=FVector.ItBegin;
It0.Next(5);
it1:=FVector.ItEnd;
It1.Next(-5);
FVector.Erase(It0,it1);
CheckEquals(FVector.size,10);
Check(FVector.Items[6]='11');
It0:=FVector.ItBegin.Clone(5);
FVector.Erase(It0);
CheckEquals(FVector.size,9);
Check(FVector.Items[6]='12');
It0:=FVector.ItBegin.Clone(5);
FVector.Insert(It0,'31');
CheckEquals(FVector.size,10);
Check(FVector.Items[5]='31');
Check(FVector.Items[6]='11');
It0:=FVector.ItBegin.Clone(5);
FVector.Insert(It0,'32');
CheckEquals(FVector.size,11);
Check(FVector.Items[5]='32');
Check(FVector.Items[6]='31');
//
FVector.Clear();
FVector.PushFront(3,'12');
CheckEquals(FVector.size,3);
Check(FVector.Items[2]='12');
FVector.PushFront(5,'11');
CheckEquals(FVector.size,8);
Check(FVector.Items[0]='11');
Check(FVector.Items[4]='11');
Check(FVector.Items[5]='12');
Check(FVector.Items[7]='12');
end;
procedure TTest_Vector.testVector;
var
FVector : IPointerVector;
tmpVector : IPointerVector;
i : integer;
It0,It1:IPointerIterator;
begin
FVector :=TPointerVector.Create();
Check(FVector.IsEmpty());
FVector.Insert(FVector.ItBegin,pointer(5));
CheckEquals(FVector.Size,1);
Check(FVector.Back=pointer(5));
Check(FVector.ItBegin.Value=pointer(5));
FVector.Clear();
Check(FVector.IsEmpty);
tmpVector:=IPointerVector(FVector.Clone());
tmpVector.PushBack(Pointer(13));
Check(FVector.IsEmpty);
Check(tmpVector.ItBegin.Value=Pointer(13));
FVector.PushBack(Pointer(31));
tmpVector:=TPointerVector.Create(FVector.ItBegin,FVector.ItEnd);
Check(tmpVector.Back=Pointer(31));
FVector.Clear();
for i:=2 to 50 do
FVector.PushBack(Pointer(i));
tmpVector.Clear();
tmpVector.PushBack(Pointer(1));
tmpVector.Insert(tmpVector.ItBegin,FVector.ItBegin,FVector.ItEnd);
CheckEquals(FVector.Size,49);
CheckEquals(FVector.IndexOf(Pointer(3)),1);
CheckEquals(tmpVector.IndexOf(Pointer(1)),50-1);
Check(FVector.Items[2]=Pointer(4));
FVector.Items[3]:=Pointer(17);
Check(FVector.Items[3]=Pointer(17));
Check(not FVector.IsEquals(tmpVector));
FVector.Clear();
FVector.PushBack(tmpVector.ItBegin,tmpVector.ItEnd);
Check(FVector.IsEquals(tmpVector));
FVector.Clear();
for i:=0 to 50-1 do
FVector.PushBack(Pointer(i));
FVector.Items[4]:=Pointer(17);
CheckEquals(FVector.EraseValue(Pointer(17)),2);
CheckEquals(FVector.Size,48);
Check(FVector.Back=Pointer(49));
FVector.PopBack();
Check(FVector.Back=Pointer(48));
//
FVector.PushFront(Pointer(21));
Check(FVector.Front=Pointer(21));
FVector.PushFront(Pointer(13));
Check(FVector.Front=Pointer(13));
Check(FVector.Items[1]=Pointer(21));
FVector.PopFront();
Check(FVector.Front=Pointer(21));
FVector.Assign(10,Pointer(5));
CheckEquals(FVector.size,10);
Check(FVector.Items[3]=Pointer(5));
tmpVector.Assign(FVector.ItBegin,FVector.ItEnd);
CheckEquals(tmpVector.size,10);
Check(tmpVector.Items[3]=Pointer(5));
CheckEquals(FVector.size,10);
FVector.Reserve(1000);
CheckEquals(FVector.size,10);
FVector.Resize(7);
CheckEquals(FVector.size,7);
FVector.Erase(FVector.ItBegin,FVector.ItEnd);
CheckEquals(FVector.size,0);
for i:=0 to 15-1 do
FVector.Insert(FVector.ItEnd,Pointer(i));
It0:=FVector.ItBegin.Clone(5);
it1:=FVector.ItEnd;
It1.Next(-5);
FVector.Erase(It0,it1);
CheckEquals(FVector.size,10);
Check(FVector.Items[6]=Pointer(11));
FVector.Erase(It0);
CheckEquals(FVector.size,9);
Check(FVector.Items[6]=Pointer(12));
It0:=FVector.ItBegin.Clone(5);
FVector.Insert(It0,Pointer(31));
CheckEquals(FVector.size,10);
Check(FVector.Items[5]=Pointer(31));
Check(FVector.Items[6]=Pointer(11));
It0:=FVector.ItBegin.Clone(5);
FVector.Insert(It0,Pointer(32));
CheckEquals(FVector.size,11);
Check(FVector.Items[5]=Pointer(32));
Check(FVector.Items[6]=Pointer(31));
//
FVector.Clear();
FVector.PushFront(3,Pointer(12));
CheckEquals(FVector.size,3);
Check(FVector.Items[2]=Pointer(12));
FVector.PushFront(5,Pointer(11));
CheckEquals(FVector.size,8);
Check(FVector.Items[0]=Pointer(11));
Check(FVector.Items[4]=Pointer(11));
Check(FVector.Items[5]=Pointer(12));
Check(FVector.Items[7]=Pointer(12));
end;
initialization
RegisterTest(TTest_Vector.Suite);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -