Beispiel #1
0
        public void BinValsTest()
        {
            Histogram rTest1 = new Histogram(20, 1);

            //Add some fake values into the mix
            for (int i = 0; i < 20; i++)
            {
                rTest1.AddBinVal((double)i - 9.9);
            }

            // Now test the values
            for (int i = 0; i < 20; i++)
            {
                Assert.AreEqual(rTest1.BinCount(i), 1);
            }

            // The special case
            Histogram rTest2 = new Histogram(1, decimal.MaxValue);

            //Add some fake values into the mix
            rTest2.AddBinVal(-1);
            rTest2.AddBinVal(1);
            rTest2.AddBinVal(1000);

            Assert.AreEqual(rTest2.BinCount(0), 1);
            Assert.AreEqual(rTest2.BinCount(1), 2);
        }
Beispiel #2
0
        public void BinValsTest2()
        {
            Histogram rTest1 = new Histogram(4, 1);

            // Let's get our integers out of the way
            rTest1.AddBinVal(-2);
            Assert.AreEqual(rTest1.BinCount(0), 1);
            rTest1.AddBinVal(-1);
            Assert.AreEqual(rTest1.BinCount(1), 1);
            rTest1.AddBinVal(0);
            Assert.AreEqual(rTest1.BinCount(2), 1);
            rTest1.AddBinVal(1);
            Assert.AreEqual(rTest1.BinCount(3), 1);
            // Make sure the last value falls backward
            rTest1.AddBinVal(2);
            Assert.AreEqual(rTest1.BinCount(3), 2);

            // Now make sure everything that is supposed to fail does.
            List <double> badVals = new List <double>()
            {
                3, -2.0000001, 2.0000011
            };

            foreach (double val in badVals)
            {
                try
                {
                    rTest1.AddBinVal(val);
                    Assert.Fail();
                }
                catch (Exception e)
                {
                    Assert.IsInstanceOfType(e, typeof(ArgumentOutOfRangeException));
                }
            }
        }