@@ -494,6 +494,54 @@ void CPoissonMeanConjugateTest::testSampleMarginalLikelihood() {
494494 }
495495}
496496
497+ void CPoissonMeanConjugateTest::testSampleMarginalLikelihoodInSupportBounds () {
498+ // Here we test that the retrieved samples are
499+ // a) positive
500+ // b) monotonically increasing
501+ // c) No ERROR log messages are generated
502+ // The input sample and weight are chosen to be ones that generate
503+ // an initial sample that is less than an offset value of 0.0
504+
505+ const char * logFile = " test.log" ;
506+
507+ std::remove (logFile);
508+ // log at level ERROR only
509+ CPPUNIT_ASSERT (ml::core::CLogger::instance ().reconfigureFromFile (
510+ " testfiles/testLogErrorsLog4cxx.properties" ));
511+
512+ CPoissonMeanConjugate filter (CPoissonMeanConjugate::nonInformativePrior ());
513+
514+ TDouble1Vec sampleVec (1 , 283.3232 );
515+ maths_t ::TDoubleWeightsAry1Vec weightVec (1 , maths_t::countWeight (0.0206505 ));
516+
517+ filter.addSamples (sampleVec, weightVec);
518+
519+ std::size_t numberSampled = 50u ;
520+ TDouble1Vec sampled;
521+
522+ filter.sampleMarginalLikelihood (numberSampled, sampled);
523+
524+ double prevSample{0.0 };
525+ for (double sample : sampled) {
526+ CPPUNIT_ASSERT (sample > prevSample);
527+ CPPUNIT_ASSERT (sample >= 0.0 );
528+ prevSample = sample;
529+ }
530+
531+ // Revert to the default properties for the test framework - very similar to the hardcoded default.
532+ CPPUNIT_ASSERT (ml::core::CLogger::instance ().reconfigureFromFile (" testfiles/log4cxx.properties" ));
533+
534+ std::ifstream log (logFile);
535+ CPPUNIT_ASSERT (log.is_open ());
536+ char line[256 ];
537+ while (log.getline (line, 256 )) {
538+ LOG_INFO (<< " Got '" << line << " '" );
539+ CPPUNIT_ASSERT (false );
540+ }
541+ log.close ();
542+ std::remove (logFile);
543+ }
544+
497545void CPoissonMeanConjugateTest::testCdf () {
498546 // Test error cases.
499547 //
@@ -960,6 +1008,9 @@ CppUnit::Test* CPoissonMeanConjugateTest::suite() {
9601008 &CPoissonMeanConjugateTest::testSampleMarginalLikelihood));
9611009 suiteOfTests->addTest (new CppUnit::TestCaller<CPoissonMeanConjugateTest>(
9621010 " CPoissonMeanConjugateTest::testCdf" , &CPoissonMeanConjugateTest::testCdf));
1011+ suiteOfTests->addTest (new CppUnit::TestCaller<CPoissonMeanConjugateTest>(
1012+ " CPoissonMeanConjugateTest::testSampleMarginalLikelihoodInSupportBounds" ,
1013+ &CPoissonMeanConjugateTest::testSampleMarginalLikelihoodInSupportBounds));
9631014 suiteOfTests->addTest (new CppUnit::TestCaller<CPoissonMeanConjugateTest>(
9641015 " CPoissonMeanConjugateTest::testProbabilityOfLessLikelySamples" ,
9651016 &CPoissonMeanConjugateTest::testProbabilityOfLessLikelySamples));
0 commit comments