public void GetHistogramAllEqualBinsTest() { BinCounter b = new BinCounter(10, -1, 1); for (int i = 0; i < b.NumBins; i++) { // log one in each bin b.Log(b.RangeMin + (b.BinSize / 2) + i * b.BinSize); } string s = b.GetHistogram(); Assert.IsTrue(s.IndexOf("TotalEntries: 10") > -1); Assert.IsTrue(s.IndexOf("CountBelowRangeMin: 0") > -1); Assert.IsTrue(s.IndexOf("CountAboveRangeMax: 0") > -1); Assert.IsTrue(s.IndexOf("MedianBinIdx: 4") > -1); // All of the bins should be the same max size of 100 string hundredStars = new string('*', 100); string[] splitOn = new string[1]; splitOn[0] = hundredStars; int count = s.Split(splitOn, System.StringSplitOptions.None).Length - 1; Assert.IsTrue(count == b.NumBins, "Not all bins were the expected size." + count + "\nOutput was:\n" + s); }
static void Main(string[] args) { BinCounter b = new BinCounter(30, 0, 2); // Log a bunch of distributed data Random r = new Random(); for (int i = 0; i < 10000; i++) { float dir = r.NextDouble() < .5 ? -1 : 1; float dist = (float)Math.Pow(r.NextDouble(), 2); b.Log(1 + dir * dist); } // Log a few outliers b.Log(5f); b.Log(-3f); Console.WriteLine("TotalEntries: " + b.TotalObservations); Console.WriteLine("Mean: " + b.Mean); Console.WriteLine("A particular bin count: " + b.Bins[4]); Console.WriteLine("\nFull histogram plus info:\n------" + b.GetHistogram()); }