public void GenerateRandomTest() { IntegerRangeDistribution ird = IntegerRangeDistribution.GenerateRandom(16); Assert.AreEqual(1, ird.Lower); Assert.AreEqual(16, ird.Upper); double sum = 0.0d; for (int i = 0x01; i <= 16; i++) { sum += ird.GetPdf(i); Assert.LessOrEqual(0.0d, ird.GetPdf(i)); Assert.GreaterOrEqual(1.0d, ird.GetPdf(i)); } Assert.AreEqual(1.0d, sum, TestConstants.Tolerance); }
public void TestConstructor() { IntegerRangeDistribution ird; ird = new IntegerRangeDistribution(1, 5); Assert.AreEqual(1, ird.Lower); Assert.AreEqual(5, ird.Upper); Assert.AreEqual(0.2d, ird.GetPdf(0x01), TestConstants.Tolerance); Assert.AreEqual(0.2d, ird.GetPdf(0x02), TestConstants.Tolerance); Assert.AreEqual(0.2d, ird.GetPdf(0x03), TestConstants.Tolerance); Assert.AreEqual(0.2d, ird.GetPdf(0x04), TestConstants.Tolerance); Assert.AreEqual(0.2d, ird.GetPdf(0x05), TestConstants.Tolerance); ird = new IntegerRangeDistribution(5); Assert.AreEqual(1, ird.Lower); Assert.AreEqual(5, ird.Upper); Assert.AreEqual(0.2d, ird.GetPdf(0x01), TestConstants.Tolerance); Assert.AreEqual(0.2d, ird.GetPdf(0x02), TestConstants.Tolerance); Assert.AreEqual(0.2d, ird.GetPdf(0x03), TestConstants.Tolerance); Assert.AreEqual(0.2d, ird.GetPdf(0x04), TestConstants.Tolerance); Assert.AreEqual(0.2d, ird.GetPdf(0x05), TestConstants.Tolerance); ird = new IntegerRangeDistribution(1, 8); Assert.AreEqual(1, ird.Lower); Assert.AreEqual(8, ird.Upper); Assert.AreEqual(0.125d, ird.GetPdf(0x01), TestConstants.Tolerance); Assert.AreEqual(0.125d, ird.GetPdf(0x02), TestConstants.Tolerance); Assert.AreEqual(0.125d, ird.GetPdf(0x03), TestConstants.Tolerance); Assert.AreEqual(0.125d, ird.GetPdf(0x04), TestConstants.Tolerance); Assert.AreEqual(0.125d, ird.GetPdf(0x05), TestConstants.Tolerance); Assert.AreEqual(0.125d, ird.GetPdf(0x06), TestConstants.Tolerance); Assert.AreEqual(0.125d, ird.GetPdf(0x07), TestConstants.Tolerance); Assert.AreEqual(0.125d, ird.GetPdf(0x08), TestConstants.Tolerance); ird = new IntegerRangeDistribution(0, 7); Assert.AreEqual(0, ird.Lower); Assert.AreEqual(7, ird.Upper); Assert.AreEqual(0.125d, ird.GetPdf(0x00), TestConstants.Tolerance); Assert.AreEqual(0.125d, ird.GetPdf(0x01), TestConstants.Tolerance); Assert.AreEqual(0.125d, ird.GetPdf(0x02), TestConstants.Tolerance); Assert.AreEqual(0.125d, ird.GetPdf(0x03), TestConstants.Tolerance); Assert.AreEqual(0.125d, ird.GetPdf(0x04), TestConstants.Tolerance); Assert.AreEqual(0.125d, ird.GetPdf(0x05), TestConstants.Tolerance); Assert.AreEqual(0.125d, ird.GetPdf(0x06), TestConstants.Tolerance); Assert.AreEqual(0.125d, ird.GetPdf(0x07), TestConstants.Tolerance); }
public void TestConstructor() { IntegerRangeDistribution ird; ird = new IntegerRangeDistribution (1, 5); Assert.AreEqual (1, ird.Lower); Assert.AreEqual (5, ird.Upper); Assert.AreEqual (0.2d, ird.GetPdf (0x01), TestConstants.Tolerance); Assert.AreEqual (0.2d, ird.GetPdf (0x02), TestConstants.Tolerance); Assert.AreEqual (0.2d, ird.GetPdf (0x03), TestConstants.Tolerance); Assert.AreEqual (0.2d, ird.GetPdf (0x04), TestConstants.Tolerance); Assert.AreEqual (0.2d, ird.GetPdf (0x05), TestConstants.Tolerance); ird = new IntegerRangeDistribution (5); Assert.AreEqual (1, ird.Lower); Assert.AreEqual (5, ird.Upper); Assert.AreEqual (0.2d, ird.GetPdf (0x01), TestConstants.Tolerance); Assert.AreEqual (0.2d, ird.GetPdf (0x02), TestConstants.Tolerance); Assert.AreEqual (0.2d, ird.GetPdf (0x03), TestConstants.Tolerance); Assert.AreEqual (0.2d, ird.GetPdf (0x04), TestConstants.Tolerance); Assert.AreEqual (0.2d, ird.GetPdf (0x05), TestConstants.Tolerance); ird = new IntegerRangeDistribution (1, 8); Assert.AreEqual (1, ird.Lower); Assert.AreEqual (8, ird.Upper); Assert.AreEqual (0.125d, ird.GetPdf (0x01), TestConstants.Tolerance); Assert.AreEqual (0.125d, ird.GetPdf (0x02), TestConstants.Tolerance); Assert.AreEqual (0.125d, ird.GetPdf (0x03), TestConstants.Tolerance); Assert.AreEqual (0.125d, ird.GetPdf (0x04), TestConstants.Tolerance); Assert.AreEqual (0.125d, ird.GetPdf (0x05), TestConstants.Tolerance); Assert.AreEqual (0.125d, ird.GetPdf (0x06), TestConstants.Tolerance); Assert.AreEqual (0.125d, ird.GetPdf (0x07), TestConstants.Tolerance); Assert.AreEqual (0.125d, ird.GetPdf (0x08), TestConstants.Tolerance); ird = new IntegerRangeDistribution (0, 7); Assert.AreEqual (0, ird.Lower); Assert.AreEqual (7, ird.Upper); Assert.AreEqual (0.125d, ird.GetPdf (0x00), TestConstants.Tolerance); Assert.AreEqual (0.125d, ird.GetPdf (0x01), TestConstants.Tolerance); Assert.AreEqual (0.125d, ird.GetPdf (0x02), TestConstants.Tolerance); Assert.AreEqual (0.125d, ird.GetPdf (0x03), TestConstants.Tolerance); Assert.AreEqual (0.125d, ird.GetPdf (0x04), TestConstants.Tolerance); Assert.AreEqual (0.125d, ird.GetPdf (0x05), TestConstants.Tolerance); Assert.AreEqual (0.125d, ird.GetPdf (0x06), TestConstants.Tolerance); Assert.AreEqual (0.125d, ird.GetPdf (0x07), TestConstants.Tolerance); }
public void TestFitting() { IntegerRangeDistribution ird; ird = new IntegerRangeDistribution (1, 5); Assert.AreEqual (1, ird.Lower); Assert.AreEqual (5, ird.Upper); Assert.AreEqual (0.2d, ird.GetPdf (0x01), TestConstants.Tolerance); Assert.AreEqual (0.2d, ird.GetPdf (0x02), TestConstants.Tolerance); Assert.AreEqual (0.2d, ird.GetPdf (0x03), TestConstants.Tolerance); Assert.AreEqual (0.2d, ird.GetPdf (0x04), TestConstants.Tolerance); Assert.AreEqual (0.2d, ird.GetPdf (0x05), TestConstants.Tolerance); ird.Fit (new Tuple<int, double>[] { new Tuple<int,double> (0x03,1.0d) }); Assert.AreEqual (1, ird.Lower); Assert.AreEqual (5, ird.Upper); Assert.AreEqual (0.0d, ird.GetPdf (0x01), TestConstants.Tolerance); Assert.AreEqual (0.0d, ird.GetPdf (0x02), TestConstants.Tolerance); Assert.AreEqual (1.0d, ird.GetPdf (0x03), TestConstants.Tolerance); Assert.AreEqual (0.0d, ird.GetPdf (0x04), TestConstants.Tolerance); Assert.AreEqual (0.0d, ird.GetPdf (0x05), TestConstants.Tolerance); ird.Fit (new Tuple<int, double>[] { new Tuple<int,double> (0x02,1.0d) }, 0.25d); Assert.AreEqual (1, ird.Lower); Assert.AreEqual (5, ird.Upper); Assert.AreEqual (0.0d, ird.GetPdf (0x01), TestConstants.Tolerance); Assert.AreEqual (0.25d, ird.GetPdf (0x02), TestConstants.Tolerance); Assert.AreEqual (0.75d, ird.GetPdf (0x03), TestConstants.Tolerance); Assert.AreEqual (0.0d, ird.GetPdf (0x04), TestConstants.Tolerance); Assert.AreEqual (0.0d, ird.GetPdf (0x05), TestConstants.Tolerance); }
public void TestFitting() { IntegerRangeDistribution ird; ird = new IntegerRangeDistribution(1, 5); Assert.AreEqual(1, ird.Lower); Assert.AreEqual(5, ird.Upper); Assert.AreEqual(0.2d, ird.GetPdf(0x01), TestConstants.Tolerance); Assert.AreEqual(0.2d, ird.GetPdf(0x02), TestConstants.Tolerance); Assert.AreEqual(0.2d, ird.GetPdf(0x03), TestConstants.Tolerance); Assert.AreEqual(0.2d, ird.GetPdf(0x04), TestConstants.Tolerance); Assert.AreEqual(0.2d, ird.GetPdf(0x05), TestConstants.Tolerance); ird.Fit(new Tuple <int, double>[] { new Tuple <int, double> (0x03, 1.0d) }); Assert.AreEqual(1, ird.Lower); Assert.AreEqual(5, ird.Upper); Assert.AreEqual(0.0d, ird.GetPdf(0x01), TestConstants.Tolerance); Assert.AreEqual(0.0d, ird.GetPdf(0x02), TestConstants.Tolerance); Assert.AreEqual(1.0d, ird.GetPdf(0x03), TestConstants.Tolerance); Assert.AreEqual(0.0d, ird.GetPdf(0x04), TestConstants.Tolerance); Assert.AreEqual(0.0d, ird.GetPdf(0x05), TestConstants.Tolerance); ird.Fit(new Tuple <int, double>[] { new Tuple <int, double> (0x02, 1.0d) }, 0.25d); Assert.AreEqual(1, ird.Lower); Assert.AreEqual(5, ird.Upper); Assert.AreEqual(0.0d, ird.GetPdf(0x01), TestConstants.Tolerance); Assert.AreEqual(0.25d, ird.GetPdf(0x02), TestConstants.Tolerance); Assert.AreEqual(0.75d, ird.GetPdf(0x03), TestConstants.Tolerance); Assert.AreEqual(0.0d, ird.GetPdf(0x04), TestConstants.Tolerance); Assert.AreEqual(0.0d, ird.GetPdf(0x05), TestConstants.Tolerance); }