//CPU TIME void TerminationCriterionTest::test_cpu_time_common( bool inner ) { MsqPrintError err(std::cout); PatchData pd; double LIMIT = 0.5; TerminationCriterion tc; tc.add_cpu_time(LIMIT); if (inner) tc.reset_inner( pd, ofEval, err ); else tc.reset_outer( 0, 0, ofEval, 0, err ); ASSERT_NO_ERROR(err); tc.reset_patch( pd, err ); ASSERT_NO_ERROR(err); Timer timer; while (timer.since_birth() < 0.5*LIMIT) { CPPUNIT_ASSERT(!tc.terminate()); tc.accumulate_patch( pd, err ); ASSERT_NO_ERROR(err); if (inner) tc.accumulate_inner( pd, 0, 0, err ); else tc.accumulate_outer( 0, 0, ofEval, 0, err ); ASSERT_NO_ERROR(err); } while (timer.since_birth() < 1.1*LIMIT); tc.accumulate_patch( pd, err ); ASSERT_NO_ERROR(err); if (inner) tc.accumulate_inner( pd, 0, 0, err ); else tc.accumulate_outer( 0, 0, ofEval, 0, err ); ASSERT_NO_ERROR(err); CPPUNIT_ASSERT(tc.terminate()); }
void TerminationCriterionTest::test_number_of_iterates_outer() { MsqPrintError err(std::cout); PatchData pd; const int LIMIT = 2; TerminationCriterion tc; tc.add_iteration_limit(LIMIT); tc.reset_outer( 0, 0, ofEval, 0, err ); ASSERT_NO_ERROR(err); tc.reset_patch( pd, err ); ASSERT_NO_ERROR(err); for (int i = 0; i < LIMIT; ++i) { CPPUNIT_ASSERT(!tc.terminate()); CPPUNIT_ASSERT_EQUAL( i, tc.get_iteration_count() ); tc.accumulate_patch( pd, err ); ASSERT_NO_ERROR(err); tc.accumulate_outer( 0, 0, ofEval, 0, err ); ASSERT_NO_ERROR(err); } CPPUNIT_ASSERT_EQUAL( 2, tc.get_iteration_count() ); CPPUNIT_ASSERT(tc.terminate()); }