template<typename Array> static void test_reserve(skiatest::Reporter* reporter) { // Test that our allocated space stays >= to the reserve count until the array is filled to // the reserve count for (int reserveCount : {1, 2, 10, 100}) { // Test setting reserve in constructor. Array array1(reserveCount); test_array_reserve(reporter, &array1, reserveCount); // Test setting reserve after constructor. Array array2; array2.reserve(reserveCount); test_array_reserve(reporter, &array2, reserveCount); // Test increasing reserve after constructor. Array array3(reserveCount/2); array3.reserve(reserveCount); test_array_reserve(reporter, &array3, reserveCount); // Test setting reserve on non-empty array. Array array4; array4.push_back_n(reserveCount); array4.reserve(reserveCount); array4.pop_back_n(reserveCount); test_array_reserve(reporter, &array4, 2 * reserveCount); } }
void profile_for_type(const T& elem, const std::string& type, const int add_flops, const int multiply_flops) { std::cout << "Profiling for array type " << type << "." << std::endl; unsigned int n = 100; pyQCD::LexicoLayout layout(std::vector<unsigned int>{n}); pyQCD::Lattice<T, Alloc> array1(layout, elem); decltype(array1) array2(layout, elem); decltype(array1) array3(layout, elem); decltype(array1) result(layout, elem); std::cout << "Profiling f(x, y, z) = x + y + z:" << std::endl; benchmark([&] () { result = array1 + array2 + array3; }, 2 * add_flops * n, 1000000); std::cout << "Profiling f(x, y) = 5.0 * x + y:" << std::endl; benchmark([&] () { result = 5.0 * array1 + array2; }, 2 * add_flops * n, 1000000); std::cout << "Profiling f(x, y, z) = x * y + z:" << std::endl; benchmark([&] () { result = array1 * array2 + array3; }, (add_flops + multiply_flops) * n, 1000000); std::cout << std::endl; }
void slavep(int msize){ int srows, i, j, k; MPI_Request reqs[1]; matrix<int> array2(w, w); MPI_Bcast(array2.arrptr(), w*w, MPI_INT, 0, MPI_COMM_WORLD); MPI_Irecv(&srows, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &reqs[0]); MPI_Wait(reqs, MPI_STATUSES_IGNORE); matrix<int> array1(w, w); matrix<int> array3(w, w); MPI_Irecv(array1.arrptr(), srows*w, MPI_INT, 0, 0, MPI_COMM_WORLD, &reqs[0]); MPI_Wait(reqs, MPI_STATUSES_IGNORE); for (i = 0; i < srows; i++) { for (j = 0; j < w; j++){ array3[i][j] = 0; for (k = 0; k < w; k++){ array3[i][j] += array1[i][k] * array2[k][j]; } } } MPI_Isend(array3.arrptr(), srows*w, MPI_INT, 0, 0, MPI_COMM_WORLD, &reqs[0]); MPI_Wait(&reqs[0], MPI_STATUSES_IGNORE); }
void UT_array_erase(const char* params) { Lumix::DefaultAllocator allocator; Lumix::Array<int> array1(allocator); for (int i = 0; i < 20; ++i) { array1.push(i * 5); } array1.eraseItem(25); LUMIX_EXPECT(array1.size() == 19); for (int i = 0; i < 18; ++i) { LUMIX_EXPECT(array1[i] < array1[i + 1]); } array1.erase(10); for (int i = 0; i < 17; ++i) { LUMIX_EXPECT(array1[i] < array1[i + 1]); } LUMIX_EXPECT(array1.size() == 18); array1.eraseFast(7); LUMIX_EXPECT(array1.size() == 17); array1.eraseItemFast(30); LUMIX_EXPECT(array1.size() == 16); array1.pop(); LUMIX_EXPECT(array1.size() == 15); }
void merge_sort(std::vector<T>& array) { if (1 < array.size()) { std::vector<T> array1(array.begin(), array.begin() + array.size() / 2); merge_sort(array1); std::vector<T> array2(array.begin() + array.size() / 2, array.end()); merge_sort(array2); merge(array, array1, array2); } }
TEST(ArrayTypeTest, MoveConstructor) { type::const_t_array<float> array1({1, 2, 3}); type::const_t_array<float> array2(std::move(array1)); auto read_array(type::read(array2)); EXPECT_EQ(1, read_array[0]); EXPECT_EQ(2, read_array[1]); EXPECT_EQ(3, read_array[2]); ASSERT_EQ(3, array2.size()); ASSERT_EQ(0, array1.size()); }
void computeTest(GLuint a_prog) { int N = 1024; std::vector<float> array1(N); std::vector<float> array2(N); for(int i=0;i<array1.size();i++) { array1[i] = float(i)/10.0f; array2[i] = 0.0f; } // create buffers // GLuint buf1; glGenBuffers(1, &buf1); glBindBuffer(GL_SHADER_STORAGE_BUFFER, buf1); CHECK_GL_ERRORS; glBufferData(GL_SHADER_STORAGE_BUFFER, array1.size()*sizeof(float), &array1[0], GL_STATIC_DRAW ); CHECK_GL_ERRORS; // copy data from CPU to GPU GLuint buf2; glGenBuffers(1, &buf2); glBindBuffer(GL_SHADER_STORAGE_BUFFER, buf2); CHECK_GL_ERRORS; glBufferData(GL_SHADER_STORAGE_BUFFER, array2.size()*sizeof(float), &array2[0], GL_STATIC_DRAW); CHECK_GL_ERRORS; // copy data from CPU to GPU //glBufferData(GL_SHADER_STORAGE_BUFFER, array2.size()*sizeof(float), NULL, GL_STATIC_DRAW ); CHECK_GL_ERRORS; // don't do that! Seems to be an OpenGL driver bug // launch threads // glUseProgram(a_prog); CHECK_GL_ERRORS; glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, buf1); CHECK_GL_ERRORS; glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, buf2); CHECK_GL_ERRORS; glDispatchCompute(array1.size()/256, 1, 1); CHECK_GL_ERRORS; // 256 is a worgroup size of g_programCompute.program glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); CHECK_GL_ERRORS; // seems not really needed but it will be better call this function before you read data // read back data // glBindBuffer(GL_SHADER_STORAGE_BUFFER, buf2); void* resultData = glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, array2.size()*sizeof(float), GL_MAP_READ_BIT); CHECK_GL_ERRORS; memcpy(&array2[0], resultData, array2.size()*sizeof(float)); glUnmapBuffer(GL_SHADER_STORAGE_BUFFER); CHECK_GL_ERRORS; // print results // std::cout << "CS, output buffer values: " << std::endl; for(int i=0;i<10;i++) std::cout << array2[i] << std::endl; // delete resources // glDeleteBuffers(1, &buf1); CHECK_GL_ERRORS; glDeleteBuffers(1, &buf2); CHECK_GL_ERRORS; }
void masterp(int msize, int size){ int workload, extra, offset, srows; int i, j, k; MPI_Request *reqs = new MPI_Request[2 * size]; struct timeval tim1, tim2; matrix<int> array1(msize, msize); matrix<int> array2(msize, msize); matrix<int> array3(msize, msize); for(i = 0; i < msize; i++){ for(j = 0; j < msize; j++){ array1[i][j] = rand()%10; array2[i][j] = rand()%10; } } MPI_Bcast(array2.arrptr(), msize*msize, MPI_INT, MASTER, MPI_COMM_WORLD); workload = msize/(size-1); extra = msize%(size-1); offset = 0; gettimeofday(&tim1, NULL); double t1 = tim1.tv_sec+(tim1.tv_usec/1000000.0); for(i = 1; i < size; i++){ srows = (i <= extra) ? workload+1 : workload; MPI_Isend(&srows, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &reqs[2* i]); MPI_Isend(&array1[offset][0], srows*msize, MPI_INT, i, 0, MPI_COMM_WORLD, &reqs[2*i+1]); offset+=srows; } MPI_Waitall(2 * size -2, reqs + 2, MPI_STATUSES_IGNORE); offset = 0; for(i = 1; i < size; i++){ srows = (i <= extra) ? workload+1 : workload; MPI_Irecv(array3.arrptr() + offset * w, srows * w, MPI_INT, i, 0, MPI_COMM_WORLD, &reqs[i]); offset += srows; } MPI_Waitall(size - 1, reqs + 1, MPI_STATUSES_IGNORE); gettimeofday(&tim2, NULL); double t2 = tim2.tv_sec+(tim2.tv_usec/1000000.0); printf("Total time taken in seconds: %f\n", t2-t1); }
void UT_array(const char* params) { Lumix::DefaultAllocator allocator; Lumix::Array<int> array1(allocator); LUMIX_EXPECT(array1.empty()); LUMIX_EXPECT(array1.size() == 0); array1.reserve(128); LUMIX_EXPECT(array1.size() == 0); LUMIX_EXPECT(array1.capacity() == 128); array1.reserve(256); LUMIX_EXPECT(array1.capacity() == 256); array1.reserve(64); LUMIX_EXPECT(array1.capacity() >= 64); LUMIX_EXPECT(array1.size() == 0); for (int i = 0; i < 10; ++i) { array1.push(i * 2); LUMIX_EXPECT(array1[i] == i * 2); LUMIX_EXPECT(array1.back() == i * 2); LUMIX_EXPECT(array1.indexOf(i*2) == i); } LUMIX_EXPECT(array1.size() == 10); for (int i = 0; i < 10; ++i) { LUMIX_EXPECT(array1[i] == i * 2); } array1.clear(); LUMIX_EXPECT(array1.size() == 0); LUMIX_EXPECT(array1.empty()); array1.resize(10); LUMIX_EXPECT(array1.size() == 10); array1.insert(0, 123); LUMIX_EXPECT(array1.size() == 11); LUMIX_EXPECT(array1[0] == 123); Lumix::Array<int> array2(allocator); array1.swap(array2); LUMIX_EXPECT(array2.size() == 11); LUMIX_EXPECT(array1.size() == 0); }
int main(void){ //Stack allocated array raw1 and its stack allocated Base objects. Base raw1[]={Base("one"),Base("two")}; //Heap allocated array raw2 and its heap allocated Base objects Base* raw2=new Base[3]; std::cout<<"3 dtor calls will follow shortly."<<std::endl; //forgetting to delete with [] operator will leak the all but raw2[0] delete [] raw2; std::cout<<"scoped_array init #1"<<std::endl; boost::scoped_array<Base> array1(new Base[2]); std::cout<<"scoped_array init #2"<<std::endl; Base *raw3=new Base[2]; boost::scoped_array<Base> array2(raw3); std::cout<<"exiting main..."<<std::endl; return 0; }
int main() { RLIdentRegister* iregister = new RLIdentRegister(); RLType::setRegister(iregister); RLArray array1(RLType::Number); RLArray array2(RLType::Number); array1.setElem(1,&RLNumber(100)); array1.setElem(2,&RLNumber(101)); array2.applyBinary(assign,&array1); array1.getElem(1)->applyUnary(increment); array1.print(); array2.print(); delete iregister; }
pilo::i32_t functional_test_construct(void* param) { M_UNUSED(param); fixed_array<testing_pod_info,13> array; if (array.size() != 0) { return -1; } testing_pod_info info[13]; for (int i = 0; i < 13; i++) { info[i].m_id = i; } fixed_array<testing_pod_info, 13> array1(info, 13, false); if (array1.size() != 13) { return -20; } for (int i = 0; i < (int) array1.size(); i++) { if (array1[i].m_id != i) { return -1000 + i; } } fixed_array<testing_pod_info, 12> array2(info, 13, true); if (array2.size() != 12) { return -30; } for (int i = 0; i < (int) array2.size(); i++) { if (array2[i].m_id != i) { return -2000 + i; } } return 0; }
void testTransactionManager() { printf("%s\n", "testTransactionManager"); // Insert a document in wal BaseTransaction* wal = new BaseTransaction(_controller); wal->dropNamespace("db", "mtx"); TransactionManager* manager = new TransactionManager(wal); BSONObj testA; testA.add("cod", 1); testA.add("name", "William"); wal->insert("db", "mtx", &testA); std::string* t1 = uuid(); StdTransaction* transaction = manager->getTransaction(*t1); std::auto_ptr<BSONArrayObj> array(transaction->find("db", "mtx", "*", "$'cod' == 1")); BSONObj* obj1up = array->get(0); obj1up->add("lastName", "Shakespeare"); transaction->update("db", "mtx", obj1up); std::auto_ptr<BSONArrayObj> array0(wal->find("db", "mtx", "*", "$'cod' == 1")); BSONObj* origin1 = array0->get(0); TEST_ASSERT(!origin1->has("lastName")); std::auto_ptr<BSONArrayObj> array1(transaction->find("db", "mtx", "*", "$'cod' == 1")); BSONObj* objtx1 = array1->get(0); TEST_ASSERT(objtx1->has("lastName")); transaction->commit(); manager->dropTransaction(*t1); std::auto_ptr<BSONArrayObj> array2(wal->find("db", "mtx", "*", "$'cod' == 1")); BSONObj* origin2 = array2->get(0); TEST_ASSERT(origin2->has("lastName")); delete t1; delete manager; printf("%s\n", "~testTransactionManager"); }
FX_BOOL color::equal(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { v8::Isolate* isolate = GetIsolate(cc); if (params.size() < 2) return FALSE; CJS_Array array1(isolate), array2(isolate); if (!params[0].ConvertToArray(array1)) return FALSE; if (!params[1].ConvertToArray(array2)) return FALSE; CPWL_Color color1; CPWL_Color color2; ConvertArrayToPWLColor(array1, color1); ConvertArrayToPWLColor(array2, color2); color1.ConvertColorType(color2.nColorType); vRet = color1 == color2; return TRUE; }
// a utility function to compare two parameter arrays ::testing::AssertionResult compareParameterArrays(std::shared_ptr<Region> region1, std::shared_ptr<Region> region2, std::string parameter, NTA_BasicType type) { UInt32 *buf1; UInt32 *buf2; Real32 *buf3; Real32 *buf4; Real64 *buf5; Real64 *buf6; Byte *buf7; Byte *buf8; Array array1(type); Array array2(type); region1->getParameterArray(parameter, array1); region2->getParameterArray(parameter, array2); if (type != array1.getType()) return ::testing::AssertionFailure() << "Failure: Original Array1 for parameter '" << parameter << "' is not the expected type. expected: " << BasicType::getName(type) << ", found: " << BasicType::getName(array1.getType()); if (type != array2.getType()) return ::testing::AssertionFailure() << "Failure: Restored Array2 for parameter '" << parameter << "' is not the expected type. expected: " << BasicType::getName(type) << ", found: " << BasicType::getName(array1.getType()); size_t len1 = array1.getCount(); size_t len2 = array2.getCount(); if (len1 != len2) { return ::testing::AssertionFailure() << "Failure: Arrays for parameter '" << parameter << "' are not the same length."; } switch (type) { case NTA_BasicType_UInt32: buf1 = (UInt32 *)array1.getBuffer(); buf2 = (UInt32 *)array2.getBuffer(); for (size_t i = 0; i < len1; i++) { if (buf1[i] != buf2[i]) { return ::testing::AssertionFailure() << "Failure: Array element for parameter '" << parameter << "[" << i << "]' is not the same after restore."; } } break; case NTA_BasicType_Real32: buf3 = (Real32 *)array1.getBuffer(); buf4 = (Real32 *)array2.getBuffer(); for (size_t i = 0; i < len1; i++) { if (buf3[i] != buf4[i]) { return ::testing::AssertionFailure() << "Failure: Array element for parameter '" << parameter << "[" << i << "]' is not the same after restore."; } } break; case NTA_BasicType_Real64: buf5 = (Real64 *)array1.getBuffer(); buf6 = (Real64 *)array2.getBuffer(); for (size_t i = 0; i < len1; i++) { if (buf5[i] != buf6[i]) { return ::testing::AssertionFailure() << "Failure: Array element for parameter '" << parameter << "[" << i << "]' is not the same after restore."; } } break; case NTA_BasicType_Byte: case NTA_BasicType_SDR: buf7 = (Byte *)array1.getBuffer(); buf8 = (Byte *)array2.getBuffer(); for (size_t i = 0; i < len1; i++) { if (buf7[i] != buf8[i]) { return ::testing::AssertionFailure() << "Failure: Array element for parameter '" << parameter << "[" << i << "]' is not the same after restore."; } } break; default: break; } // end switch return ::testing::AssertionSuccess(); }
DEF_TEST(SkSLMemoryLayout430Test, r) { SkSL::Context context; SkSL::MemoryLayout layout(SkSL::MemoryLayout::k430_Standard); // basic types REPORTER_ASSERT(r, 4 == layout.size(*context.fFloat_Type)); REPORTER_ASSERT(r, 8 == layout.size(*context.fVec2_Type)); REPORTER_ASSERT(r, 12 == layout.size(*context.fVec3_Type)); REPORTER_ASSERT(r, 16 == layout.size(*context.fVec4_Type)); REPORTER_ASSERT(r, 4 == layout.size(*context.fInt_Type)); REPORTER_ASSERT(r, 8 == layout.size(*context.fIVec2_Type)); REPORTER_ASSERT(r, 12 == layout.size(*context.fIVec3_Type)); REPORTER_ASSERT(r, 16 == layout.size(*context.fIVec4_Type)); REPORTER_ASSERT(r, 1 == layout.size(*context.fBool_Type)); REPORTER_ASSERT(r, 2 == layout.size(*context.fBVec2_Type)); REPORTER_ASSERT(r, 3 == layout.size(*context.fBVec3_Type)); REPORTER_ASSERT(r, 4 == layout.size(*context.fBVec4_Type)); REPORTER_ASSERT(r, 16 == layout.size(*context.fMat2x2_Type)); REPORTER_ASSERT(r, 32 == layout.size(*context.fMat2x4_Type)); REPORTER_ASSERT(r, 48 == layout.size(*context.fMat3x3_Type)); REPORTER_ASSERT(r, 32 == layout.size(*context.fMat4x2_Type)); REPORTER_ASSERT(r, 64 == layout.size(*context.fMat4x4_Type)); REPORTER_ASSERT(r, 4 == layout.alignment(*context.fFloat_Type)); REPORTER_ASSERT(r, 8 == layout.alignment(*context.fVec2_Type)); REPORTER_ASSERT(r, 16 == layout.alignment(*context.fVec3_Type)); REPORTER_ASSERT(r, 16 == layout.alignment(*context.fVec4_Type)); REPORTER_ASSERT(r, 4 == layout.alignment(*context.fInt_Type)); REPORTER_ASSERT(r, 8 == layout.alignment(*context.fIVec2_Type)); REPORTER_ASSERT(r, 16 == layout.alignment(*context.fIVec3_Type)); REPORTER_ASSERT(r, 16 == layout.alignment(*context.fIVec4_Type)); REPORTER_ASSERT(r, 1 == layout.alignment(*context.fBool_Type)); REPORTER_ASSERT(r, 2 == layout.alignment(*context.fBVec2_Type)); REPORTER_ASSERT(r, 4 == layout.alignment(*context.fBVec3_Type)); REPORTER_ASSERT(r, 4 == layout.alignment(*context.fBVec4_Type)); REPORTER_ASSERT(r, 8 == layout.alignment(*context.fMat2x2_Type)); REPORTER_ASSERT(r, 16 == layout.alignment(*context.fMat2x4_Type)); REPORTER_ASSERT(r, 16 == layout.alignment(*context.fMat3x3_Type)); REPORTER_ASSERT(r, 8 == layout.alignment(*context.fMat4x2_Type)); REPORTER_ASSERT(r, 16 == layout.alignment(*context.fMat4x4_Type)); // struct 1 std::vector<SkSL::Type::Field> fields1; fields1.emplace_back(SkSL::Modifiers(), SkString("a"), context.fVec3_Type.get()); SkSL::Type s1(SkSL::Position(), SkString("s1"), fields1); REPORTER_ASSERT(r, 16 == layout.size(s1)); REPORTER_ASSERT(r, 16 == layout.alignment(s1)); fields1.emplace_back(SkSL::Modifiers(), SkString("b"), context.fFloat_Type.get()); SkSL::Type s2(SkSL::Position(), SkString("s2"), fields1); REPORTER_ASSERT(r, 16 == layout.size(s2)); REPORTER_ASSERT(r, 16 == layout.alignment(s2)); fields1.emplace_back(SkSL::Modifiers(), SkString("c"), context.fBool_Type.get()); SkSL::Type s3(SkSL::Position(), SkString("s3"), fields1); REPORTER_ASSERT(r, 32 == layout.size(s3)); REPORTER_ASSERT(r, 16 == layout.alignment(s3)); // struct 2 std::vector<SkSL::Type::Field> fields2; fields2.emplace_back(SkSL::Modifiers(), SkString("a"), context.fInt_Type.get()); SkSL::Type s4(SkSL::Position(), SkString("s4"), fields2); REPORTER_ASSERT(r, 4 == layout.size(s4)); REPORTER_ASSERT(r, 4 == layout.alignment(s4)); fields2.emplace_back(SkSL::Modifiers(), SkString("b"), context.fVec3_Type.get()); SkSL::Type s5(SkSL::Position(), SkString("s5"), fields2); REPORTER_ASSERT(r, 32 == layout.size(s5)); REPORTER_ASSERT(r, 16 == layout.alignment(s5)); // arrays SkSL::Type array1(SkString("float[4]"), SkSL::Type::kArray_Kind, *context.fFloat_Type, 4); REPORTER_ASSERT(r, 16 == layout.size(array1)); REPORTER_ASSERT(r, 4 == layout.alignment(array1)); REPORTER_ASSERT(r, 4 == layout.stride(array1)); SkSL::Type array2(SkString("vec4[4]"), SkSL::Type::kArray_Kind, *context.fVec4_Type, 4); REPORTER_ASSERT(r, 64 == layout.size(array2)); REPORTER_ASSERT(r, 16 == layout.alignment(array2)); REPORTER_ASSERT(r, 16 == layout.stride(array2)); }
//============================================================================== int checkSharedOwnership(Epetra_Comm& Comm, bool verbose) { // check to make sure each function returns 1 when it should // check to make sure each function doesn't return 1 when it shouldn't int ierr = 0; // initialize Map const int NumMyElements = 10; const long long IndexBase = 0; Epetra_Map Map1((long long) -1, NumMyElements, IndexBase, Comm); // initialize Graphs const int NumIndicesPerRow = 5; Epetra_CrsGraph SoleOwner(Copy, Map1, Map1, NumIndicesPerRow); Epetra_CrsGraph SharedOrig(Copy, Map1, Map1, NumIndicesPerRow); Epetra_CrsGraph SharedOwner(SharedOrig); // arrays used by Insert & Remove Epetra_IntSerialDenseVector array1(2); array1[0] = NumIndicesPerRow / 2; array1[1] = array1[0] + 1; Epetra_LongLongSerialDenseVector array2(NumIndicesPerRow); for(int i = 0; i < NumIndicesPerRow; i++) array2[i] = i; // output variables (declaring them here lets us comment out indiv. tests) int soleOutput, sharedOutput; // InsertMyIndices if(verbose) cout << "InsertMyIndices..." << endl; soleOutput = SoleOwner.InsertMyIndices(0, 2, array1.Values()); sharedOutput = SharedOwner.InsertMyIndices(0, 2, array1.Values()); EPETRA_TEST_ERR(!(soleOutput == 0), ierr); EPETRA_TEST_ERR(!(sharedOutput == 1), ierr); if(verbose && ierr > 0) cout << "soleOutput = " << soleOutput << " sharedOutput = " << sharedOutput << endl; // SortIndices //if(verbose) cout << "SortIndices..." << endl; //soleOutput = SoleOwner.SortIndices(); //sharedOutput = SharedOwner.SortIndices(); //EPETRA_TEST_ERR(!(soleOutput == 0), ierr); //EPETRA_TEST_ERR(!(sharedOutput == 1), ierr); //if(verbose && ierr > 0) cout << "soleOutput = " << soleOutput << " sharedOutput = " << sharedOutput << endl; // RemoveRedundantIndices //if(verbose) cout << "RemoveRedundantIndices..." << endl; //SoleOwner.InsertGlobalIndices(0, 1, array1.Values()); //SharedOwner.InsertGlobalIndices(0, 1, array1.Values()); //soleOutput = SoleOwner.RemoveRedundantIndices(); //sharedOutput = SharedOwner.RemoveRedundantIndices(); //EPETRA_TEST_ERR(!(soleOutput == 0), ierr); //EPETRA_TEST_ERR(!(sharedOutput == 1), ierr); //if(verbose && ierr > 0) cout << "soleOutput = " << soleOutput << " sharedOutput = " << sharedOutput << endl; // FillComplete (#1) if(verbose) cout << "FillComplete..." << endl; soleOutput = SoleOwner.FillComplete(); sharedOutput = SharedOwner.FillComplete(); EPETRA_TEST_ERR(!(soleOutput == 0), ierr); EPETRA_TEST_ERR(!(sharedOutput == 1), ierr); if(verbose && ierr > 0) cout << "soleOutput = " << soleOutput << " sharedOutput = " << sharedOutput << endl; // OptimizeStorage if(verbose) cout << "OptimizeStorage..." << endl; soleOutput = SoleOwner.OptimizeStorage(); sharedOutput = SharedOwner.OptimizeStorage(); EPETRA_TEST_ERR(!(soleOutput == 0), ierr); EPETRA_TEST_ERR(!(sharedOutput == 0), ierr); if(verbose && ierr > 0) cout << "soleOutput = " << soleOutput << " sharedOutput = " << sharedOutput << endl; // RemoveMyIndices (#1) if(verbose) cout << "RemoveMyIndices..." << endl; soleOutput = SoleOwner.RemoveMyIndices(0, 1, &array1[1]); sharedOutput = SharedOwner.RemoveMyIndices(0, 1, &array1[1]); EPETRA_TEST_ERR(!(soleOutput == -1), ierr); EPETRA_TEST_ERR(!(sharedOutput == -1), ierr); if(verbose && ierr > 0) cout << "soleOutput = " << soleOutput << " sharedOutput = " << sharedOutput << endl; // RemoveMyIndices (#2) if(verbose) cout << "RemoveMyIndices(#2)..." << endl; soleOutput = SoleOwner.RemoveMyIndices(0); sharedOutput = SharedOwner.RemoveMyIndices(0); EPETRA_TEST_ERR(!(soleOutput == -1), ierr); EPETRA_TEST_ERR(!(sharedOutput == -1), ierr); if(verbose && ierr > 0) cout << "soleOutput = " << soleOutput << " sharedOutput = " << sharedOutput << endl; // FillComplete (#2) if(verbose) cout << "FillComplete(#2)..." << endl; soleOutput = SoleOwner.FillComplete(SoleOwner.DomainMap(), SoleOwner.RangeMap()); sharedOutput = SharedOwner.FillComplete(SharedOwner.DomainMap(), SharedOwner.RangeMap()); EPETRA_TEST_ERR(!(soleOutput == 0), ierr); EPETRA_TEST_ERR(!(sharedOutput == 1), ierr); if(verbose && ierr > 0) cout << "soleOutput = " << soleOutput << " sharedOutput = " << sharedOutput << endl; { // make new Graphs so that we can insert Global instead of Local // inside of new scope so that we can use same names Epetra_CrsGraph SoleOwnerG(Copy, Map1, NumIndicesPerRow); Epetra_CrsGraph SharedOrigG(Copy, Map1, NumIndicesPerRow); Epetra_CrsGraph SharedOwnerG(SharedOrig); long long GlobalRow = SoleOwnerG.GRID64(0); // InsertGlobalIndices if(verbose) cout << "InsertGlobalIndices..." << endl; soleOutput = SoleOwnerG.InsertGlobalIndices(GlobalRow, 2, array2.Values()); sharedOutput = SharedOwnerG.InsertGlobalIndices(GlobalRow, 2, array2.Values()); EPETRA_TEST_ERR(!(soleOutput == 0), ierr); EPETRA_TEST_ERR(!(sharedOutput == 1), ierr); if(verbose && ierr > 0) cout << "soleOutput = " << soleOutput << " sharedOutput = " << sharedOutput << endl; // RemoveGlobalIndices (#1) if(verbose) cout << "RemoveGlobalIndices..." << endl; soleOutput = SoleOwnerG.RemoveGlobalIndices(GlobalRow, 1, &array2[1]); sharedOutput = SharedOwnerG.RemoveGlobalIndices(GlobalRow, 1, &array2[1]); EPETRA_TEST_ERR(!(soleOutput == 0), ierr); EPETRA_TEST_ERR(!(sharedOutput == 1), ierr); if(verbose && ierr > 0) cout << "soleOutput = " << soleOutput << " sharedOutput = " << sharedOutput << endl; // RemoveGlobalIndices (#2) if(verbose) cout << "RemoveGlobalIndices(#2)..." << endl; soleOutput = SoleOwnerG.RemoveGlobalIndices(GlobalRow); sharedOutput = SharedOwnerG.RemoveGlobalIndices(GlobalRow); EPETRA_TEST_ERR(!(soleOutput == 0), ierr); EPETRA_TEST_ERR(!(sharedOutput == 1), ierr); if(verbose && ierr > 0) cout << "soleOutput = " << soleOutput << " sharedOutput = " << sharedOutput << endl; } // *PROT* InsertIndices // *PROT* MakeIndicesLocal return(ierr); }
void UnitTestDynamicArray::DoTest() { UNIT_TEST_BLOCK_START(); Dia::Core::Containers::DynamicArray<int> array(3); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array.At(0) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_POSITIVE(array.Capacity() == 3, "DynamicArray()"); UNIT_TEST_POSITIVE(array.Size() == 0, "DynamicArray()"); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[3] = {1, 2, 3}; UNIT_TEST_ASSERT_EXPECTED_START(); int* ptr = NULL; Dia::Core::Containers::DynamicArray<int> array0(ptr, 3); UNIT_TEST_ASSERT_EXPECTED_END(); Dia::Core::Containers::DynamicArray<int> array1(&cArray1[0], 3); UNIT_TEST_POSITIVE(array1.Capacity() == 3, "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.IsFull(), "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.Size() == 3, "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.At(0) == 1, "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.At(1) == 2, "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.At(2) == 3, "DynamicArray(ConstPointer pData, unsigned int _size)"); int cArray2[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> array2(&cArray2[0], 3); UNIT_TEST_POSITIVE(array2.Capacity() == 3, "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array2.IsFull(), "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array2.Size() == 3, "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array2.At(0) == 1, "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array2.At(1) == 2, "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array2.At(2) == 3, "DynamicArray(ConstPointer pData, unsigned int _size)"); int cArray3[2] = {1, 2}; Dia::Core::Containers::DynamicArray<int> array3(&cArray3[0], 2); UNIT_TEST_POSITIVE(array3.Capacity() == 2, "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.IsFull(), "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.Size() == 2, "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.At(0) == 1, "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.At(1) == 2, "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array3.At(2) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[3] = {1, 2, 3}; Dia::Core::Containers::DynamicArray<int> tempArray1(cArray1, 3); Dia::Core::Containers::DynamicArray<int> array1(tempArray1); UNIT_TEST_POSITIVE(array1.IsFull(), "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.Capacity() == 3, "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.Size() == 3, "DynamicArray(ConstReference data, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.At(0) == 1, "DynamicArray(ConstReference data, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.At(1) == 2, "DynamicArray(ConstReference data, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.At(2) == 3, "DynamicArray(ConstReference data, unsigned int _size)"); int cArray3[2] = {1, 2}; Dia::Core::Containers::DynamicArray<int> tempArray3(cArray3, 2); Dia::Core::Containers::DynamicArray<int> array3(tempArray3); UNIT_TEST_POSITIVE(array3.IsFull(), "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.Capacity() == 2, "DynamicArray(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.Size() == 2, "DynamicArray(ConstReference data, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.At(0) == 1, "DynamicArray(ConstReference data, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.At(1) == 2, "DynamicArray(ConstReference data, unsigned int _size)"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array3.At(2) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> tempArray1(cArray1, 5); Dia::Core::Containers::DynamicArray<int> array1(tempArray1); UNIT_TEST_POSITIVE(array1.IsFull(), "DynamicArray(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array1.Capacity() == 5, "DynamicArray(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array1.Size() == 5, "DynamicArray(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array1.At(0) == 1, "DynamicArray(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array1.At(1) == 2, "DynamicArray(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array1.At(2) == 3, "DynamicArray(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array1.At(3) == 4, "DynamicArray(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array1.At(4) == 5, "DynamicArray(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> tempArray(cArray, 5); UNIT_TEST_ASSERT_EXPECTED_START(); Dia::Core::Containers::DynamicArray<int> array1(tempArray, 2, 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_ASSERT_EXPECTED_START(); Dia::Core::Containers::DynamicArray<int> array1(tempArray, 5, 2); UNIT_TEST_ASSERT_EXPECTED_END(); int cArray1[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> tempArray1(cArray1, 5); Dia::Core::Containers::DynamicArray<int> array1(tempArray1, 1, 3); UNIT_TEST_POSITIVE(array1.IsFull(), "DynamicArray(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements"); UNIT_TEST_POSITIVE(array1.Capacity() == 3, "DynamicArray(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); UNIT_TEST_POSITIVE(array1.Size() == 3, "DynamicArray(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); UNIT_TEST_POSITIVE(array1.At(0) == 2, "DynamicArray(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); UNIT_TEST_POSITIVE(array1.At(1) == 3, "DynamicArray(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); UNIT_TEST_POSITIVE(array1.At(2) == 4, "DynamicArray(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); int cArray2[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> tempArray2(cArray2, 5); Dia::Core::Containers::DynamicArray<int> array2(tempArray2, 1, 2); UNIT_TEST_POSITIVE(array2.IsFull(), "DynamicArray(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements"); UNIT_TEST_POSITIVE(array2.Capacity() == 2, "DynamicArray(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); UNIT_TEST_POSITIVE(array2.Size() == 2, "DynamicArray(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); UNIT_TEST_POSITIVE(array2.At(0) == 2, "DynamicArray(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); UNIT_TEST_POSITIVE(array2.At(1) == 3, "DynamicArray(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array2.At(2) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[3] = {1, 2, 3}; Dia::Core::Containers::DynamicArray<int> tempArray1(cArray1, 3); Dia::Core::Containers::DynamicArray<int>::ConstIterator iter1(tempArray1.Begin()); Dia::Core::Containers::DynamicArray<int> array1(3, iter1); UNIT_TEST_POSITIVE(array1.IsFull(), "DynamicArray(Iterator begin)"); UNIT_TEST_POSITIVE(array1.Capacity() == 3, "DynamicArray(Iterator begin)"); UNIT_TEST_POSITIVE(array1.Size() == 3, "DynamicArray<T, size>::DynamicArray ( Iterator begin )"); UNIT_TEST_POSITIVE(array1.At(0) == 1, "DynamicArray<T, size>::DynamicArray ( Iterator begin )"); UNIT_TEST_POSITIVE(array1.At(1) == 2, "DynamicArray<T, size>::DynamicArray ( Iterator begin )"); UNIT_TEST_POSITIVE(array1.At(2) == 3, "DynamicArray<T, size>::DynamicArray ( Iterator begin )"); int cArray2[2] = {1, 2}; Dia::Core::Containers::DynamicArray<int> tempArray2(cArray2, 2); Dia::Core::Containers::DynamicArray<int> array2(3, tempArray2.BeginConst()); UNIT_TEST_POSITIVE(!array2.IsFull(), "DynamicArray(Iterator begin)"); UNIT_TEST_POSITIVE(array2.Capacity() == 3, "DynamicArray(Iterator begin)"); UNIT_TEST_POSITIVE(array2.Size() == 2, "DynamicArray<T, size>::DynamicArray ( Iterator begin )"); UNIT_TEST_POSITIVE(array2.At(0) == 1, "DynamicArray<T, size>::DynamicArray ( Iterator begin )"); UNIT_TEST_POSITIVE(array2.At(1) == 2, "DynamicArray<T, size>::DynamicArray ( Iterator begin )"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array2.At(2) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[3] = {1, 2, 3}; Dia::Core::Containers::DynamicArray<int> tempArray1(cArray1, 3); Dia::Core::Containers::DynamicArray<int> array1(3, tempArray1.EndConst()); UNIT_TEST_POSITIVE(array1.IsFull(), "DynamicArray(ConstReverseIterator begin)"); UNIT_TEST_POSITIVE(array1.Capacity() == 3, "DynamicArray(ConstReverseIterator begin)"); UNIT_TEST_POSITIVE(array1.Size() == 3, "DynamicArray<T, size>::DynamicArray ( ConstReverseIterator iter begin )"); UNIT_TEST_POSITIVE(array1.At(0) == 3, "DynamicArray<T, size>::DynamicArray ( ConstReverseIterator iter begin )"); UNIT_TEST_POSITIVE(array1.At(1) == 2, "DynamicArray<T, size>::DynamicArray ( ConstReverseIterator iter begin )"); UNIT_TEST_POSITIVE(array1.At(2) == 1, "DynamicArray<T, size>::DynamicArray ( ConstReverseIterator iter begin )"); int cArray2[2] = {1, 2}; Dia::Core::Containers::DynamicArray<int> tempArray2(cArray2, 2); Dia::Core::Containers::DynamicArray<int> array2(3, tempArray2.EndConst()); UNIT_TEST_POSITIVE(!array2.IsFull(), "DynamicArray(ConstReverseIterator begin)"); UNIT_TEST_POSITIVE(array2.Capacity() == 3, "DynamicArray(ConstReverseIterator begin)"); UNIT_TEST_POSITIVE(array2.Size() == 2, "DynamicArray<T, size>::DynamicArray ( ConstReverseIterator iter begin )"); UNIT_TEST_POSITIVE(array2.At(0) == 2, "DynamicArray<T, size>::DynamicArray ( ConstReverseIterator iter begin )"); UNIT_TEST_POSITIVE(array2.At(1) == 1, "DynamicArray<T, size>::DynamicArray ( ConstReverseIterator iter begin )"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array2.At(2) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); class AboveTwoFilter { public: bool Evaluate(const int& currentIter)const { return (currentIter > 2); }; }; AboveTwoFilter filter1; int cArray1[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> tempArray1(cArray1, 5); Dia::Core::Containers::DynamicArray<int> array1(5, tempArray1.BeginConst(), filter1); UNIT_TEST_POSITIVE(!array1.IsFull(), "DynamicArray(ConstIterator& iter, const EvaluateFunctor& filter)"); UNIT_TEST_POSITIVE(array1.Capacity() == 5, "DynamicArray(ConstIterator& iter, const EvaluateFunctor& filter)"); UNIT_TEST_POSITIVE(array1.Size() == 3, "DynamicArray<T, size>::DynamicArray ( ConstIterator& iter, const EvaluateFunctor& filter )"); UNIT_TEST_POSITIVE(array1.At(0) == 3, "DynamicArray<T, size>::DynamicArray ( ConstIterator& iter, const EvaluateFunctor<T, bool>* filter )"); UNIT_TEST_POSITIVE(array1.At(1) == 4, "DynamicArray<T, size>::DynamicArray ( ConstIterator& iter, const EvaluateFunctor<T, bool>* filter )"); UNIT_TEST_POSITIVE(array1.At(2) == 5, "DynamicArray<T, size>::DynamicArray ( ConstIterator& iter, const EvaluateFunctor<T, bool>* filter )"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array1.At(3) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array1.At(4) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[3] = {1, 2, 3}; UNIT_TEST_ASSERT_EXPECTED_START(); int* ptr = NULL; Dia::Core::Containers::DynamicArray<int> array0(3); array0.Assign(ptr, 3); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_ASSERT_EXPECTED_START(); Dia::Core::Containers::DynamicArray<int> array1(3); array1.Assign(&cArray1[0], 10); UNIT_TEST_ASSERT_EXPECTED_END(); Dia::Core::Containers::DynamicArray<int> array1(3); array1.Assign(&cArray1[0], 3); UNIT_TEST_POSITIVE(array1.IsFull(), "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.Capacity() == 3, "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.Size() == 3, "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.At(0) == 1, "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.At(1) == 2, "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.At(2) == 3, "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); int cArray2[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> array2(3); array2.Assign(&cArray2[0], 3); UNIT_TEST_POSITIVE(array2.IsFull(), "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array2.Capacity() == 3, "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array2.Size() == 3, "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array2.At(0) == 1, "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array2.At(1) == 2, "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array2.At(2) == 3, "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); int cArray3[2] = {1, 2}; Dia::Core::Containers::DynamicArray<int> array3(3); array3.Assign(&cArray3[0], 2); UNIT_TEST_POSITIVE(!array3.IsFull(), "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.Capacity() == 3, "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.Size() == 2, "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.At(0) == 1, "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.At(1) == 2, "DynamicArray.Assign(ConstPointer pData, unsigned int _size)"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array3.At(2) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[3] = {1, 2, 3}; UNIT_TEST_ASSERT_EXPECTED_START(); Dia::Core::Containers::DynamicArray<int> array1(3); array1.Assign(cArray1, 10); UNIT_TEST_ASSERT_EXPECTED_END(); Dia::Core::Containers::DynamicArray<int> tempArray1; tempArray1.Reserve(3); tempArray1.Assign(cArray1, 3); Dia::Core::Containers::DynamicArray<int> array1(tempArray1); UNIT_TEST_POSITIVE(array1.IsFull(), "DynamicArray.Assign(ConstReference pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.Capacity() == 3, "DynamicArray.Assign(ConstReference pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.Size() == 3, "DynamicArray.Assign(ConstReference data, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.At(0) == 1, "DynamicArray.Assign(ConstReference data, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.At(1) == 2, "DynamicArray.Assign(ConstReference data, unsigned int _size)"); UNIT_TEST_POSITIVE(array1.At(2) == 3, "DynamicArray.Assign(ConstReference data, unsigned int _size)"); int cArray3[2] = {1, 2}; Dia::Core::Containers::DynamicArray<int> tempArray3; tempArray3.Reserve(3); tempArray3.Assign(cArray3, 2); Dia::Core::Containers::DynamicArray<int> array3(tempArray3); UNIT_TEST_POSITIVE(!array3.IsFull(), "DynamicArray.Assign(ConstReference pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.Capacity() == 3, "DynamicArray.Assign(ConstReference pData, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.Size() == 2, "DynamicArray.Assign(ConstReference data, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.At(0) == 1, "DynamicArray.Assign(ConstReference data, unsigned int _size)"); UNIT_TEST_POSITIVE(array3.At(1) == 2, "DynamicArray.Assign(ConstReference data, unsigned int _size)"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array3.At(2) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> tempArray1(cArray1, 5); Dia::Core::Containers::DynamicArray<int> array1; array1.Reserve(5); array1.Assign(tempArray1); UNIT_TEST_POSITIVE(array1.Size() == 5, "DynamicArray(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array1.At(0) == 1, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array1.At(1) == 2, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array1.At(2) == 3, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array1.At(3) == 4, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array1.At(4) == 5, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs)"); int cArray2[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> tempArray2(cArray2, 5); Dia::Core::Containers::DynamicArray<int> array2(3); array2.Assign(tempArray2); UNIT_TEST_POSITIVE(array2.Size() == 3, "DynamicArray(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array2.At(0) == 1, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array2.At(1) == 2, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_POSITIVE(array2.At(2) == 3, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs)"); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> tempArray(cArray, 5); UNIT_TEST_ASSERT_EXPECTED_START(); Dia::Core::Containers::DynamicArray<int> array1(3); array1.Assign(tempArray, 2, 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_ASSERT_EXPECTED_START(); Dia::Core::Containers::DynamicArray<int> array1(3); array1.Assign(tempArray, 5, 2); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_ASSERT_EXPECTED_START(); Dia::Core::Containers::DynamicArray<int> array1(3); array1.Assign(tempArray, 2, 10); UNIT_TEST_ASSERT_EXPECTED_END(); int cArray1[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> tempArray1(cArray1, 5); Dia::Core::Containers::DynamicArray<int> array1(3); array1.Assign(tempArray1, 1, 3); UNIT_TEST_POSITIVE(array1.Size() == 3, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); UNIT_TEST_POSITIVE(array1.At(0) == 2, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); UNIT_TEST_POSITIVE(array1.At(1) == 3, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); UNIT_TEST_POSITIVE(array1.At(2) == 4, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); int cArray2[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> tempArray2(cArray2, 5); Dia::Core::Containers::DynamicArray<int> array2(3); array2.Assign(tempArray2, 1, 2); UNIT_TEST_POSITIVE(array2.Size() == 2, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); UNIT_TEST_POSITIVE(array2.At(0) == 2, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); UNIT_TEST_POSITIVE(array2.At(1) == 3, "DynamicArray.Assign(const DynamicArray<T,_size>& rhs, unsigned int startIndex, unsigned int numberElements)"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array2.At(2) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[3] = {1, 2, 3}; Dia::Core::Containers::DynamicArray<int> tempArray1(cArray1, 3); Dia::Core::Containers::DynamicArray<int> array1(3); array1.Assign(tempArray1.BeginConst()); UNIT_TEST_POSITIVE(array1.Size() == 3, "DynamicArray<T, size>::DynamicArray.Assign ( Iterator begin )"); UNIT_TEST_POSITIVE(array1.At(0) == 1, "DynamicArray<T, size>::DynamicArray.Assign ( Iterator begin )"); UNIT_TEST_POSITIVE(array1.At(1) == 2, "DynamicArray<T, size>::DynamicArray.Assign ( Iterator begin )"); UNIT_TEST_POSITIVE(array1.At(2) == 3, "DynamicArray<T, size>::DynamicArray.Assign ( Iterator begin )"); int cArray2[2] = {1, 2}; Dia::Core::Containers::DynamicArray<int> tempArray2(cArray2, 2); Dia::Core::Containers::DynamicArray<int> array2(3); array2.Assign(tempArray2.BeginConst()); UNIT_TEST_POSITIVE(array2.Size() == 2, "DynamicArray<T, size>::DynamicArray.Assign ( Iterator begin )"); UNIT_TEST_POSITIVE(array2.At(0) == 1, "DynamicArray<T, size>::DynamicArray.Assign ( Iterator begin )"); UNIT_TEST_POSITIVE(array2.At(1) == 2, "DynamicArray<T, size>::DynamicArray.Assign ( Iterator begin )"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array2.At(2) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[3] = {1, 2, 3}; Dia::Core::Containers::DynamicArray<int> tempArray1(cArray1, 3); Dia::Core::Containers::DynamicArray<int> array1(3); array1.Assign(tempArray1.EndConst()); UNIT_TEST_POSITIVE(array1.Size() == 3, "DynamicArray<T, size>::DynamicArray.Assign ( ConstReverseIterator iter begin )"); UNIT_TEST_POSITIVE(array1.At(0) == 3, "DynamicArray<T, size>::DynamicArray.Assign ( ConstReverseIterator iter begin )"); UNIT_TEST_POSITIVE(array1.At(1) == 2, "DynamicArray<T, size>::DynamicArray.Assign ( ConstReverseIterator iter begin )"); UNIT_TEST_POSITIVE(array1.At(2) == 1, "DynamicArray<T, size>::DynamicArray.Assign ( ConstReverseIterator iter begin )"); int cArray2[2] = {1, 2}; Dia::Core::Containers::DynamicArray<int> tempArray2(cArray2, 2); Dia::Core::Containers::DynamicArray<int> array2(3); array2.Assign(tempArray2.EndConst()); UNIT_TEST_POSITIVE(array2.Size() == 2, "DynamicArray<T, size>::DynamicArray.Assign ( ConstReverseIterator iter begin )"); UNIT_TEST_POSITIVE(array2.At(0) == 2, "DynamicArray<T, size>::DynamicArray.Assign ( ConstReverseIterator iter begin )"); UNIT_TEST_POSITIVE(array2.At(1) == 1, "DynamicArray<T, size>::DynamicArray.Assign ( ConstReverseIterator iter begin )"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array2.At(2) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); class AboveTwoFilter { public: bool Evaluate(const int& currentIter)const { return (currentIter > 2); }; }; AboveTwoFilter filter1; int cArray1[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> tempArray1(cArray1, 5); Dia::Core::Containers::DynamicArray<int> array1(5); array1.Assign(tempArray1.BeginConst(), filter1); UNIT_TEST_POSITIVE(array1.Size() == 3, "DynamicArray<T, size>::DynamicArray.Assign ( ConstIterator& iter, const EvaluateFunctor<T, bool>* filter )"); UNIT_TEST_POSITIVE(array1.At(0) == 3, "DynamicArray<T, size>::DynamicArray.Assign ( ConstIterator& iter, const EvaluateFunctor<T, bool>* filter )"); UNIT_TEST_POSITIVE(array1.At(1) == 4, "DynamicArray<T, size>::DynamicArray.Assign ( ConstIterator& iter, const EvaluateFunctor<T, bool>* filter )"); UNIT_TEST_POSITIVE(array1.At(2) == 5, "DynamicArray<T, size>::DynamicArray.Assign ( ConstIterator& iter, const EvaluateFunctor<T, bool>* filter )"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array1.At(3) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array1.At(4) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> tempArray1(cArray1, 5); Dia::Core::Containers::DynamicArray<int> array1(5); array1 = tempArray1; UNIT_TEST_POSITIVE(array1.Size() == 5, "DynamicArray opertor="); UNIT_TEST_POSITIVE(array1.At(0) == 1, "DynamicArray opertor="); UNIT_TEST_POSITIVE(array1.At(1) == 2, "DynamicArray opertor="); UNIT_TEST_POSITIVE(array1.At(2) == 3, "DynamicArray opertor="); UNIT_TEST_POSITIVE(array1.At(3) == 4, "DynamicArray opertor="); UNIT_TEST_POSITIVE(array1.At(4) == 5, "DynamicArray opertor="); int cArray2[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> tempArray2(cArray2, 5); Dia::Core::Containers::DynamicArray<int> array2(3); array2 = tempArray2; UNIT_TEST_POSITIVE(array2.Size() == 3, "DynamicArray opertor="); UNIT_TEST_POSITIVE(array2.At(0) == 1, "DynamicArray opertor="); UNIT_TEST_POSITIVE(array2.At(1) == 2, "DynamicArray opertor="); UNIT_TEST_POSITIVE(array2.At(2) == 3, "DynamicArray opertor="); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> array1(cArray1, 5); Dia::Core::Containers::DynamicArray<int> array2(array1); Dia::Core::Containers::DynamicArray<int> array3(array1, 1, 3); UNIT_TEST_POSITIVE(array1 == array2, "DynamicArray opertor=="); UNIT_TEST_NEGATIVE(array1 == array3, "DynamicArray opertor=="); UNIT_TEST_POSITIVE(array1 != array3, "DynamicArray opertor!="); UNIT_TEST_NEGATIVE(array1 != array2, "DynamicArray opertor!="); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> array1(cArray1, 5); UNIT_TEST_ASSERT_EXPECTED_START(); int temp = array1[-1]; UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_ASSERT_EXPECTED_START(); int temp = array1[6]; UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_ASSERT_EXPECTED_START(); int temp = array1.At(-1); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_ASSERT_EXPECTED_START(); int temp = array1.At(6); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_POSITIVE(array1[0] == array1.At(0), "DynamicArray opertor[]"); UNIT_TEST_POSITIVE(array1[1] == array1.At(1), "DynamicArray opertor[]"); UNIT_TEST_POSITIVE(array1[2] == array1.At(2), "DynamicArray opertor[]"); UNIT_TEST_POSITIVE(array1[3] == array1.At(3), "DynamicArray opertor[]"); UNIT_TEST_POSITIVE(array1[4] == array1.At(4), "DynamicArray opertor[]"); UNIT_TEST_POSITIVE(array1.Front() == array1.At(0), "DynamicArray Front"); UNIT_TEST_POSITIVE(array1.Back() == array1.At(4), "DynamicArray Back"); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[5] = {1, 2, 3, 4, 5}; Dia::Core::Containers::DynamicArray<int> array1(cArray1, 5); UNIT_TEST_POSITIVE(&array1[0] == array1.IteratorAt(0).Current(), "DynamicArray IteratorAt"); UNIT_TEST_POSITIVE(&array1[1] == array1.IteratorAt(1).Current(), "DynamicArray IteratorAt"); UNIT_TEST_POSITIVE(&array1[2] == array1.IteratorAt(2).Current(), "DynamicArray IteratorAt"); UNIT_TEST_POSITIVE(&array1[3] == array1.IteratorAt(3).Current(), "DynamicArray IteratorAt"); UNIT_TEST_POSITIVE(&array1[4] == array1.IteratorAt(4).Current(), "DynamicArray IteratorAt"); UNIT_TEST_POSITIVE(array1.Begin() == array1.IteratorAt(0), "DynamicArray Begin"); UNIT_TEST_POSITIVE(array1.BeginConst() == array1.IteratorAtConst(0), "DynamicArray BeginConst"); UNIT_TEST_POSITIVE(&array1[0] == array1.ReverseIteratorAt(0).Current(), "DynamicArray ReverseIteratorAt"); UNIT_TEST_POSITIVE(&array1[1] == array1.ReverseIteratorAt(1).Current(), "DynamicArray ReverseIteratorAt"); UNIT_TEST_POSITIVE(&array1[2] == array1.ReverseIteratorAt(2).Current(), "DynamicArray ReverseIteratorAt"); UNIT_TEST_POSITIVE(&array1[3] == array1.ReverseIteratorAt(3).Current(), "DynamicArray ReverseIteratorAt"); UNIT_TEST_POSITIVE(&array1[4] == array1.ReverseIteratorAt(4).Current(), "DynamicArray ReverseIteratorAt"); UNIT_TEST_POSITIVE(array1.End() == array1.ReverseIteratorAt(4), "DynamicArray End"); UNIT_TEST_POSITIVE(array1.EndConst() == array1.ReverseIteratorAtConst(4), "DynamicArray EndConst"); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[10] = {1, 2, 3, 4, 5, 1, 3, 3, 3, 4}; Dia::Core::Containers::DynamicArray<int> array1(cArray1, 10); UNIT_TEST_POSITIVE(array1.FrequencyOfElement(1) == 2, "DynamicArray FrequencyOfElement"); UNIT_TEST_POSITIVE(array1.FrequencyOfElement(2) == 1, "DynamicArray FrequencyOfElement"); UNIT_TEST_POSITIVE(array1.FrequencyOfElement(3) == 4, "DynamicArray FrequencyOfElement"); UNIT_TEST_POSITIVE(array1.FrequencyOfElement(4) == 2, "DynamicArray FrequencyOfElement"); UNIT_TEST_POSITIVE(array1.FrequencyOfElement(5) == 1, "DynamicArray FrequencyOfElement"); UNIT_TEST_POSITIVE(array1.FrequencyOfElement(6) == 0, "DynamicArray FrequencyOfElement"); Dia::Core::Containers::DynamicArray<int> arrayUnique(10); array1.UniqueElements(arrayUnique); UNIT_TEST_POSITIVE(arrayUnique.Size() == 5, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayUnique[0] == 1, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayUnique[1] == 2, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayUnique[2] == 3, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayUnique[3] == 4, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayUnique[4] == 5, "DynamicArray numberOfUniqueElements"); Dia::Core::Containers::DynamicArray<int> arrayFreqUnique(10); Dia::Core::Containers::DynamicArray<int> arrayFreq(10); array1.FrequencyUniqueElements(arrayFreqUnique, arrayFreq); UNIT_TEST_POSITIVE(arrayFreqUnique.Size() == 5, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayFreqUnique[0] == 1, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayFreqUnique[1] == 2, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayFreqUnique[2] == 3, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayFreqUnique[3] == 4, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayFreqUnique[4] == 5, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayFreq[0] == 2, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayFreq[1] == 1, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayFreq[2] == 4, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayFreq[3] == 2, "DynamicArray numberOfUniqueElements"); UNIT_TEST_POSITIVE(arrayFreq[4] == 1, "DynamicArray numberOfUniqueElements"); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); class IncreasingOrder { public: bool GreaterThen(const int& object1, const int& object2)const { return (object1 > object2); } bool LessThen(const int& object1, const int& object2)const { return (object1 < object2); } bool Equal(const int& object1, const int& object2)const { return (object1 == object2); } }; IncreasingOrder order; int cArray1[10] = {1, 2, 3, 4, 5, 1, 3, 3, 3, 4}; int cArray2[5] = {4, 2, 5, 1, 3}; Dia::Core::Containers::DynamicArray<int> array1(cArray1, 10); Dia::Core::Containers::DynamicArray<int> array2(cArray2, 5); Dia::Core::Containers::DynamicArray<int> array3(cArray1, 10); Dia::Core::Containers::DynamicArray<int> array4(cArray2, 5); array1.Sort(order); UNIT_TEST_POSITIVE(array1[0] == 1, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array1[1] == 1, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array1[2] == 2, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array1[3] == 3, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array1[4] == 3, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array1[5] == 3, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array1[6] == 3, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array1[7] == 4, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array1[8] == 4, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array1[9] == 5, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array1.IsSorted(order), "DynamicArray Sort"); array2.Sort(order); UNIT_TEST_POSITIVE(array2[0] == 1, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array2[1] == 2, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array2[2] == 3, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array2[3] == 4, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array2[4] == 5, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array2.IsSorted(order), "DynamicArray Sort"); array3.Sort(); UNIT_TEST_POSITIVE(array3[0] == 1, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array3[1] == 1, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array3[2] == 2, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array3[3] == 3, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array3[4] == 3, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array3[5] == 3, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array3[6] == 3, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array3[7] == 4, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array3[8] == 4, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array3[9] == 5, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array3.IsSorted(), "DynamicArray Sort"); array4.Sort(); UNIT_TEST_POSITIVE(array4[0] == 1, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array4[1] == 2, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array4[2] == 3, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array4[3] == 4, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array4[4] == 5, "DynamicArray Sort"); UNIT_TEST_POSITIVE(array4.IsSorted(), "DynamicArray Sort"); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[5] = {1, 2, 3, 4, 5}; int cArray2[5] = {4, 2, 5, 1, 3}; Dia::Core::Containers::DynamicArray<int> array1(cArray1, 5); Dia::Core::Containers::DynamicArray<int> array2(cArray2, 5); array1.Swap(array2); UNIT_TEST_POSITIVE(array1[0] == 4, "DynamicArray Swap"); UNIT_TEST_POSITIVE(array1[1] == 2, "DynamicArray Swap"); UNIT_TEST_POSITIVE(array1[2] == 5, "DynamicArray Swap"); UNIT_TEST_POSITIVE(array1[3] == 1, "DynamicArray Swap"); UNIT_TEST_POSITIVE(array1[4] == 3, "DynamicArray Swap"); UNIT_TEST_POSITIVE(array2[0] == 1, "DynamicArray Swap"); UNIT_TEST_POSITIVE(array2[1] == 2, "DynamicArray Swap"); UNIT_TEST_POSITIVE(array2[2] == 3, "DynamicArray Swap"); UNIT_TEST_POSITIVE(array2[3] == 4, "DynamicArray Swap"); UNIT_TEST_POSITIVE(array2[4] == 5, "DynamicArray Swap"); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[10] = {1, 2, 3, 4, 5, 6, 3, 4, 5, 7}; Dia::Core::Containers::DynamicArray<int> array1(cArray1, 10); class OneLess { public: bool Equal(const int& object1, const int& object2)const { return (object1 == (object2 - 1)); } }; OneLess oneLess; UNIT_TEST_ASSERT_EXPECTED_START(); array1.FindBetweenIndex(5, -2, 3); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_ASSERT_EXPECTED_START(); array1.FindBetweenIndex(5, 3, 1); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_ASSERT_EXPECTED_START(); array1.FindBetweenIndex(5, 0, 17); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_POSITIVE(array1.FindIndex(5) == 4 , "DynamicArray FindIndex"); UNIT_TEST_POSITIVE(array1.FindIndex(7) == 9, "DynamicArray FindIndex"); UNIT_TEST_POSITIVE(array1.FindIndex(10) == -1, "DynamicArray FindIndex"); UNIT_TEST_POSITIVE(array1.FindBetweenIndex(5, 0, 7) == 4 , "DynamicArray FindBetweenIndex"); UNIT_TEST_POSITIVE(array1.FindBetweenIndex(5, 6, 9) == 8, "DynamicArray FindBetweenIndex"); UNIT_TEST_POSITIVE(array1.FindBetweenIndex(1, 6, 9) == -1, "DynamicArray FindBetweenIndex"); UNIT_TEST_POSITIVE(array1.FindIndex(5, oneLess) == 3 , "DynamicArray FindIndex"); UNIT_TEST_POSITIVE(array1.FindIndex(7, oneLess) == 5, "DynamicArray FindIndex"); UNIT_TEST_POSITIVE(array1.FindIndex(10, oneLess) == -1, "DynamicArray FindIndex"); UNIT_TEST_POSITIVE(array1.FindBetweenIndex(5, oneLess, 0, 7) == 3 , "DynamicArray FindBetweenIndex"); UNIT_TEST_POSITIVE(array1.FindBetweenIndex(5, oneLess, 6, 9) == 7, "DynamicArray FindBetweenIndex"); UNIT_TEST_POSITIVE(array1.FindBetweenIndex(1, oneLess, 6, 9) == -1, "DynamicArray FindBetweenIndex"); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[10] = {1, 2, 3, 4, 5, 6, 3, 4, 5, 7}; Dia::Core::Containers::DynamicArray<int> array1(cArray1, 10); class OneLess { public: bool Equal(const int& object1, const int& object2)const { return (object1 == (object2 - 1)); } }; OneLess oneLess; UNIT_TEST_ASSERT_EXPECTED_START(); array1.FindLastBetweenIndex(5, -2, 3); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_ASSERT_EXPECTED_START(); array1.FindLastBetweenIndex(5, 3, 1); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_ASSERT_EXPECTED_START(); array1.FindLastBetweenIndex(5, 0, 17); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_POSITIVE(array1.FindLastIndex(5) == 8 , "DynamicArray FindLastIndex"); UNIT_TEST_POSITIVE(array1.FindLastIndex(3) == 6, "DynamicArray FindLastIndex"); UNIT_TEST_POSITIVE(array1.FindLastIndex(10) == -1, "DynamicArray FindLastIndex"); UNIT_TEST_POSITIVE(array1.FindLastBetweenIndex(4, 0, 7) == 7 , "DynamicArray FindLastBetweenIndex"); UNIT_TEST_POSITIVE(array1.FindLastBetweenIndex(5, 6, 9) == 8, "DynamicArray FindLastBetweenIndex"); UNIT_TEST_POSITIVE(array1.FindLastBetweenIndex(1, 6, 9) == -1, "DynamicArray FindLastBetweenIndex"); UNIT_TEST_POSITIVE(array1.FindLastIndex(5, oneLess) == 7 , "DynamicArray FindLastIndex"); UNIT_TEST_POSITIVE(array1.FindLastIndex(7, oneLess) == 5, "DynamicArray FindLastIndex"); UNIT_TEST_POSITIVE(array1.FindLastIndex(10, oneLess) == -1, "DynamicArray FindLastIndex"); UNIT_TEST_POSITIVE(array1.FindLastBetweenIndex(5, oneLess, 0, 7) == 7 , "DynamicArray FindLastBetweenIndex"); UNIT_TEST_POSITIVE(array1.FindLastBetweenIndex(5, oneLess, 6, 9) == 7, "DynamicArray FindLastBetweenIndex"); UNIT_TEST_POSITIVE(array1.FindLastBetweenIndex(1, oneLess, 6, 9) == -1, "DynamicArray FindLastBetweenIndex"); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); int cArray1[10] = {1, 2, 3, 4, 5, 6, 3, 4, 5, 7}; Dia::Core::Containers::DynamicArray<int> array1(cArray1, 10); array1.Sort(); class Equality { public: bool GreaterThen(const int& object1, const int& object2)const { return (object1 > object2); } bool LessThen(const int& object1, const int& object2)const { return (object1 < object2); } bool Equal(const int& object1, const int& object2)const { return (object1 == object2); } }; Equality equality; UNIT_TEST_POSITIVE(array1.IsSorted(), "DynamicArray FindSortedIndex"); UNIT_TEST_POSITIVE(array1.FindSortedIndex(5) == 6 , "DynamicArray FindSortedIndex"); UNIT_TEST_POSITIVE(array1.FindSortedIndex(3) == 2, "DynamicArray FindSortedIndex"); UNIT_TEST_POSITIVE(array1.FindSortedIndex(10) == -1, "DynamicArray FindSortedIndex"); UNIT_TEST_POSITIVE(array1.FindLastSortedIndex(4) == 5 , "DynamicArray FindLastSortedIndex"); UNIT_TEST_POSITIVE(array1.FindLastSortedIndex(5) == 7, "DynamicArray FindLastSortedIndex"); UNIT_TEST_POSITIVE(array1.FindLastSortedIndex(10) == -1, "DynamicArray FindLastSortedIndex"); UNIT_TEST_POSITIVE(array1.FindSortedIndex(5, equality) == 6 , "DynamicArray FindSortedIndex"); UNIT_TEST_POSITIVE(array1.FindSortedIndex(3, equality) == 2, "DynamicArray FindSortedIndex"); UNIT_TEST_POSITIVE(array1.FindSortedIndex(10, equality) == -1, "DynamicArray FindSortedIndex"); UNIT_TEST_POSITIVE(array1.FindLastSortedIndex(4, equality) == 5 , "DynamicArray FindLastSortedIndex"); UNIT_TEST_POSITIVE(array1.FindLastSortedIndex(5, equality) == 7, "DynamicArray FindLastSortedIndex"); UNIT_TEST_POSITIVE(array1.FindLastSortedIndex(10, equality) == -1, "DynamicArray FindLastSortedIndex"); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); class Eval { public: float Evaluate(const int& object1)const { return static_cast<float>(object1); }; }; Eval eval; int cArray1[10] = {1, 2, 3, 9, 5, 6, 3, 4, 5, 7}; Dia::Core::Containers::DynamicArray<int> array1(cArray1, 10); UNIT_TEST_POSITIVE(array1.HighestEvalutionIndex(eval) == 3, "DynamicArray HighestEvalutionIndex"); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); class Foo { public: Foo(): mSomeData(true), mMoreData(21.0f){} bool SomeData(){return mSomeData;} float MoreData(){return mMoreData;} bool mSomeData; float mMoreData; }; Foo cArray1[3]; Dia::Core::Containers::DynamicArray<Foo> array1(cArray1, 3); cArray1[0].mSomeData = false; cArray1[0].mMoreData = 11.0f; UNIT_TEST_POSITIVE(array1.Size() == 3, "DynamicArray Test Non primitive"); UNIT_TEST_POSITIVE(array1.At(0).SomeData(), "DynamicArray Test Non primitive"); UNIT_TEST_POSITIVE(array1.At(1).SomeData(), "DynamicArray Test Non primitive"); UNIT_TEST_POSITIVE(array1.At(2).SomeData(), "DynamicArray Test Non primitive"); UNIT_TEST_POSITIVE(array1.At(0).MoreData() == 21.0f, "DynamicArray Test Non primitive"); UNIT_TEST_POSITIVE(array1.At(1).MoreData() == 21.0f, "DynamicArray Test Non primitive"); UNIT_TEST_POSITIVE(array1.At(2).MoreData() == 21.0f, "DynamicArray Test Non primitive"); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); Dia::Core::Containers::DynamicArray<int> array1(3); array1.Add(1); array1.AddDefault(); array1.Add(2); UNIT_TEST_POSITIVE(array1.Size() == 3, "DynamicArray Add"); UNIT_TEST_POSITIVE(array1.At(0) == 1, "DynamicArray Add"); UNIT_TEST_POSITIVE(array1.At(1) == 0, "DynamicArray AddDefault"); UNIT_TEST_POSITIVE(array1.At(2) == 2, "DynamicArray Add"); Dia::Core::Containers::DynamicArray<int> array2(3); array2.FillDefault(); UNIT_TEST_POSITIVE(array2.Size() == 3, "DynamicArray Add"); UNIT_TEST_POSITIVE(array2.At(0) == 0, "DynamicArray FillDefault"); UNIT_TEST_POSITIVE(array2.At(1) == 0, "DynamicArray FillDefault"); UNIT_TEST_POSITIVE(array2.At(2) == 0, "DynamicArray FillDefault"); Dia::Core::Containers::DynamicArray<int> array3(3); array3.Fill(11); UNIT_TEST_POSITIVE(array3.Size() == 3, "DynamicArray Add"); UNIT_TEST_POSITIVE(array3.At(0) == 11, "DynamicArray Fill"); UNIT_TEST_POSITIVE(array3.At(1) == 11, "DynamicArray Fill"); UNIT_TEST_POSITIVE(array3.At(2) == 11, "DynamicArray Fill"); Dia::Core::Containers::DynamicArray<int> array4(3); array4.FillDefault(); UNIT_TEST_POSITIVE(array4.Size() == 3, "DynamicArray Add"); UNIT_TEST_POSITIVE(array4.At(0) == 0, "DynamicArray Fill"); UNIT_TEST_POSITIVE(array4.At(1) == 0, "DynamicArray Fill"); UNIT_TEST_POSITIVE(array4.At(2) == 0, "DynamicArray Fill"); Dia::Core::Containers::DynamicArray<int> array5(5); array5.AddDefault(); array5.AddAt(1, 0); array5.AddAt(2, 1); array5.AddAt(3, 1); array5.AddAt(4, 3); UNIT_TEST_POSITIVE(array5.Size() == 5, "DynamicArray Add"); UNIT_TEST_POSITIVE(array5.At(0) == 1, "DynamicArray Fill"); UNIT_TEST_POSITIVE(array5.At(1) == 3, "DynamicArray Fill"); UNIT_TEST_POSITIVE(array5.At(2) == 2, "DynamicArray Fill"); UNIT_TEST_POSITIVE(array5.At(3) == 4, "DynamicArray Fill"); UNIT_TEST_POSITIVE(array5.At(4) == 0, "DynamicArray Fill"); UNIT_TEST_BLOCK_END(); UNIT_TEST_BLOCK_START(); Dia::Core::Containers::DynamicArray<int> array1(3); array1.Fill(11); array1.Remove(); UNIT_TEST_POSITIVE(array1.Size() == 2, "DynamicArray Remove"); UNIT_TEST_POSITIVE(array1.At(0) == 11, "DynamicArray Remove"); UNIT_TEST_POSITIVE(array1.At(1) == 11, "DynamicArray Remove"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array1.At(2) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); Dia::Core::Containers::DynamicArray<int> array2(3); array2.Add(1); array2.Add(2); array2.Add(3); array2.RemoveAt(1); UNIT_TEST_POSITIVE(array2.Size() == 2, "DynamicArray Remove"); UNIT_TEST_POSITIVE(array2.At(0) == 1, "DynamicArray Remove"); UNIT_TEST_POSITIVE(array2.At(1) == 3, "DynamicArray Remove"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array2.At(2) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); Dia::Core::Containers::DynamicArray<int> array3(3); array3.Add(1); array3.Add(2); array3.Add(3); array3.RemoveFirst(2); UNIT_TEST_POSITIVE(array3.Size() == 2, "DynamicArray Remove"); UNIT_TEST_POSITIVE(array3.At(0) == 1, "DynamicArray Remove"); UNIT_TEST_POSITIVE(array3.At(1) == 3, "DynamicArray Remove"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array3.At(2) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); Dia::Core::Containers::DynamicArray<int> array4(3); array4.Add(1); array4.Add(2); array4.Add(3); array4.RemoveLast(2); UNIT_TEST_POSITIVE(array4.Size() == 2, "DynamicArray Remove"); UNIT_TEST_POSITIVE(array4.At(0) == 1, "DynamicArray Remove"); UNIT_TEST_POSITIVE(array4.At(1) == 3, "DynamicArray Remove"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array4.At(2) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); Dia::Core::Containers::DynamicArray<int> array5(3); array5.Add(1); array5.Add(2); array5.Add(3); array5.RemoveAll(); UNIT_TEST_POSITIVE(array5.Size() == 0, "DynamicArray Remove"); Dia::Core::Containers::DynamicArray<int> array6(5); array6.Add(1); array6.Add(2); array6.Add(3); array6.Add(2); array6.Add(3); array6.RemoveAll(2); UNIT_TEST_POSITIVE(array6.Size() == 3, "DynamicArray Remove"); UNIT_TEST_POSITIVE(array6.At(0) == 1, "DynamicArray Remove"); UNIT_TEST_POSITIVE(array6.At(1) == 3, "DynamicArray Remove"); UNIT_TEST_POSITIVE(array6.At(2) == 3, "DynamicArray Remove"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array6.At(3) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); class Comparisson { public: bool Evaluate(const int&a)const { return (a == 2); }; }; Comparisson compare; Dia::Core::Containers::DynamicArray<int> array7(5); array7.Add(1); array7.Add(2); array7.Add(3); array7.Add(2); array7.Add(3); array7.RemoveAll(compare); UNIT_TEST_POSITIVE(array7.Size() == 3, "DynamicArray Remove"); UNIT_TEST_POSITIVE(array7.At(0) == 1, "DynamicArray Remove"); UNIT_TEST_POSITIVE(array7.At(1) == 3, "DynamicArray Remove"); UNIT_TEST_POSITIVE(array7.At(2) == 3, "DynamicArray Remove"); UNIT_TEST_ASSERT_EXPECTED_START(); bool test = (array7.At(3) == 0); UNIT_TEST_ASSERT_EXPECTED_END(); UNIT_TEST_BLOCK_END(); mState = kFinished; }