Esempio n. 1
0
        public void Test1()
        {
            //Random rng = new Random();

            EmpiricalDistribution <int> listDist = new EmpiricalDistribution <int>();

            listDist.CreateDistribution(Data);
            Dictionary <int, int> testCounts = new Dictionary <int, int>();

            foreach (int i in Data)
            {
                if (!testCounts.ContainsKey(i))
                {
                    testCounts.Add(i, 0);
                }
                testCounts[i]++;
            }

            Assert.IsTrue(TestDistribution(listDist, testCounts));
        }
Esempio n. 2
0
        public void TestCreateFromCalls()
        {
            Dictionary <int, int> trueCounts = new Dictionary <int, int>();
            List <FakeCall>       callData   = new List <FakeCall>();

            foreach (int i in Data)
            {
                if (!trueCounts.ContainsKey(i))
                {
                    trueCounts.Add(i, 0);
                }
                trueCounts[i]++;
                callData.Add(new FakeCall(i));
            }
            EmpiricalDistribution <int> testDist = new EmpiricalDistribution <int>();

            testDist.CreateDistribution(new List <object>(callData), x =>
            {
                var fCall = x as FakeCall;
                return(fCall.code);
            });
            Assert.IsTrue(TestDistribution(testDist, trueCounts));
        }
Esempio n. 3
0
        public void TestSample()
        {
            Dictionary <int, int> fakeData = new Dictionary <int, int>();

            fakeData.Add(1, 2); //20%
            fakeData.Add(2, 4); //40%
            fakeData.Add(3, 3); //30%
            fakeData.Add(4, 1); //10%

            EmpiricalDistribution <int> toSample = new EmpiricalDistribution <int>();

            toSample.CreateDistribution(fakeData);
            //dist should look like: (.1, 4), (.3, 1), (.6, 3), (1, 2)

            int shouldBeFour = toSample.GetValue(.05);

            Assert.AreEqual(shouldBeFour, 4);
            shouldBeFour = toSample.GetValue(.1);
            Assert.AreEqual(shouldBeFour, 4);

            int shouldBeOne = toSample.GetValue(.11);

            Assert.AreEqual(shouldBeOne, 1);
            shouldBeOne = toSample.GetValue(.3);
            Assert.AreEqual(shouldBeOne, 1);

            int shouldBeThree = toSample.GetValue(.304);

            Assert.AreEqual(shouldBeThree, 3);

            int shouldBeTwo = toSample.GetValue(.7);

            Assert.AreEqual(shouldBeTwo, 2);

            shouldBeTwo = toSample.GetValue(1);
            Assert.AreEqual(shouldBeTwo, 2);
        }