예제 #1
0
        public void TryToOverflowBinsTest()
        {
            BinCounter b = new BinCounter(3, -1, 1);

            b.Log(0f, 5);
            b.Log(0f, long.MaxValue);
            Assert.IsTrue(b.IsFull && b.TotalObservations == long.MaxValue && b.Bins[1] == long.MaxValue, "Individual bin overflow fail.");
            b.Reset();
            b.Log(0f, 5);
            b.Log(1f, long.MaxValue - 4);
            Assert.IsTrue(b.IsFull && b.TotalObservations == long.MaxValue, "TotalEntries overflow fail.");
        }
예제 #2
0
        public void ResetTest()
        {
            BinCounter b = new BinCounter(10, 0, 1);

            System.Random r = new System.Random();

            for (int i = 0; i < 500; i++)
            {
                b.Log((float)r.NextDouble());
            }

            // Log some outliers
            b.Log(-5);
            b.Log(10);
            b.Log(1);

            // All bins should have something in them.
            foreach (int binVal in b.Bins)
            {
                Assert.IsTrue(binVal > 0, "Failure populating bins");
            }

            b.Reset();

            // Make sure the entries counter is empty.
            Assert.IsTrue(b.TotalObservations == 0, "Expected 0 TotalEntries. Found " + b.TotalObservations);

            // Make sure all bins are empty.
            bool foundSomething = false;

            foreach (int binVal in b.Bins)
            {
                if (binVal > 0)
                {
                    foundSomething = true;
                    break;
                }
            }
            Assert.IsFalse(foundSomething, "Expected all bins to be empty. They weren't.");
            Assert.AreEqual(0, b.CountAboveRangeMax, nameof(b.CountAboveRangeMax));
            Assert.AreEqual(0, b.CountBelowRangeMin, nameof(b.CountBelowRangeMin));
            Assert.AreEqual(float.NaN, b.Mean, nameof(b.Mean));

            b.Log(1f);
            b.Log(2f);
            Assert.AreEqual(1f, b.MinObservation, nameof(b.MinObservation));
            Assert.AreEqual(2f, b.MaxObservation, nameof(b.MaxObservation));
            Assert.AreEqual(1.5f, b.Mean, nameof(b.Mean));
        }