public void TestThreePSelecter() { double tolarance = .5; int iFrequency = 5; int aveKpi = 20; int freq = 500; int popSize = 10_000; int numSamples = popSize / freq; //int numIsamples = (iFrequency > 0) ? numSamples / iFrequency : 0; // same as other implementation but less consistant with how i test other methods int numIsamples = (iFrequency > 0) ? popSize / (iFrequency * freq) : 0; int popVol = aveKpi * popSize; int kz = popVol / numSamples; var selecter = new ThreePSelecter(kz, iFrequency); int sampleCounter = 0; int iSampleCounter = 0; for (int i = 0; i < popSize; i++) { var result = selecter.Sample(aveKpi); if (result == SampleResult.M) { sampleCounter++; } else if (result == SampleResult.I) { iSampleCounter++; } } // taking the double sided binomial probability with the number of samples recieved against our frequency // will tell us the liklyhood of recieving the number of samples we recieved // check that probability against our tolarance var likelihood_twoSided = 2 * BinomialProbability(popSize, sampleCounter, 1 / (double)freq); likelihood_twoSided.Should().BeLessThan(tolarance); if (iFrequency > 1) { // because insurance trees should be generated for x number of // regular samples. We should know exactly how many insurance samples // to expect give or take one var actualExpectediSamples = sampleCounter / (double)(iFrequency); var iSampleDiff = Math.Abs(iSampleCounter - numIsamples); iSampleDiff.Should().BeLessOrEqualTo(1); } }
public SampleResult Sample(int kpi, out int rand) { return(ThreePSelecter.Sample(kpi, out rand)); }