public void TestBlockSelecter(int freqency, int iFrequency) { BlockSelecter selecter = new BlockSelecter(freqency, iFrequency); var sResult = selecter.Sample(); sResult.Should().NotBeNull(); selecter.BlockState.Should().NotBeEmpty(); }
protected void ValidateBlockSelecter(BlockSelecter selecter, int freq, int iFreq, int numSamples, int blockMarginOfError = BLOCK_SAMPLING_MARGIN_OF_ERROR) { int[] results = new int[numSamples]; int totalSamples = 0; int totalISamples = 0; for (int i = 0; i < numSamples; i++) { var result = selecter.Sample(); if (result == SampleResult.M) { results[i] = 1; totalSamples++; } else if (result == SampleResult.I) { results[i] = 2; totalISamples++; } else { results[i] = 0; } } selecter.ITreeFrequency.ShouldBeEquivalentTo(iFreq); //this.TestContext.WriteLine(" numsamples = {0}", numSamples.ToString()); //this.TestContext.WriteLine("total samples = {0}", totalSamples.ToString()); //this.TestContext.WriteLine("total Isamples = {0}", totalISamples.ToString()); decimal observedFreq = (totalSamples / (decimal)numSamples); decimal observediFreq = (totalISamples / (decimal)numSamples); var expectedSamples = numSamples / freq; // if we are sampleing insurance trees then some regualr samples will get converted // into insurance samples, so we need to ajust expected samples to account for insuance trees var expectedITrees = (iFreq > 0) ? numSamples / (iFreq * freq) : 0; Math.Abs(expectedSamples - totalSamples) .Should().BeLessOrEqualTo(blockMarginOfError, $"expected samples:{expectedSamples} actual samples {totalSamples}"); // difference between actual samples and expected should be less than 1, allowing for rounding errors if (iFreq > 0) { var iSampleMarginOfError = Math.Max(blockMarginOfError / iFreq, 1); Math.Abs(expectedITrees - totalISamples) .Should().BeLessOrEqualTo(iSampleMarginOfError, $"expected i samples:{expectedITrees} actual i samples:{totalISamples}"); } }
public void BlockSelecter_Rehidrate_AfterSample(int freqency, int iFrequency) { BlockSelecter selecter = new BlockSelecter(freqency, iFrequency); selecter.Sample(); var selecterAgian = new BlockSelecter(selecter.Frequency, selecter.ITreeFrequency, selecter.BlockState, selecter.Count, selecter.InsuranceIndex, selecter.InsuranceCounter); }
public SampleResult Sample() { return(BlockSelecter.Sample()); }