added a new test example, it's CollectionTest

This commit is contained in:
hyzboy 2021-03-22 17:45:35 +08:00
parent ffc31f161f
commit af53db0a64

View File

@ -1,22 +1,17 @@
#include<hgl/type/Collection.h>
//#include<hgl/type/List.h>
#include<iostream>
using namespace hgl;
using namespace std;
template<typename T> class NewList:public Collection<T>
void out(const Collection<uint32> &c)
{
for(const uint32 &value:c)
std::cout<<value<<" ";
public:
NewList(MemoryBlock *amb=new MemoryBlock(new MemoryAllocator)):Collection(amb)
{
}
virtual ~NewList()=default;
};//
std::cout<<std::endl;
}
void main(int,char **)
{
@ -29,10 +24,41 @@ void main(int,char **)
}
{
cout<<"Collection"<<endl<<endl;
Collection<uint32> cu;
NewList<uint32> ulist;
for(uint i=0;i<20;i++)
{
cu.Add(i/2);out(cu);
}
ulist.Add(1);
cu.Insert(0,0);out(cu);
std::cout<<"indexOf(5) is "<<cu.indexOf(5)<<std::endl;
cu.RemoveAt(1);out(cu);
std::cout<<"remove all 0"<<std::endl;
cu.Remove(0);out(cu);
cu.RemoveAt(2,3);out(cu);
cu.RemoveAt(3,2);out(cu);
cu.RemoveAt(3,2);out(cu);
Collection<uint32> del_cu;
del_cu.Add(2);
del_cu.Add(3);
std::cout<<"remove all 2 and 3"<<std::endl;
cu.Remove(del_cu);out(cu);
std::cout<<"exchanged two elements, they at 0 and 2"<<std::endl;
cu.Exchange(0,2);out(cu);
}
{
//List<uint32> ul;
//ul.Add(1024);
}
}