updated CollectionTest.cpp, use not template class Collection

This commit is contained in:
hyzboy 2021-05-07 19:03:28 +08:00
parent 2d6d76ab6d
commit 99ad89ddb5

View File

@ -5,58 +5,65 @@
using namespace hgl;
using namespace std;
using TEST_TYPE =uint32;
using TEST_TYPE =char;
using MyEnumerator=ElementEnumerator<TEST_TYPE>;
using MyOperator =ElementOperatorRawtype<TEST_TYPE>;
using MyCheck =CheckElementEqual<TEST_TYPE>;
constexpr size_t UNIT_BYTES =sizeof(TEST_TYPE);
void out(const Collection &c)
{
MyEnumerator me(&c);
for(const TEST_TYPE &value:me)
std::cout<<value<<" ";
const TEST_TYPE *str=me.begin();
const size_t count=me.size();
for(size_t i=0;i<count;i++)
{
std::cout<<*str<<' ';
++str;
}
// for(const TEST_TYPE &value:me)
// std::cout<<value<<" ";
std::cout<<std::endl;
}
void main(int,char **)
{
MyOperator my_operator;
MemoryAllocator *ma=new MemoryAllocator;
{
Collection cu(UNIT_BYTES);
ma->Alloc(1024*UNIT_BYTES);
MemoryBlock *mb=new MemoryBlock(ma);
{
Collection cu(UNIT_BYTES,mb,&my_operator);
for(uint i=0;i<20;i++)
for(TEST_TYPE i=0;i<10;i++)
{
cu.Add(i/2);out(cu);
cu.AddValue<TEST_TYPE>('A'+i);
out(cu);
}
cu.Insert(0,0);out(cu);
std::cout<<"indexOf(5) is "<<cu.indexOf(5)<<std::endl;
std::cout<<"indexOf(E) is "<<cu.indexOf('E')<<std::endl;
std::cout<<"remove second data."<<std::endl;
cu.RemoveAt(1);out(cu);
std::cout<<"remove all 0"<<std::endl;
cu.Remove(0);out(cu);
std::cout<<"remove all 'A'"<<std::endl;
cu.Remove('A');out(cu);
std::cout<<"remove 3 data from third"<<std::endl;
cu.RemoveAt(2,3);out(cu);
cu.RemoveAt(3,2);out(cu);
cu.RemoveAt(3,2);out(cu);
Collection<uint32> del_cu;
{
Collection del_cu(UNIT_BYTES);
CheckElementEqual<TEST_TYPE> cee;
del_cu.Add(2);
del_cu.Add(3);
del_cu.AddValue<TEST_TYPE>('I');
del_cu.AddValue<TEST_TYPE>('F');
std::cout<<"remove all 2 and 3"<<std::endl;
cu.Remove(del_cu);out(cu);
std::cout<<"remove all 'I' and 'F'"<<std::endl;
cu.RemoveCollection(del_cu,&cee);out(cu);
}
std::cout<<"exchanged two elements, they at 0 and 2"<<std::endl;
cu.Exchange(0,2);out(cu);