void Test::Run(TestResults& testResults) { try { #ifdef TRANSLATE_POSIX_SIGNALS //add any signals you want translated into system exceptions here SignalTranslator<SIGSEGV> sigSEGV; SignalTranslator<SIGFPE> sigFPE; SignalTranslator<SIGBUS> sigBUS; #endif RunImpl(testResults); } catch (std::exception const& e) { std::string msg = "Unhandled exception: "; msg += e.what(); testResults.ReportFailure(m_filename.c_str(), m_lineNumber, msg); } catch (...) { testResults.ReportFailure(m_filename.c_str(), m_lineNumber, "Unhandled exception: crash!"); } testResults.ReportDone(m_testName); }
void Test::runGetQartersTM(O_Stock& stock){ LOG_INFO << "\n --- Testing retreval of latest quarters in test mode for " << stock._ticker() << " ---\n"; // Ensure we switched to test DB bool rok(false); rok = db_setup(); if(!rok) { LOG_ERROR << "Something wrong with TEST(probably with TEST DB setup)." << "EXITING"; cout << "An error uccored. exiting"; exit(-1); } //bool repFail(true); TestResults testRes; string testName(stock._ticker() + ": "); testRes.setTestName(testName); EdgarData edgar; edgar.updateFinancials(stock); // delete added quarters from test DB T_Ep te; vector<DMMM::O_Ep> eps_copy = stock._eps(); for(auto it = eps_copy.begin(); it != eps_copy.end();++it) if (it->_quarter() < 5) te.erase( te._id() == it->_id() ); }
bool Test::updateTest(O_Stock& stock) { LOG_INFO << "\n --- Testing retreval of data for " << stock._ticker() << " ---\n"; // Ensure we switched to test DB bool rok(false); rok = db_setup(); if(!rok) { LOG_ERROR << "Something wrong with TEST(probably with TEST DB setup)." << "EXITING"; cout << "An error uccored. exiting"; exit(-1); } bool repFail(true); TestResults testRes; string testName(stock._ticker() + ": "); testRes.setTestName(testName); EdgarData edgar; edgar.updateFinancials( stock ); // test covreage (if data missing) // income // balance_ return repFail; }
void TailGasMS::DegradedComponentTest(double _mean21, double _cv21, double _mean10, double _cv10, double _muTime, TestResults& result, std::string name, bool bAddTime) { std::cout << name << std::endl; vector<double> _phi; vector<double> _time; JaggedMatrix *jm = new JaggedMatrix(3); jm->AddDistribution(2,1, _mean21, _cv21, DistributionFactory::Weibull); jm->AddDistribution(1,0, _mean10, _cv10, DistributionFactory::Weibull); jm->AddDistribution(1,2, _muTime, 1.0, DistributionFactory::Weibull); jm->Display(); SemiMarkovModel smp(jm); smp.SetModelInput(_missionTime, _NSteps); smp.RegisterHandlers(NULL, NULL); smp.SetupMatrices(); smp.ComputeStateProbabilities(); if(bAddTime) { _time = smp.GetTimeVector(); result.AddResult(_time); } _phi = smp.GetStateProbability(-1,0); result.AddResult(_phi); }
/* * Name : _mem_cache_test_impl() * Desc : Implements the memory cache performance config test * as a separate RT thread. * Args : args - Contains the test parameters. * Returns : (void *) NULL. */ void *_mem_cache_test_impl(void *args) { RTThreadArgs *threadArgs = (RTThreadArgs *) args; TestResults *tResult = threadArgs->tResult; int loop = 0, count = 0; bool done(false); int num = MCACHE_CONFIG_ARR_SIZE; struct timespec startTime, endTime; long long timeDiff; bool printFlag(false); while (!done) { for (loop = 0; loop < threadArgs->iterations; loop++) { TimeOperations::getCurTime(&startTime); ArrayOperations::doArrayOpern(num); TimeOperations::getCurTime(&endTime); timeDiff = TimeOperations::getTimeDiff(endTime, startTime); if (threadArgs->clParams.getVerboseLevel() >= 2) { cout << "mem_cache_test: Difference " "between end and start times = " << MICROSEC(timeDiff) << " us" << endl; } /* Add this to results */ tResult->setValuesAtNextIndex(timeDiff); } if (tResult->getMedian() > threadArgs -> clockAccuracy) { printFlag = true; if (tResult->checkStdDev(threadArgs->rangePct, threadArgs->acceptablePct, threadArgs->clParams.getVerboseLevel(), false)) { done = true; break; } else { if (++count == threadArgs->threshold) { done = true; break; } if (printFlag) { VerbosePrint::rtmbPrintRetryMsg(threadArgs->clParams, 1, "mcache_perf"); } } } delete tResult; tResult = new TestResults(MCACHE_CONFIG, threadArgs->iterations); threadArgs->tResult = tResult; num = num * 2; } tResult->setWorkQuantum(num); return (void *) NULL; }
string Test::runFourthQarterTest(TestResults& tResults) { LOG_INFO << "\n --- Running runFourthQarterTest() ---\n"; string testName("Test-Create fourth quarter: "); T_Stock ts; T_Ep te; O_Stock stock = ts.select( ts._ticker() == string("IBM")).front(); string filing = getMockFromDisk("IBM_2013_10k"); size_t year = 2013; EdgarData edgar; edgar.extract10kToDisk( filing, stock, year); edgar.createFourthQuarter(stock, year); //Test results writen to DB if (te.select( te._stock_id() == stock._id() && te._quarter() == 4 ).empty()) { tResults.addFailure(testName + "No record was added to DB"); O_Ep ibm2013mockyear = te.select( te._stock_id() == stock._id() && te._quarter() == 0 && te._year() == 2013).front(); te.erase( te._id() == ibm2013mockyear._id()); return tResults.getResultsSummary(); } O_Ep ibm2013 = te.select( te._stock_id() == stock._id() && te._year() == 2013 && te._quarter() == 4 ).front(); if (ibm2013._year() != 2013) tResults.addFailure(testName + "Year should be: 2013, but is: " + to_string(ibm2013._year()) ); if (ibm2013._quarter() != 4) tResults.addFailure(testName + "Quarter should be: 4, but is: " + to_string(ibm2013._quarter()) ); if (ibm2013._revenue() != "27699000000") tResults.addFailure(testName + "Revenue should be: 27699000000, but is: " + ibm2013._revenue() ); if (ibm2013._net_income() != "6184000000") tResults.addFailure(testName + "Net Income should be: 6184000000, but is: " + ibm2013._net_income() ); if ( withinPercent<double>( round(ibm2013._eps()), 0.05, 5.6) ) tResults.addFailure(testName + "(diluted) Eps should be: 5.6, but is: " + to_string(ibm2013._eps()) ); if (ibm2013._shares() != "1103042156") tResults.addFailure(testName + "Number of (diluted) shares should be: 1103042156, but is: " + ibm2013._shares() ); // test clean up te.erase( te._id() == ibm2013._id()); O_Ep ibm2013mockyear = te.select( te._stock_id() == stock._id() && te._quarter() == 0 && te._year() == 2013).front(); te.erase( te._id() == ibm2013mockyear._id()); return tResults.getResultsSummary(); }
// Custom checkers void CheckEqual(TestResults& results, const wchar_t* expected, const wchar_t* actual, TestDetails const& details) { using namespace std; if (wcscmp(expected, actual)) { UnitTest::MemoryOutStream stream; stream << "Expected '" << expected << "' but was '" << actual << "'"; results.OnTestFailure(details, stream.GetText()); } }
string Test::compareTest(const O_Stock& rStock, const O_Ep rEarnings, TestResults& tResults) { LOG_INFO << "\n --- Running compareTest() ---\n"; T_Stock ts; T_Ep te; O_Stock stock = ts.select( ts._ticker() == rStock._ticker()).front(); //Test results writen to DB if (te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).empty()) { tResults.addFailure(string("No record was added to DB")); return tResults.getResultsSummary(); } // BDX fiscal year ends in Sep, so latest annual report is for 2014 // so this quesry returns empty set. O_Ep earnings = te.select( te._stock_id() == stock._id() && te._year() == rEarnings._year() && te._quarter() == 0 ).front(); cout << "\n Comparing DB record: "<<printEarnings(rEarnings) << "\n With SEC retrival: "<<printEarnings(earnings)<<endl; if (! withinPercent( stol(earnings._revenue()), 0.02, stol(rEarnings._revenue()) ) ) tResults.addFailure("Revenue should be: "+rEarnings._revenue() +", but is: " + earnings._revenue() ); if (! withinPercent( stol(earnings._net_income()), 0.02, stol(rEarnings._net_income()) ) ) tResults.addFailure("Net Income should be: "+rEarnings._net_income() +", but is: " + earnings._net_income() ); if (! withinPercent( earnings._eps(), 0.02, rEarnings._eps() ) ) tResults.addFailure("(diluted) Eps should be: "+ to_string(rEarnings._eps() )+", but is: " + to_string(earnings._eps() ) ); long lnshares = convertNumSharesToLong( string(rEarnings._shares()) ); LOG_INFO<<"\n Converted "<<rEarnings._shares()<<" to " <<to_string(lnshares)<< "\n"; if (! withinPercent( stol(earnings._shares()), 0.02, lnshares) ) tResults.addFailure("Number of (diluted) shares should be: " + rEarnings._shares() + ", but is: " + earnings._shares() ); // test clean up te.erase( te._id() == earnings._id()); return tResults.getResultsSummary(); }
void Test::run_all() { bool rok(false); rok = db_setup(); if(!rok) { LOG_ERROR << "Something wrong with TEST(probably with TEST DB setup)." << "EXITING"; cout << "An error uccored. exiting"; exit(-1); } string resultSummary; TestResults testRes; // test single year runSingleYearTest(testRes); runSingleQarterTest(testRes); // runFourthQarterTest(testRes); resultSummary = testRes.getResultsSummary(); cout << "\n --- TEST Results ---" <<resultSummary << endl; }
void Test::Run(TestResults& testResults) const { try { #ifdef UNITTEST_POSIX UNITTEST_THROW_SIGNALS #endif RunImpl(testResults); } catch (AssertException const& e) { testResults.OnTestFailure( TestDetails(m_details.testName, m_details.suiteName, e.Filename(), e.LineNumber()), e.what()); } catch (std::exception const& e) { MemoryOutStream stream; stream << "Unhandled exception: " << e.what(); testResults.OnTestFailure(m_details, stream.GetText()); } catch (...) { testResults.OnTestFailure(m_details, "Unhandled exception: Crash!"); } }
bool processManifest(std::string manifestPath, TestResults &accumulatedResults) { fprintf(stderr, "manifest %s\n", manifestPath.c_str()); std::string base = basename(manifestPath); std::string dir = dirname(manifestPath); std::string cwd(getcwd()); chdir(dir.c_str()); std::ifstream fin(base.c_str()); YAML::Parser parser(fin); TestResults testResults; YAML::Node doc; while (parser.GetNextDocument(doc)) { for (YAML::Iterator it=doc.begin(); it!=doc.end(); ++it) { if (it->Type() == YAML::NodeType::Map) { testResults.entries++; ManifestEntry manifestEntry(*it); ManifestEntry::Result result = manifestEntry.process(); if (result == ManifestEntry::kSuccess) testResults.successes++; else if (result == ManifestEntry::kFailure) testResults.failures++; else if (result == ManifestEntry::kSkipped) testResults.skipped++; else if (result == ManifestEntry::kManifestError) testResults.manifestErrors++; } } } chdir(cwd.c_str()); fprintf(stderr, "entries: %d, successes: %d, failures: %d, skipped: %d, manifest errors: %d\n", testResults.entries, testResults.successes, testResults.failures, testResults.skipped, testResults.manifestErrors); accumulatedResults.accumulate(testResults); return 0; }
void RunnerGUI::showDetails(Q3ListViewItem *item) { if ( item == 0L ) return; QString name = fullName(item); if ( name.endsWith("()") ) name = fullName(item->parent()); Tester *tester = Runner::self()->registry().find(name.local8Bit()); if ( tester == 0L ) return; TestResults *res = 0L; if ( tester->inherits("KUnitTest::SlotTester") ) res = static_cast<SlotTester*>(tester)->results(item->text(g_nameColumn).local8Bit()); else res = tester->results(); if ( tester == 0L ) m_testerWidget->details()->setText("No test found with name: " + fullName(item)); else { Q3TextEdit *te = m_testerWidget->details(); te->clear(); te->append("<qt><a name=\"errors\"><font color=\"#990000\">Errors</font></a>:<br></qt>"); appendList(te, res->errorList()); te->append("<qt><br><hr><font color=\"#c2c939\">Expected to fail</font>:<br></qt>"); appendList(te, res->xfailList()); te->append("<qt><br><hr><font color=\"#BF00B5\">Unexpected Success</font>:<br></qt>"); appendList(te, res->xpassList()); te->append("<qt><br><hr><font color=\"#009900\">Success</font>:<br></qt>"); appendList(te, res->successList()); te->append("<qt><br><hr><font color=\"#F7A300\">Skipped</font>:<br></qt>"); appendList(te, res->skipList()); te->append("<qt><br><hr><font color=\"#000099\">Debug</font>:<br></qt>"); te->append(res->debugInfo()); te->scrollToAnchor("errors"); } }
extern "C" bool mem_cache_test(CmdLineParams &clParams, BenchMarkTestInfo &testInfo, RealTimeValues &rtValues, ResultTable &resultTable) { pthread_t tid; pthread_attr_t *attr = NULL; int new_iters = testInfo.getIterations(); bool rc(true); /* If we are running quick mode, then we should just do 1 iteration */ if (clParams.isQuickRun()) { new_iters = 1; } else { new_iters = new_iters * rtValues.getMultiplier(); } testInfo.setIterations(new_iters); list<TestResults *> *listOfResults = new list<TestResults *> (); TestResults *tResult = new TestResults(MCACHE_CONFIG, new_iters); /* Now ready the arguments to RT thread that will run the test */ RTThreadArgs thr_args(clParams, new_iters, testInfo.getThreshold(), tResult, rtValues, getClockAccuracy(resultTable)); if (clParams.isVerbose() && (clParams.getVerboseLevel() >= 1)) { cout << endl << "Test Report for mem_cache_test test:" << endl; cout << "=============================================" << endl; cout << endl << "mem_cache_test: Total number of iterations: " << new_iters << endl; } /* Create pthread attribute for the RT test thread */ attr = (pthread_attr_t *) malloc(sizeof(pthread_attr_t)); if (attr != NULL) { pthread_attr_init(attr); PthreadWrapper::setPthreadAttrSchedParam(attr, SCHED_FIFO, (PthreadWrapper::schedGetPriorityMax(SCHED_FIFO) - 10)); /* Create and start RT test thread */ if (pthread_create(&tid, NULL, _mem_cache_test_impl, (void *) &thr_args) == -1) { perror("mem_cache_test"); cerr << "ERROR: Thread creation failed in " << "mem_cache_test()" << endl; rc = false; } else { pthread_join(tid, (void **) NULL); tResult = thr_args.tResult; listOfResults->push_back(tResult); if (thr_args.ret) { if (clParams.isVerbose()) { if (clParams.getVerboseLevel() >= 1) { cout << "mem_cache_test: " << "Benchmark will be configured" << " to expect the memory cache " << " performance of this system " << " to be accurate to " << tResult->getMedian() / 1000.0 << " us." << endl; } } rc = true; } else { rc = false; } resultTable.addResult(testInfo, listOfResults, rc); } } else { cerr << "ERROR: malloc() of pthread_attr_t failed in " << "mem_cache_test()" << endl; rc = false; } if (attr != NULL) { pthread_attr_destroy(attr); free(attr); } if (!rc) { if (tResult != NULL) { delete tResult; } } return rc; }
/* Runs through each test case, pulls in the correct files, validates, and outputs the results */ int validateTestCases(const std::string &hw_id, const std::string &rcsid, int subnum, const std::string &subtime) { std::string grade_path = ".submit.grade"; std::ofstream gradefile(grade_path.c_str()); gradefile << "Grade for: " << rcsid << std::endl; gradefile << " submission#: " << subnum << std::endl; int penalty = -std::min(submission_penalty,int(std::ceil(std::max(0,subnum-max_submissions)/10.0))); assert (penalty >= -submission_penalty && penalty <= 0); if (penalty != 0) { gradefile << " penalty for excessive submissions: " << penalty << " points" << std::endl; } int nonhidden_auto_pts = penalty; int hidden_auto_pts = penalty; int nonhidden_extra_credit = 0; int hidden_extra_credit = 0; int nonhidden_possible_pts = 0; int hidden_possible_pts = 0; int possible_ta_pts = ta_pts; std::stringstream testcase_json; std::vector<std::string> all_testcases; // LOOP OVER ALL TEST CASES for (int i = 0; i < testcases.size(); ++i) { std::cout << "------------------------------------------\n" << testcases[i].title() << " - points: " << testcases[i].points() << std::endl; // START JSON FOR TEST CASE std::vector<std::string> testcase_vector; testcase_vector.push_back("\t\t\t\"test_name\": \"" + testcases[i].title() + "\""); testcase_vector.push_back("\t\t\t\"execute_logfile\": \"" + testcases[i].prefix() + "_execute_logfile.txt\""); int testcase_pts = 0; std::string message = ""; // FILE EXISTS & COMPILATION TESTS DON'T HAVE FILE COMPARISONS if (testcases[i].isFileExistsTest()) { std::cerr << "THIS IS A FILE EXISTS TEST! " << testcases[i].getFilename() << std::endl; assert (testcases[i].getFilename() != ""); if ( access( (std::string("")+testcases[i].getFilename()).c_str(), F_OK|R_OK|W_OK ) != -1 ) { /* file exists */ std::cerr << "file does exist: " << testcases[i].getFilename() << std::endl; testcase_pts = testcases[i].points(); } else { std::cerr << "ERROR file DOES NOT exist: " << testcases[i].getFilename() << std::endl; message += "Error: " + testcases[i].getFilename() + " was not found!"; } } else if (testcases[i].isCompilationTest()) { std::cerr << "THIS IS A COMPILATION! " << std::endl; if ( access( testcases[i].getFilename().c_str(), F_OK|R_OK|W_OK ) != -1 ) { /* file exists */ std::cerr << "file does exist: " << testcases[i].getFilename() << std::endl; testcase_pts = testcases[i].points(); } else { std::cerr << "ERROR file DOES NOT exist: " << testcases[i].getFilename() << std::endl; message += "Error: compilation was not successful!"; } if (testcases[i].isCompilationTest()) { testcase_vector.push_back("\t\t\t\"compilation_output\": \"" + testcases[i].prefix() + "_STDERR.txt\""); } } else { // ALL OTHER TESTS HAVE 1 OR MORE FILE COMPARISONS std::vector<std::string> diff_vectors; double pts_helper = 0.0; double fraction_sum = 0.0; for (int j = 0; j < testcases[i].numFileGraders(); j++) { std::vector<std::string> diff_vector; std::cerr << "comparison #" << j << std::endl; std::string helper_message = ""; TestResults *result = testcases[i].do_the_grading(j,helper_message); // PREPARE THE JSON DIFF FILE std::stringstream diff_path; diff_path << testcases[i].prefix() << "_" << j << "_diff.json"; std::ofstream diff_stream(diff_path.str().c_str()); if (result != NULL) { // THE GRADE (will be compiled across all comparisons) std::cout << "result->getGrade() " << result->getGrade() << std::endl; double pts_fraction = testcases[i].test_case_grader[j]->points_fraction; std::cout << "pts_fraction " << pts_fraction << std::endl; if (pts_fraction < -0.5) { pts_fraction = 1 / double(testcases[i].numFileGraders()); } fraction_sum += pts_fraction; pts_helper += pts_fraction*result->getGrade(); result->printJSON(diff_stream); helper_message += " " + result->get_message(); // CLEANUP THIS COMPARISON delete result; } // JSON FOR THIS COMPARISON diff_vector.push_back("\t\t\t\t\t\"diff_id\":\"" + testcases[i].prefix() + "_" + std::to_string(j) + "_diff\""); diff_vector.push_back("\t\t\t\t\t\"student_file\":\"" + testcases[i].filename(j) + "\""); std::string expected = ""; if (testcases[i].test_case_grader[j] != NULL) { expected = testcases[i].test_case_grader[j]->getExpected(); } if (expected != "") { std::stringstream expected_path; std::string id = hw_id; std::string expected_out_dir = "test_output/" + id + "/"; expected_path << expected_out_dir << expected; diff_vector.push_back("\t\t\t\t\t\"instructor_file\":\"" + expected_path.str() + "\""); //diff_vector.push_back("\t\t\t\t\t\"difference\":\"" + testcases[i].prefix() + "_" + std::to_string(j) + "_diff.json\",\n"); diff_vector.push_back("\t\t\t\t\t\"difference\":\"" + testcases[i].prefix() + "_" + std::to_string(j) + "_diff.json\""); } diff_vector.push_back("\t\t\t\t\t\"description\": \"" + testcases[i].description(j) + "\""); if (helper_message != "") { diff_vector.push_back("\t\t\t\t\t\"message\": \"" + helper_message + "\""); } diff_vectors.push_back("\t\t\t\t{\n" + join(diff_vector) + "\t\t\t\t}"); } // END COMPARISON LOOP testcase_vector.push_back("\t\t\t\"diffs\": [\n" + join(diff_vectors) + "\t\t\t]"); if (fraction_sum < 0.99 || fraction_sum > 1.01) { std::cout << "Fraction sum " << fraction_sum << std::endl; } assert (fraction_sum > 0.99 && fraction_sum < 1.01); assert (pts_helper >= -0.00001 && pts_helper <= 1.000001); pts_helper = std::max(0.0,std::min(1.0,pts_helper)); testcase_pts = (int)floor(pts_helper * testcases[i].points()); } // end if/else of test case type // output grade & message std::cout << "Grade: " << testcase_pts << std::endl; // TODO: LOGIC NEEDS TO BE TESTED WITH MORE COMPLEX HOMEWORK! if (!testcases[i].hidden()) { nonhidden_auto_pts += testcase_pts; if (testcases[i].extracredit()) { nonhidden_extra_credit += testcase_pts; //testcases[i].points(); } else { nonhidden_possible_pts += testcases[i].points(); } } hidden_auto_pts += testcase_pts; if (testcases[i].extracredit()) { hidden_extra_credit += testcase_pts; //testcases[i].points(); } else { hidden_possible_pts += testcases[i].points(); } testcase_vector.push_back("\t\t\t\"points_awarded\": " + std::to_string(testcase_pts)); if (message != "") { testcase_vector.push_back("\t\t\t\"message\": \"" + message + "\""); } all_testcases.push_back("\t\t{\n" + join(testcase_vector) + "\t\t}"); gradefile << " Test " << std::setw(2) << std::right << i+1 << ":" << std::setw(30) << std::left << testcases[i].just_title() << " " << std::setw(2) << std::right << testcase_pts << " / " << std::setw(2) << std::right << testcases[i].points() << std::endl; } // end test case loop int total_possible_pts = possible_ta_pts + hidden_possible_pts; std::cout << "penalty " << penalty << std::endl; std::cout << "nonhidden auto pts " << nonhidden_auto_pts << std::endl; std::cout << "hidden auto pts " << hidden_auto_pts << std::endl; std::cout << "nonhidden extra credit " << nonhidden_extra_credit << std::endl; std::cout << "hidden extra credit " << hidden_extra_credit << std::endl; std::cout << "nonhidden possible pts " << nonhidden_possible_pts << std::endl; std::cout << "hidden possible pts " << hidden_possible_pts << std::endl; std::cout << "possible ta pts " << possible_ta_pts << std::endl; std::cout << "total possible pts " << total_possible_pts << std::endl; assert (total_possible_pts == total_pts); /* Generate submission.json */ std::ofstream json_file("submission.json"); json_file << "{\n" << "\t\"submission_number\": " << subnum << ",\n" << "\t\"points_awarded\": " << hidden_auto_pts << ",\n" << "\t\"nonhidden_points_awarded\": " << nonhidden_auto_pts << ",\n" << "\t\"extra_credit_points_awarded\": " << hidden_extra_credit << ",\n" << "\t\"non_extra_credit_points_awarded\": " << hidden_auto_pts - hidden_extra_credit << ",\n" << "\t\"submission_time\": \"" << subtime << "\",\n" << "\t\"testcases\": [\n"; json_file << join(all_testcases) << "\t]\n" << "}"; json_file.close(); gradefile << "Automatic extra credit (w/o hidden): " << "+ " << nonhidden_extra_credit << " points" << std::endl; gradefile << "Automatic grading total (w/o hidden): " << nonhidden_auto_pts << " / " << nonhidden_possible_pts << std::endl; gradefile << "Max possible hidden automatic grading points: " << hidden_possible_pts - nonhidden_possible_pts << std::endl; gradefile << "Automatic extra credit: " << "+ " << hidden_extra_credit << " points" << std::endl; gradefile << "Automatic grading total: " << hidden_auto_pts << " / " << hidden_possible_pts << std::endl; gradefile << "Remaining points to be graded by TA: " << possible_ta_pts << std::endl; gradefile << "Max points for assignment (excluding extra credit):" << total_possible_pts << std::endl; return 0; }
void TestResults::add(const TestResults &result) { results_.insert(results_.end(), result.begin(), result.end()); }
void Test::runCompanyTest(string& ticker) { // get record from REAL DB for 2013 LOG_INFO << "\n --- Running Test for retreval of " << ticker << " ---\n"; cout << "\n Switching to REAL DB--------------------" << endl; string realDB("graham_dev"); string testDB("graham_test"); if ( DBFace::instance()->switchDB( realDB ) ) cout << "Switch to real db succeccful" << endl; size_t year = 2013; T_Stock rts; T_Ep rte; const O_Stock rstock = rts.select( rts._ticker() == ticker).front(); const O_Ep real2013 = rte.select( rte._stock_id() == rstock._id() && rte._quarter() == 0 && rte._year() == year).front(); cout << "\n Switching back to TEST DB--------------------" << endl; if (DBFace::instance()->switchDB( testDB ) ) cout << "Switch to TEST db succeccful" << endl; // Switch back to TEST DB // Ensure we switched to test DB bool rok(false); rok = db_setup(); if(!rok) { LOG_ERROR << "Something wrong with TEST(probably with TEST DB setup)." << "EXITING"; cout << "An error uccored. exiting"; exit(-1); } TestResults testRes; T_Stock ts; T_Ep te; O_Stock stock; // CREATE Dummy stock in test DB! if ( ts.select( ts._ticker() == ticker).empty() ) { stock._ticker() = ticker; stock._cik() = rstock._cik(); stock.insert(); }else{ stock = ts.select( ts._ticker() == ticker).front(); } string testName("Test-Company " + stock._ticker() + ": "); testRes.setTestName(testName); EdgarData edgar; if ( edgar.getSingleYear( stock, year) ) { compareTest( rstock , real2013, testRes); }else{ testRes.addFailure("Could Not get annual data for " + stock._ticker()); } string resultSummary = testRes.getResultsSummary(); cout << "\n --- TEST Results ---" <<resultSummary << endl; }
string Test::runSingleYearTest(TestResults& tResults) { LOG_INFO << "\n --- Running runSingelYearTest() ---\n"; string testName("Test-Single year 10K retrieval: "); T_Stock ts; O_Stock stock = ts.select( ts._ticker() == string("IBM")).front(); T_Ep te; tResults.setStockTickerName( stock._ticker() ); // extract to DB string filing = getMockFromDisk("IBM_2013_10k"); if ( filing == "") { tResults.addFailure(testName + "Could not load mock 10k for testing"); return tResults.getResultsSummary(); } // Hard code 2013 to be used in all stocks in test int year = 2013; EdgarData edgar; edgar.extract10kToDisk( filing, stock, year); //Test results writen to DB if (te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).empty()) { tResults.addFailure(testName + "No record was added to DB"); return tResults.getResultsSummary(); } O_Ep ibm2013 = te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).front(); if (ibm2013._year() != 2013) tResults.addFailure(testName + "Year should be: 2013, but is: " + to_string(ibm2013._year()) ); if (ibm2013._quarter() != 0) tResults.addFailure(testName + "Quarter (for 10k) should be: 0, but is: " + to_string(ibm2013._quarter()) ); if (ibm2013._revenue() != "99751000000") tResults.addFailure(testName + "Revenue should be: 99751000000, but is: " + ibm2013._revenue() ); if (ibm2013._net_income() != "16483000000") tResults.addFailure(testName + "Net Income should be: 16483000000, but is: " + ibm2013._net_income() ); if (ibm2013._eps() != 14.94) tResults.addFailure(testName + "(diluted) Eps should be: 14.94, but is: " + to_string(ibm2013._eps()) ); if (ibm2013._shares() != "1103042156") tResults.addFailure(testName + "Number of (diluted) shares should be: 1103042156, but is: " + ibm2013._shares() ); // test clean up te.erase( te._id() == ibm2013._id()); //BALANCE extraction test T_BalanceSheet tb; string balanceTestName = "BalanceTest"; O_BalanceSheet b_ibm2013 = tb.select( tb._stock_id() == stock._id() && tb._year() == year ).front(); if (b_ibm2013._year() != 2013) tResults.addFailure(balanceTestName + "Year should be: 2013, but is: " + to_string(b_ibm2013._year()) ); if (b_ibm2013._current_assets() != "51350000000") tResults.addFailure(balanceTestName + "CA should be: 51350000000, but is: " + b_ibm2013._current_assets() ); if (b_ibm2013._total_assets() != "126223000000") tResults.addFailure(balanceTestName + "TA should be: 126223000000, but is: " + b_ibm2013._total_assets() ); if (b_ibm2013._current_liabilities() != "40154000000") tResults.addFailure(balanceTestName + "CL should be: 40154000000, but is: " + b_ibm2013._current_liabilities() ); if (b_ibm2013._total_liabilities() != "103294000000") tResults.addFailure(balanceTestName + "TA should be: 103294000000, but is: " + b_ibm2013._total_liabilities() ); if (b_ibm2013._long_term_debt() != "32856000000") tResults.addFailure(balanceTestName + "LTD should be: 32856000000, but is: " + b_ibm2013._long_term_debt() ); if (stock._has_currant_ratio() != true) tResults.addFailure(balanceTestName + "Should Have current ratio. but is set to FALSE" ); // if (b_ibm2013._book_value() != "99751000000") // tResults.addFailure(balanceTestName + "Calculated Book value should be: 99751000000, but is: " // + b_ibm2013._book_value() ); // test clean up tb.erase( tb._id() == b_ibm2013._id()); // CVX stock = ts.select( ts._ticker() == string("CVX")).front(); tResults.setStockTickerName( stock._ticker() ); // extract to DB filing = getMockFromDisk("CVX_2013_10k.txt"); if ( filing == ""){ tResults.addFailure(testName + "Could not load mock 10k for testing"); return tResults.getResultsSummary(); } edgar.extract10kToDisk( filing, stock, year); //Test results writen to DB if (te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).empty()) { tResults.addFailure(testName + "No record was added to DB"); return tResults.getResultsSummary(); } O_Ep cvx2013 = te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).front(); if (cvx2013._year() != year) tResults.addFailure(testName + "Year should be: 2013, but is: " + to_string(cvx2013._year()) ); if (cvx2013._quarter() != 0) tResults.addFailure(testName + "Quarter (for 10k) should be: 0, but is: " + to_string(cvx2013._quarter()) ); if (cvx2013._revenue() != "228848000000") tResults.addFailure(testName + "Revenue should be: 228848000000, but is: " + cvx2013._revenue() ); if (cvx2013._net_income() != "21423000000") tResults.addFailure(testName + "Net Income should be: 21423000000, but is: " + cvx2013._net_income() ); if (cvx2013._eps() != 11.09) tResults.addFailure(testName + "(diluted) Eps should be: 11.09, but is: " + to_string(cvx2013._eps()) ); // if (cvx2013._shares() != "1103042156") // tResults.addFailure(testName + "Number of shares should be: 1103042156, but is: " + cvx2013._shares() ); // test clean up te.erase( te._id() == cvx2013._id()); //BALANCE extraction test O_BalanceSheet b_cvx2013 = tb.select( tb._stock_id() == stock._id() && tb._year() == year ).front(); if (b_cvx2013._year() != 2013) tResults.addFailure(balanceTestName + "Year should be: 2013, but is: " + to_string(b_cvx2013._year()) ); if (b_cvx2013._current_assets() != "50250000000") tResults.addFailure(balanceTestName + "CA should be: 50250000000, but is: " + b_cvx2013._current_assets() ); if (b_cvx2013._total_assets() != "253753000000") tResults.addFailure(balanceTestName + "TA should be: 253753000000, but is: " + b_cvx2013._total_assets() ); if (b_cvx2013._current_liabilities() != "33018000000") tResults.addFailure(balanceTestName + "CL should be: 33018000000, but is: " + b_cvx2013._current_liabilities() ); if (b_cvx2013._total_liabilities() != "103326000000") tResults.addFailure(balanceTestName + "TA should be: 103326000000, but is: " + b_cvx2013._total_liabilities() ); if (b_cvx2013._long_term_debt() != "19960000000") tResults.addFailure(balanceTestName + "LTD should be: 19960000000, but is: " + b_cvx2013._long_term_debt() ); if (stock._has_currant_ratio() != true) tResults.addFailure(balanceTestName + "Should Have current ratio. but is set to FALSE" ); // test clean up tb.erase( tb._id() == b_cvx2013._id()); // GOOG stock = ts.select( ts._ticker() == string("GOOG")).front(); tResults.setStockTickerName( stock._ticker() ); // extract to DB filing = getMockFromDisk("GOOG_2013_10k.txt"); if ( filing == ""){ tResults.addFailure(testName + "Could not load mock 10k for testing"); return tResults.getResultsSummary(); } edgar.extract10kToDisk( filing, stock, year); //Test results writen to DB if (te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).empty()) { tResults.addFailure(testName + "No record was added to DB"); return tResults.getResultsSummary(); } O_Ep goog2013 = te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).front(); if (goog2013._year() != year) tResults.addFailure(testName + "Year should be: 2013, but is: " + to_string(goog2013._year()) ); if (goog2013._quarter() != 0) tResults.addFailure(testName + "Quarter (for 10k) should be: 0, but is: " + to_string(goog2013._quarter()) ); if (goog2013._revenue() != "59825000000") tResults.addFailure(testName + "Revenue should be: 59825000000, but is: " + goog2013._revenue() ); if (goog2013._net_income() != "12920000000") tResults.addFailure(testName + "Net Income should be: 12920000000, but is: " + goog2013._net_income() ); if (goog2013._eps() != 38.13) tResults.addFailure(testName + "(diluted) Eps should be: 38.13, but is: " + to_string(goog2013._eps()) ); // if (goog2013._shares() != "1103042156") // tResults.addFailure(testName + "Number of shares should be: 1103042156, but is: " + goog2013._shares() ); // test clean up te.erase( te._id() == goog2013._id()); //BALANCE extraction test O_BalanceSheet b_goog2013 = tb.select( tb._stock_id() == stock._id() && tb._year() == year ).front(); if (b_goog2013._year() != 2013) tResults.addFailure(balanceTestName + "Year should be: 2013, but is: " + to_string(b_goog2013._year()) ); if (b_goog2013._current_assets() != "72886000000") tResults.addFailure(balanceTestName + " CA should be: 72886000000, but is: " + b_goog2013._current_assets() ); if (b_goog2013._total_assets() != "110920000000") tResults.addFailure(balanceTestName + " TA should be: 110920000000, but is: " + b_goog2013._total_assets() ); if (b_goog2013._current_liabilities() != "15908000000") tResults.addFailure(balanceTestName + " CL should be: 15908000000, but is: " + b_goog2013._current_liabilities() ); if (b_goog2013._book_value() != "87309000000") tResults.addFailure(balanceTestName + " BV should be: 87309000000, but is: " + b_goog2013._book_value() ); if (b_goog2013._total_liabilities() != "23611000000") tResults.addFailure(balanceTestName + " TL should be: 23611000000, but is: " + b_goog2013._total_liabilities() ); if (b_goog2013._long_term_debt() != "2236000000") tResults.addFailure(balanceTestName + " LTD should be: 2236000000, but is: " + b_goog2013._long_term_debt() ); if (stock._has_currant_ratio() != true) tResults.addFailure(balanceTestName + "Should Have current ratio. but is set to FALSE" ); // test clean up tb.erase( tb._id() == b_goog2013._id()); // BDX stock = ts.select( ts._ticker() == string("BDX")).front(); tResults.setStockTickerName( stock._ticker() ); // extract to DB filing = getMockFromDisk("BDX_2013_10k.txt"); if ( filing == ""){ tResults.addFailure(testName + "Could not load mock 10k for testing"); return tResults.getResultsSummary(); } edgar.extract10kToDisk( filing, stock, year); //Test results writen to DB if (te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).empty()) { tResults.addFailure(testName + "No record was added to DB"); return tResults.getResultsSummary(); } O_Ep bdx2013 = te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).front(); if (bdx2013._year() != year) tResults.addFailure(testName + "Year should be: 2013, but is: " + to_string(bdx2013._year()) ); if (bdx2013._quarter() != 0) tResults.addFailure(testName + "Quarter (for 10k) should be: 0, but is: " + to_string(bdx2013._quarter()) ); if (bdx2013._revenue() != "8054000000") tResults.addFailure(testName + "Revenue should be: 8054000000, but is: " + bdx2013._revenue() ); if (bdx2013._net_income() != "1293000000") tResults.addFailure(testName + "Net Income should be: 1293000000, but is: " + bdx2013._net_income() ); if (bdx2013._eps() != 6.49) tResults.addFailure(testName + "(diluted) Eps should be: 6.49, but is: " + to_string(bdx2013._eps()) ); if (bdx2013._shares() != "194094466") tResults.addFailure(testName + "Number of shares should be: 194094466, but is: " + bdx2013._shares() ); // test clean up te.erase( te._id() == bdx2013._id()); //BALANCE extraction test O_BalanceSheet b_bdx2013 = tb.select( tb._stock_id() == stock._id() && tb._year() == year ).front(); if (b_bdx2013._current_assets() != "5873000000") tResults.addFailure(balanceTestName + " CA should be: 5873000000, but is: " + b_bdx2013._current_assets() ); if (b_bdx2013._total_assets() != "12149000000") tResults.addFailure(balanceTestName + " TA should be: 12149000000, but is: " + b_bdx2013._total_assets() ); if (b_bdx2013._current_liabilities() != "2130000000") tResults.addFailure(balanceTestName + " CL should be: 2130000000, but is: " + b_bdx2013._current_liabilities() ); if (b_bdx2013._book_value() != "5043000000") tResults.addFailure(balanceTestName + " BV should be: 5043000000, but is: " + b_bdx2013._book_value() ); if (b_bdx2013._total_liabilities() != "7106000000") tResults.addFailure(balanceTestName + "TL should be: 7106000000, but is: " + b_bdx2013._total_liabilities() ); if (b_bdx2013._long_term_debt() != "3763000000") tResults.addFailure(balanceTestName + "LTD should be: 3763000000, but is: " + b_bdx2013._long_term_debt() ); if (stock._has_currant_ratio() != true) tResults.addFailure(balanceTestName + "Should Have current ratio. but is set to FALSE" ); // test clean up tb.erase( tb._id() == b_bdx2013._id()); // BRK.A stock = ts.select( ts._ticker() == string("BRK.A")).front(); tResults.setStockTickerName( stock._ticker() ); // extract to DB filing = getMockFromDisk("BRK_2013_10k.txt"); if ( filing == ""){ tResults.addFailure(testName + "Could not load mock 10k for testing"); return tResults.getResultsSummary(); } edgar.extract10kToDisk( filing, stock, year); //Test results writen to DB if (te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).empty()) { tResults.addFailure(testName + "No record was added to DB"); return tResults.getResultsSummary(); } O_Ep brk2013 = te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).front(); if (brk2013._year() != 2013) tResults.addFailure(testName + "Year should be: 2013, but is: " + to_string(brk2013._year()) ); if (brk2013._quarter() != 0) tResults.addFailure(testName + "Quarter (for 10k) should be: 0, but is: " + to_string(brk2013._quarter()) ); if (brk2013._revenue() != "182150000000") tResults.addFailure(testName + "Revenue should be: 182150000000, but is: " + brk2013._revenue() ); if (brk2013._net_income() != "19476000000") tResults.addFailure(testName + "Net Income should be: 19476000000, but is: " + brk2013._net_income() ); if (brk2013._eps() != 11850.0) tResults.addFailure(testName + "(diluted) Eps should be: 11850.0, but is: " + to_string(brk2013._eps()) ); // test clean up te.erase( te._id() == brk2013._id()); //BALANCE extraction test O_BalanceSheet b_brk2013 = tb.select( tb._stock_id() == stock._id() && tb._year() == year ).front(); if (b_brk2013._current_assets() != "") tResults.addFailure(balanceTestName + " CA should be: , but is: " + b_brk2013._current_assets() ); if (b_brk2013._total_assets() != "484931000000") tResults.addFailure(balanceTestName + " TA should be: 484931000000, but is: " + b_brk2013._total_assets() ); if (b_brk2013._current_liabilities() != "") tResults.addFailure(balanceTestName + " CL should be: , but is: " + b_brk2013._current_liabilities() ); if (b_brk2013._total_liabilities() != "260446000000") tResults.addFailure(balanceTestName + " TL should be: 260446000000, but is: " + b_brk2013._total_liabilities() ); // if (b_brk2013._long_term_debt() != "") // tResults.addFailure(balanceTestName + " LTD should be: , but is: " + b_brk2013._long_term_debt() ); if (b_brk2013._book_value() != "221890000000") tResults.addFailure(balanceTestName + " BV should be: 221890000000, but is: " + b_brk2013._book_value() ); if (stock._has_currant_ratio() == true) tResults.addFailure(balanceTestName + "Should NOT Have current ratio. but is set to TRUE" ); // test clean up tb.erase( tb._id() == b_brk2013._id()); // DE stock = ts.select( ts._ticker() == string("DE")).front(); tResults.setStockTickerName( stock._ticker() ); // extract to DB filing = getMockFromDisk("DE_2013_10k.txt"); if ( filing == ""){ tResults.addFailure(testName + "Could not load mock 10k for testing"); return tResults.getResultsSummary(); } edgar.extract10kToDisk( filing, stock, year); //Test results writen to DB if (te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).empty()) { tResults.addFailure(testName + "No record was added to DB"); return tResults.getResultsSummary(); } O_Ep de2013 = te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).front(); if (de2013._revenue() != "37795400000") tResults.addFailure(testName + "Revenue should be: 37795400000, but is: " + de2013._revenue() ); if (de2013._net_income() != "3537300000") tResults.addFailure(testName + "Net Income should be: 3537300000, but is: " + de2013._net_income() ); if (de2013._eps() != 9.09) tResults.addFailure(testName + "(diluted) Eps should be: 9.09, but is: " + to_string(de2013._eps()) ); if (de2013._shares() != "389200000") tResults.addFailure(testName + "Number of shares should be: 389200000, but is: " + de2013._shares() ); // test clean up te.erase( te._id() == de2013._id()); //BALANCE extraction test O_BalanceSheet b_de2013 = tb.select( tb._stock_id() == stock._id() && tb._year() == year ).front(); if (b_de2013._current_assets() != "") tResults.addFailure(balanceTestName + " CA should be: , but is: " + b_de2013._current_assets() ); if (b_de2013._total_assets() != "59521300000") tResults.addFailure(balanceTestName + " TA should be: 59521300000, but is: " + b_de2013._total_assets() ); if (b_de2013._current_liabilities() != "") tResults.addFailure(balanceTestName + " CL should be: , but is: " + b_de2013._current_liabilities() ); if (b_de2013._total_liabilities() != "49253600000") tResults.addFailure(balanceTestName + " TL should be: 49253600000, but is: " + b_de2013._total_liabilities() ); if (b_de2013._long_term_debt() != "21577700000") tResults.addFailure(balanceTestName + " LTD should be: 21577700000, but is: " + b_de2013._long_term_debt() ); if (b_de2013._book_value() != "10265800000") tResults.addFailure(balanceTestName + " BV should be: 10265800000, but is: " + b_de2013._book_value() ); if (stock._has_currant_ratio() == true) tResults.addFailure(balanceTestName + "Should NOT Have current ratio. but is set to TRUE" ); // test clean up tb.erase( tb._id() == b_de2013._id()); // INTC stock = ts.select( ts._ticker() == string("INTC")).front(); tResults.setStockTickerName( stock._ticker() ); // extract to DB filing = getMockFromDisk("INTC_2013_10k.txt"); if ( filing == ""){ tResults.addFailure(testName + "Could not load mock 10k for testing"); return tResults.getResultsSummary(); } edgar.extract10kToDisk( filing, stock, year); //Test results writen to DB if (te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).empty()) { tResults.addFailure(testName + "No record was added to DB"); return tResults.getResultsSummary(); } O_Ep intc2013 = te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).front(); if (intc2013._revenue() != "52708000000") tResults.addFailure(testName + "Revenue should be: 52708000000, but is: " + intc2013._revenue() ); if (intc2013._net_income() != "9620000000") tResults.addFailure(testName + "Net Income should be: 9620000000, but is: " + intc2013._net_income() ); if (intc2013._eps() != 1.89) tResults.addFailure(testName + "(diluted) Eps should be: 1.89, but is: " + to_string(intc2013._eps()) ); // test clean up te.erase( te._id() == intc2013._id()); //BALANCE extraction test O_BalanceSheet b_intc2013 = tb.select( tb._stock_id() == stock._id() && tb._year() == year ).front(); if (b_intc2013._current_assets() != "32084000000") tResults.addFailure(balanceTestName + " CA should be: 32084000000, but is: " + b_intc2013._current_assets() ); if (b_intc2013._total_assets() != "92358000000") tResults.addFailure(balanceTestName + " TA should be: 92358000000, but is: " + b_intc2013._total_assets() ); if (b_intc2013._current_liabilities() != "13568000000") tResults.addFailure(balanceTestName + " CL should be: 13568000000, but is: " + b_intc2013._current_liabilities() ); if (b_intc2013._total_liabilities() != "34102000000") tResults.addFailure(balanceTestName + " TL should be: 34102000000, but is: " + b_intc2013._total_liabilities() ); if (b_intc2013._calculated_tl() == false) tResults.addFailure(balanceTestName + " TL NOT suplied, so calculated_tl should be NOT be false" ); if (b_intc2013._long_term_debt() != "13165000000") tResults.addFailure(balanceTestName + " LTD should be: 13165000000, but is: " + b_intc2013._long_term_debt() ); if (b_intc2013._book_value() != "58256000000") tResults.addFailure(balanceTestName + " BV should be: 58256000000, but is: " + b_intc2013._book_value() ); // test clean up tb.erase( tb._id() == b_intc2013._id()); // F stock = ts.select( ts._ticker() == string("F")).front(); tResults.setStockTickerName( stock._ticker() ); // extract to DB filing = getMockFromDisk("F_2013_10k.txt"); if ( filing == ""){ tResults.addFailure(testName + "Could not load mock 10k for testing"); return tResults.getResultsSummary(); } edgar.extract10kToDisk( filing, stock, year); //Test results writen to DB if (te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).empty()) { tResults.addFailure(testName + "No record was added to DB"); return tResults.getResultsSummary(); } O_Ep f2013 = te.select( te._stock_id() == stock._id() && te._quarter() == 0 ).front(); if (f2013._revenue() != "146917000000") tResults.addFailure(testName + "Revenue should be: 146917000000, but is: " + f2013._revenue() ); if (f2013._net_income() != "7155000000") tResults.addFailure(testName + "Net Income should be: 7155000000, but is: " + f2013._net_income() ); if (f2013._eps() != 1.76) tResults.addFailure(testName + "(diluted) Eps should be: 1.76, but is: " + to_string(f2013._eps()) ); // test clean up te.erase( te._id() == f2013._id()); //BALANCE extraction test O_BalanceSheet b_f2013 = tb.select( tb._stock_id() == stock._id() && tb._year() == year ).front(); if (b_f2013._current_assets() != "") tResults.addFailure(balanceTestName + " CA should be: , but is: " + b_f2013._current_assets() ); if (b_f2013._total_assets() != "202026000000") tResults.addFailure(balanceTestName + " TA should be: 202026000000, but is: " + b_f2013._total_assets() ); if (b_f2013._current_liabilities() != "") tResults.addFailure(balanceTestName + " CL should be: , but is: " + b_f2013._current_liabilities() ); if (b_f2013._total_liabilities() != "175279000000") tResults.addFailure(balanceTestName + " TL should be: 175279000000, but is: " + b_f2013._total_liabilities() ); if (stock._has_currant_ratio() == true) tResults.addFailure(balanceTestName + " NO current ratios, so stock._has_currant() should be false" ); if (b_f2013._long_term_debt() != "114688000000") tResults.addFailure(balanceTestName + " LTD should be: 114688000000, but is: " + b_f2013._long_term_debt() ); if (b_f2013._book_value() != "26383000000") tResults.addFailure(balanceTestName + " BV should be: 26383000000, but is: " + b_f2013._book_value() ); // test clean up tb.erase( tb._id() == b_f2013._id()); return tResults.getResultsSummary(); }
string Test::runSingleQarterTest(TestResults& tResults) { LOG_INFO << "\n --- Running runSingleQarterTest() ---\n"; string testName("Test-Single Quarter 10Q retrieval: "); //LOG_INFO << "single quarter test under restructuring\n"; //return ""; T_Stock ts; T_Ep te; O_Stock stock = ts.select( ts._ticker() == string("CVX")).front(); tResults.setStockTickerName( stock._ticker() ); string filing = getMockFromDisk("CVX_2014_1stQ.txt"); if ( filing == "") { tResults.addFailure(testName + "Could not load mock 10q for testing"); return tResults.getResultsSummary(); } //cout << "Got filing " << filing.substr(0,300) << endl; EdgarData edgar; Acn acn( string("0000093410-14-000024"), date(2014,May,2), 1 ); acn._year = 2014; //string cover_rep_mok = ""; //string page = filing; Parser parser(stock); string cover_rep = parser.get_report_from_complete_filing(filing,ReportType::COVER); //check_report_year_and_date(cover_rep, *it); string income_rep = parser.get_report_from_complete_filing(filing,ReportType::INCOME); edgar.addIncomeStatmentToDB( income_rep, stock, acn._year, acn._quarter, cover_rep, to_iso_extended_string( acn._report_date) ); //Test results writen to DB if (te.select( te._stock_id() == stock._id() && te._year() == 2014 && te._quarter() == 1).empty()) { tResults.addFailure(testName + "No record was added to DB"); return tResults.getResultsSummary(); } O_Ep cvx2013Q1 = te.select( te._stock_id() == stock._id() && te._year() == 2014 && te._quarter() == 1).front() ; if (cvx2013Q1._year() != 2014) tResults.addFailure(testName + "Year should be: 2014, but is: " + to_string(cvx2013Q1._year()) ); if (cvx2013Q1._quarter() != 1) tResults.addFailure(testName + "Quarter should be: 1, but is: " + to_string(cvx2013Q1._quarter()) ); if (cvx2013Q1._revenue() != "53265000000") tResults.addFailure(testName + "Revenue should be: 53265000000, but is: " + cvx2013Q1._revenue() ); if (cvx2013Q1._net_income() != "4512000000") tResults.addFailure(testName + "Net Income should be: 4512000000, but is: " + cvx2013Q1._net_income() ); if (cvx2013Q1._eps() != 2.36) tResults.addFailure(testName + "(diluted) Eps should be: 2.36, but is: " + to_string(cvx2013Q1._eps()) ); if (cvx2013Q1._shares() != "1909424000") tResults.addFailure(testName + "Number of (diluted) shares should be: 1909424000, but is: " + cvx2013Q1._shares() ); // erase record from DB te.erase( te._id() == cvx2013Q1._id()); return tResults.getResultsSummary(); }
bool Test::getReportsTest(O_Stock& stock, boost::filesystem::ofstream& outFile) { LOG_INFO << "\n --- Testing retreval of reports for " << stock._ticker() << " ---\n"; // Ensure we switched to test DB bool rok(false); rok = db_setup(); if(!rok) { LOG_ERROR << "Something wrong with TEST(probably with TEST DB setup)." << "EXITING"; cout << "An error uccored. exiting"; exit(-1); } bool repFail(true); TestResults testRes; string testName(stock._ticker() + ": "); testRes.setTestName(testName); EdgarData edgar; /* Acn* acn = edgar.getLastYear10KAcn(stock); if (acn == NULL) { LOG_INFO << "Did not get acn for "<<stock._ticker() ; return false; } string filing = edgar.getEdgarFiling(stock,*acn); if (filing == "") { LOG_ERROR << "Failed to retrive filing for acn "<<acn->_acn<<"\n"; return false; } */ edgar.getSingleYear(stock,2013); auto reports = &edgar._reports; bool foreign = false; LOG_INFO << "Got "<<reports->size()<<" reports\n"; ReportType reportType = ReportType::COVER; auto coverReportIt = reports->find(reportType); if( coverReportIt == reports->end()) { testRes.addFailure("NO COVER REPORT"); repFail =false; } reportType = ReportType::INCOME; auto incomeReportIt = reports->find(reportType); if( incomeReportIt == reports->end()) { testRes.addFailure("NO INCOME REPORT"); if ( (stock._country() != "") && (stock._country() != "USA") ) foreign = true; repFail =false; } else { T_Ep te; O_Ep earnings_data; bool inDB(true); if (te.select( te._stock_id() == stock._id() && te._year() == 2013).empty() ) { inDB = false; testRes.addFailure("No earnings record for 2013 retrieved from DB"); earnings_data = edgar._ep; } else earnings_data = te.select( te._stock_id() == stock._id() && te._year() == 2013).front(); LOG_INFO << "\n Testing values extracted for eps record with id: " << to_string(earnings_data._id())<<", stock_id is: "<< to_string(earnings_data._stock_id())<<" year "<< to_string(earnings_data._year()) <<", revenue: " <<earnings_data._revenue() << ", income: " <<earnings_data._net_income()<<", and eps: "<< to_string(earnings_data._eps())<<"\n"; if (earnings_data._revenue() == "") testRes.addFailure("No Revenue exracted from Income Statement"); if (earnings_data._net_income() == "") testRes.addFailure("No Income exracted from Income Statement"); if (withinPercent(earnings_data._eps(),0.01,0.0)) testRes.addFailure("No Eps exracted from Income Statement"); if (earnings_data._shares() == "") testRes.addFailure("No Share data exracted from Income Statement"); if (inDB) te.erase( te._id() == earnings_data._id()); } // balancereporttest: reportType = ReportType::BALANCE; auto balanceReportIt = reports->find(reportType); if( balanceReportIt == reports->end()) { testRes.addFailure("NO BALANCE REPORT"); repFail =false; } string resultSummary = testRes.getResultsSummary(); if (testRes._numFails > 0) { if (foreign) outFile << stock._ticker() << " is foreign - " << stock._country(); outFile << resultSummary; outFile.flush(); } LOG_INFO << resultSummary; cout << "\n --- TEST Results for "<<stock._ticker()<<" ---" <<resultSummary << endl; return repFail; }