Test::Test(const char* n, const char* f, unsigned int l) { name = n; file = f; line = l; get_tests().push_back(this); }
int run() { std::vector<impl::Test*>& tests = get_tests(); unsigned int failed = 0; for (unsigned int i = 0; i < tests.size(); i++) { try { std::cerr << tests[i]->name << std::endl; tests[i]->run(); } catch (impl::Failure& failure) { std::cerr << failure.file << "(" << failure.line << "): error: " << failure.msg << std::endl; failed++; } catch (std::exception& ex) { std::cerr << tests[i]->file << "(" << tests[i]->line << "): error: " << ex.what() << std::endl; failed++; } catch (...) { std::cerr << tests[i]->file << "(" << tests[i]->line << "): error: Test " << tests[i]->name << " crashed." << std::endl; failed++; } } unsigned int succeded = tests.size() - failed; std::cerr << succeded << " of " << tests.size() << " tests succeded." << std::endl; return failed == 0 ? 0 : -1; }
void do_feature_selection(){ struct url_test *t; struct feature *f; struct feature *top=NULL; struct feature_selection *fs=NULL; struct feature_selection *fs_node; int i=0; double current_highest=0; double highest=0; double gain=0; struct test_score score; for(t=get_tests();t!=NULL;t=t->hh.next){ fs=NULL; score.score=(double) t->success/(double) t->count; score.test=t; current_highest=9000; /* if there are less than 100 successes for this test, * we probably don't know enough to make an informed decision. * Roll with the total probability */ if(t->success<100){ t->feature_selections=NULL; goto skip_feature_selection; } for(i=0;i<9;i++){ highest=0; for(f=get_features();f!=NULL;f=f->hh.next){ if(!f->ftr_loaded){ load_ftr_by_feature_id(f->id); f->ftr_loaded=1; } gain=expected_change(&score,f); if(gain>highest && gain<current_highest){ highest=gain; top=f; } } current_highest=highest; fs_node=malloc(sizeof(struct feature_selection)); fs_node->feature=top; fs_node->next=fs; fs=fs_node; } skip_feature_selection: printf("features for %s :",t->url); for(fs_node=fs;fs_node!=NULL;fs_node=fs_node->next){ if(fs_node->feature==NULL) continue; printf(" %s", fs_node->feature->label); } t->feature_selections=fs; update_feature_selection(t); printf("\n"); } }
int main(int argc, char *argv[]) { #ifdef HAVE_MPI std::cerr << "The serial unittest launcher is not capable of running MPI tests." << std::endl << "If you are seeing this error, then CMake isn't behaving as expected!" << std::endl << "END RESULT: SOME TESTS FAILED" << std::endl; return 1; #endif int failed = 0; if (argc < 2) { std::cerr << "Specify unit test input file on the command line." << std::endl; return 1; } std::vector<std::string> names; try { names = get_tests(argv[1]); } catch (std::string &ex) { std::cerr << ex << std::endl; std::cerr << "END RESULT: SOME TESTS FAILED" << std::endl; return 1; } int cnt = names.size(); failed = run_all_unittests(names); std::cout << (cnt-failed) << " tests passed out of " << cnt << std::endl; if (failed > 0) { std::cerr << "END RESULT: SOME TESTS FAILED" << std::endl; } else { std::cout << "END RESULT: ALL TESTS PASSED" << std::endl; } return (failed == 0 ? 0 : 1); }