void TextTestResult::printErrors (std::ostream &stream) { if (testErrors () != 0) { if (testErrors () == 1) { stream << "There was " << testErrors () << " error: " << std::endl; } else { stream << "There were " << testErrors () << " errors: " << std::endl; } // if printCauses(stream, errors()); } // if }
MojErr MojDbQuotaTest::run() { MojDb db; MojErr err = db.open(MojDbTestDir); MojTestErrCheck(err); MojObject obj; err = obj.fromJson(MojTestKind1Str1); MojTestErrCheck(err); err = db.putKind(obj); MojTestErrCheck(err); err = testUsage(db); MojTestErrCheck(err); err = testMultipleQuotas(db); MojTestErrCheck(err); err = testEnforce(db); MojTestErrCheck(err); err = db.close(); MojErrCheck(err); err = testErrors(); MojTestErrCheck(err); return MojErrNone; }
void TextTestResult::printErrors(std::ostream& stream) { if (testErrors() != 0) { stream << "\n"; if (testErrors() == 1) stream << "There was " << testErrors() << " error: " << std::endl; else stream << "There were " << testErrors() << " errors: " << std::endl; int i = 1; for (std::vector<TestFailure*>::iterator it = errors().begin(); it != errors().end(); ++it) { TestFailure* failure = *it; CppUnitException* e = failure->thrownException(); stream << std::setw(2) << i << ": " << failure->failedTest()->toString() << "\n" << " \"" << (e ? e->what() : "") << "\"\n" << " in \"" << (e ? e->fileName() : std::string()) << "\", line "; if (e == 0) { stream << "0"; } else { stream << e->lineNumber(); if (e->data2LineNumber() != CppUnitException::CPPUNIT_UNKNOWNLINENUMBER) { stream << " data lines " << e->data1LineNumber() << ", " << e->data2LineNumber(); } else if (e->data1LineNumber() != CppUnitException::CPPUNIT_UNKNOWNLINENUMBER) { stream << " data line " << e->data1LineNumber(); } } stream << "\n"; i++; } } }
int main(){ testEnterAndRetrieve(); testCopyConstructor(); testClear(); testSameKey(); testGetKeyTypeMap(); testErrors(); FINALREPORT("TEST_CONTENT_VALUE"); }
void TextTestResult::printHeader(std::ostream& stream) { stream << "\n\n"; if (wasSuccessful()) stream << "OK (" << runTests() << " tests)" << std::endl; else stream << "!!!FAILURES!!!" << std::endl << "Runs: " << runTests () << " Failures: " << testFailures () << " Errors: " << testErrors () << std::endl; }
bool FileSystem::findCurrentRobotName(void) { ur::error_state io_state; bool have_name = false; boost::filesystem::fstream fs; boost::filesystem::path p = m_pathImageBase; p += "/etc/hostname"; if ( !boost::filesystem::exists(p) || !boost::filesystem::is_regular_file(p) ) return (false); fs.open(p, std::ios_base::in); if ( !fs.is_open() ) { return (false); } else { while(getline( fs, m_sRobotName ) && !have_name ) { //strip leading and trailing white space trim( m_sRobotName ); // empty lines are valid in a hostname file if ( !m_sRobotName.empty() ) have_name = true; io_state = testErrors(fs); if ( io_state.fatal ) { if ( ( io_state.state == HF_FAIL ) || ( io_state.state == HF_BAD ) ) return (false); } break; } } fs.close(); return (true); }
void TextTestResult::printHeader (std::ostream &stream) { if (wasSuccessful ()) std::cout << "OK (" << runTests () << " tests and " << testSuccesses() << " assertions in " << elapsedTime() << " ms)" << std::endl; else std::cout << std::endl << "!!!FAILURES!!!" << std::endl << "Test Results:" << std::endl << "Run: " << runTests () << " Failures: " << testFailures () << " Errors: " << testErrors () << std::endl << "(" << testSuccesses() << " assertions ran successfully in " << elapsedTime() << " ms)" << std::endl; }
int main() { double x[2],y[2],yp[2]; double mseTr[2]; double testErr[2],wTestErr[2]; double binErr[2], wBinErr[2]; double xmlErr[2], wXmlErr[2]; double sumErr; LWPR_Model model; int i,j; int numRFS; /* This allocates some memory and sets initial values ** Note that the model structure itself already exists (on the stack) */ lwpr_init_model(&model,2,2,"2D_Cross"); /* Set initial distance metric to 50*(identity matrix) */ lwpr_set_init_D_spherical(&model,50); /* Set init_alpha to 250 in all elements */ lwpr_set_init_alpha(&model,250); /* Set w_gen to 0.2 */ model.w_gen = 0.2; /* See above definition, we either use srand() on Windows or srand48 everywhere else */ SEED_RAND(); for (j=0;j<20;j++) { mseTr[0] = mseTr[1] = 0.0; for (i=0;i<1000;i++) { x[0] = 2.0*URAND()-1.0; x[1] = 2.0*URAND()-1.0; y[0] = cross(x[0],x[1]) + 0.1*URAND()-0.05; y[1] = y[0] + 10; /* sanity check */ /* Update the model with one sample ** ** x points to (x[0],x[1]) (input vector) ** &y points to y (output "vector") ** &yp points to yp (prediction "vector") ** ** If you are interested in maximum activation, call ** lwpr_update(&model, x, &y, &yp, &max_w); */ lwpr_update(&model, x, y, yp, NULL); mseTr[0]+=(y[0]-yp[0])*(y[0]-yp[0]); mseTr[1]+=(y[1]-yp[1])*(y[1]-yp[1]); } mseTr[0]/=500; mseTr[1]/=500; printf("#Data = %d #RFS = %d / %d MSE = %f / %f\n",model.n_data, model.sub[0].numRFS, model.sub[1].numRFS, mseTr[0], mseTr[1]); } if (model.n_data != 20000) { fprintf(stderr,"model.n_data should have been 20*1000 = 20000. Something is very wrong!\n"); exit(1); } if (model.sub[0].numRFS != model.sub[1].numRFS) { fprintf(stderr,"There should have been an equal number of receptive fields for both outputs :-(\n"); exit(1); } numRFS = model.sub[0].numRFS; testErrors(&model, testErr, wTestErr); printf("MSE on test data: %f / %f\n",testErr[0], testErr[1]); if (fabs(testErr[0]-testErr[1]) > 1e-4) { fprintf(stderr,"MSE should be equal for both outputs, but the difference is > 1e-4\n"); exit(1); } printf("Weighted MSE....: %f / %f\n",wTestErr[0], wTestErr[1]); if (fabs(wTestErr[0]-wTestErr[1]) > 1e-4) { fprintf(stderr,"Weighted MSE should be equal for both outputs, but the difference is > 1e-4\n"); exit(1); } printf("Writing the model to a binary file\n"); /* Write the model to an XML file */ lwpr_write_binary(&model,"lwpr_cross_2d.dat"); /* Free the memory that was allocated for receptive fields etc. */ lwpr_free_model(&model); printf("Re-read the model from the binary file\n"); /* Read a model from an XML file, memory allocation is done automatically, ** but later lwpr_free_model has to be called again */ j=lwpr_read_binary(&model,"lwpr_cross_2d.dat"); remove("lwpr_cross_2d.dat"); if (j==0) { fprintf(stderr,"File could not be read, aborting\n"); exit(1); } printf("#Data = %d #RFS = %d / %d\n",model.n_data, model.sub[0].numRFS, model.sub[1].numRFS); if (model.n_data != 20000 || model.sub[0].numRFS!=numRFS || model.sub[1].numRFS!=numRFS) { fprintf(stderr,"Model (from binary file) seems to be broken :-(\n"); exit(1); } testErrors(&model, binErr, wBinErr); printf("MSE on test data: %f / %f\n",binErr[0], binErr[1]); printf("Weighted MSE....: %f / %f\n",wBinErr[0], wBinErr[1]); sumErr = fabs(binErr[0] - testErr[0]) + fabs(binErr[1] - testErr[1]); sumErr+= fabs(wBinErr[0] - wTestErr[0]) + fabs(wBinErr[1] - wTestErr[1]); if (sumErr>1e-8) { fprintf(stderr,"Error statistics from the binary-IO LWPR model are not the same :-(\n"); exit(1); } #if HAVE_LIBEXPAT printf("Writing the model to an XML file\n"); /* Write the model to an XML file */ lwpr_write_xml(&model,"lwpr_cross_2d.xml"); /* Free the memory that was allocated for receptive fields etc. */ lwpr_free_model(&model); /* Read a model from an XML file, memory allocation is done automatically, ** but later lwpr_free_model has to be called again */ j=lwpr_read_xml(&model,"lwpr_cross_2d.xml",&i); remove("lwpr_cross_2d.xml"); printf("Re-read the model from the XML file\n"); printf("%d errors %d warnings\n",j,i); if (j!=0) { printf("Errors detected, aborting\n"); exit(1); } printf("#Data = %d #RFS = %d / %d\n",model.n_data, model.sub[0].numRFS, model.sub[1].numRFS); if (model.n_data != 20000 || model.sub[0].numRFS!=numRFS || model.sub[1].numRFS!=numRFS) { fprintf(stderr,"Model (from XML file) seems to be broken :-(\n"); exit(1); } testErrors(&model, xmlErr, wXmlErr); printf("MSE on test data: %f / %f\n",xmlErr[0], xmlErr[1]); printf("Weighted MSE....: %f / %f\n",wXmlErr[0], wXmlErr[1]); sumErr = fabs(xmlErr[0] - testErr[0]) + fabs(xmlErr[1] - testErr[1]); sumErr+= fabs(wXmlErr[0] - wTestErr[0]) + fabs(wXmlErr[1] - wTestErr[1]); sumErr/=fabs(testErr[0]) + fabs(testErr[1]) + fabs(wTestErr[0]) + fabs(wTestErr[1]); printf("Relative difference to the original model: %f\n",sumErr); if (sumErr>0.0001) { fprintf(stderr,"Error statistics from the XML-IO LWPR model differ too much :-(\n"); exit(1); } #else printf("LWPR library has been compiled without EXPAT support, XML IO will not be tested.\n"); #endif /* Free the memory that was allocated for receptive fields etc. ** Note again that this does not free the LWPR_Model structure ** itself (but it exists on the stack, so it's automatically free'd) */ lwpr_free_model(&model); exit(0); }