void TestCase_ObjBase_Array::BasicTest() { std::cout <<"Basic test: " <<std::endl; std::cout <<"Insert 10 objects." <<std::endl; LLBC_Array *arr = new LLBC_Array; const LLBC_Array &constArr = *arr; for(int i = 0; i < 10; i ++) { LLBC_Object *obj = new TestObj; arr->Insert(arr->End(), obj); obj->Release(); } ForeachFun foreachFun; ConstForeachFun constForeachFun; std::cout <<"Done, output it: " <<std::endl; arr->Foreach(foreachFun); std::cout <<"Output it(using const foreach version method): " <<std::endl; constArr.Foreach(constForeachFun); std::cout <<"Using subscript to access array element." <<std::endl; for(int i = 0; i < 10; i ++) { std::cout <<(*arr)[i]->ToString() <<std::endl; } std::cout <<"Done" <<std::endl; std::cout <<"Using subscript to access array element(const array)." <<std::endl; for(int i = 0; i < 10; i ++) { std::cout <<constArr[i]->ToString() <<std::endl; } std::cout <<"Done" <<std::endl; std::cout <<"Fetch sub array in range[3, 5): " <<std::endl; LLBC_Array::IndexSet idxs; idxs.insert(3); idxs.insert(4); LLBC_Array *subArr = arr->ObjectsAtIndexs(idxs); std::cout <<"Done, output it: " <<std::endl; subArr->Foreach(foreachFun); delete arr; delete subArr; std::cout <<"Basic test done!" <<std::endl; }
void TestCase_ObjBase_Array::IterTest() { std::cout <<"Iter test: " <<std::endl; // PushBack/PushFront test. LLBC_Array arr; static const int insertCnt = 10; std::cout <<"PushBack/PushFront" <<insertCnt <<" objects into array." <<std::endl; for(int i = 1; i <= insertCnt; i ++) { LLBC_Object *obj = new TestObj; arr.PushBack(obj); obj->Release(); } std::cout <<"Done, array size: " <<arr.GetSize() <<", Capacity: " <<arr.GetCapacity() <<std::endl; // Iterator test. ForeachFun foreachFun; std::cout <<"Iteration, using LLBC_Array::Iter" <<std::endl; LLBC_Array::Iter it1 = arr.Begin(); for(; it1 != arr.End(); it1 ++) { LLBC_Object *obj = *it1; std::cout <<obj->ToString() <<std::endl; } std::cout <<"Done" <<std::endl; std::cout <<"Iteration, using LLBC_Array::ReverseIter" <<std::endl; LLBC_Array::ReverseIter it2 = arr.ReverseBegin(); for(; it2 != arr.ReverseEnd(); it2 ++) { std::cout <<(*it2)->ToString() <<std::endl; } std::cout <<"Done" <<std::endl; std::cout <<"Insert new object to front" <<std::endl; LLBC_Object *obj = new TestObj; arr.Insert(arr.Begin(), obj); obj->Release(); std::cout <<"Done, ouput it: " <<std::endl; arr.Foreach(foreachFun); std::cout <<"Insert new object before position 1: " <<std::endl; obj = new TestObj; arr.Insert(++ arr.Begin(), obj); obj->Release(); std::cout <<"Done, output it: " <<std::endl; arr.Foreach(foreachFun); std::cout <<"Erase position 1's object: " <<std::endl; arr.Erase(arr.Begin() + 1); std::cout <<"Done, output it: " <<std::endl; arr.Foreach(foreachFun); std::cout <<"Erase position 0's object: " <<std::endl; arr.Erase(0); std::cout <<"Done, output it: " <<std::endl; arr.Foreach(foreachFun); std::cout <<"Erase range[begin, end): " <<std::endl; arr.Erase( arr.Begin(), arr.End() ); std::cout <<"Done, output it: " <<std::endl; arr.Foreach(foreachFun); std::cout <<"Iter test done" <<std::endl; }