Esempio n. 1
0
        public void TallyStandardTest()
        {
            var count = new CountTree()
            {
                TreeCount = 0
            };

            FMSC.Sampling.IFrequencyBasedSelecter sampleSelector = new FMSC.Sampling.SystematicSelecter(1, 0, true);//100%

            var expectedTree = new Tree();

            var dataServiceMock = new Moq.Mock <ITreeDataService>();

            dataServiceMock.Setup(ds => ds.CreateNewTreeEntry(It.IsAny <CountTree>())).Returns(expectedTree);

            var dialogServiceMock = new Mock <IDialogService>();
            //dialogServiceMock.Setup()

            var result = FormDataEntryLogic.TallyStandard(count, sampleSelector, dataServiceMock.Object, dialogServiceMock.Object);

            result.Should().NotBeNull();
            result.TreeRecord.Should().BeSameAs(expectedTree);
            result.Count.Should().BeSameAs(count);
            result.TreeCount.Should().Be(1);
            result.KPI.Should().Be(0);

            expectedTree.CountOrMeasure.Should().Be("M");

            sampleSelector = new ZeroPCTSelector();//0%

            sampleSelector.Sample().Should().Be(SampleResult.C);

            result = FormDataEntryLogic.TallyStandard(count, sampleSelector, dataServiceMock.Object, dialogServiceMock.Object);
            result.TreeRecord.Should().BeNull();
            result.TreeCount.Should().Be(1);
            result.KPI.Should().Be(0);
        }
 private SampleSelecter MakeSystematicSampleSelector()
 {
     SampleSelecter selecter = null;
     int iFrequency = (int)this.InsuranceFrequency;
     int frequency = (int)this.SamplingFrequency;
     if (frequency == 0) { selecter = null; }
     else
     {
         selecter = new FMSC.Sampling.SystematicSelecter(frequency, iFrequency, true);
     }
     return selecter;
 }
        public void TestSystmaticSelecter()
        {
            decimal tolarance = .01m;
            int freqency = 15;
            int iFrequency = 0;
            SystematicSelecter selecter = new SystematicSelecter(freqency, iFrequency, true);

            int numSamples = freqency * 10000;
            int[] results = new int[numSamples];
            int totalSamples = 0;
            int totalISamples = 0;
            
            for (int i = 0; i < numSamples; i++)
            {
                SampleItem item = selecter.NextItem();
                
                if (item != null && item.IsInsuranceItem)
                {
                    results[i] = 2;
                    totalISamples++;
                }
                else if(item != null && item.IsSelected)
                {
                    results[i] = 1;
                    totalSamples++;
                }
                else
                {
                    results[i] = 0;
                }
            }

            Assert.IsTrue(selecter.ITreeFrequency == iFrequency);

            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)totalSamples);
            this.TestContext.WriteLine("Observed freq = {0}", observedFreq.ToString());
            this.TestContext.WriteLine("Observed iFreq = {0}", observediFreq.ToString());


            decimal dFreq = Math.Abs((1 / (decimal)freqency) - observedFreq);


            this.TestContext.WriteLine("delta freq  = {0}", dFreq.ToString());



            bool freqInTolarance = Math.Abs((1 / (decimal)freqency) - observedFreq) <= tolarance;

            Assert.IsTrue(freqInTolarance);


            if (iFrequency > 0)
            {
                decimal dIFreq = Math.Abs((1 / (decimal)iFrequency) - observediFreq);
                this.TestContext.WriteLine("delta iFreq = {0}", dIFreq.ToString());
                bool ifreqInTolarance = Math.Abs((1 / (decimal)iFrequency) - observediFreq) <= tolarance;
                Assert.IsTrue(ifreqInTolarance);
            }
        }