Example #1
0
        public void UnitRb_ElementsBetween()
        {
            var rb0 = new RankedBag <int>();
            var rb1 = new RankedBag <int> {
                Capacity = 4
            };
            var rb2 = new RankedBag <int> (new int[] { 5, 5, 5, 5, 5 });

            foreach (var k1 in new int[] { 3, 4, 5, 5, 6, 6, 7, 7, 8 })
            {
                rb1.Add(k1);
            }

            var d0 = new System.Collections.Generic.List <int> (rb0.ElementsBetween(2, 4));

            Assert.AreEqual(0, d0.Count);

            var d1 = new System.Collections.Generic.List <int> (rb1.ElementsBetween(5, 6));

            Assert.AreEqual(4, d1.Count);

            var d2 = new System.Collections.Generic.List <int> (rb1.ElementsBetween(5, 5));

            Assert.AreEqual(2, d2.Count);

            var d3 = new System.Collections.Generic.List <int> (rb2.ElementsBetween(5, 5));

            Assert.AreEqual(5, d3.Count);

            var d4 = new System.Collections.Generic.List <int> (rb2.ElementsBetween(1, 2));

            Assert.AreEqual(0, d4.Count);

            var d5 = new System.Collections.Generic.List <int> (rb2.ElementsBetween(9, 11));

            Assert.AreEqual(0, d5.Count);
        }
Example #2
0
        static void Main()
        {
            var scores = new RankedBag <int> {
                2, 5, 4, 4, 5, 4, 7, 9
            };

            var mean   = Mean(scores);
            var stddev = StandardDeviation(scores);

            Console.WriteLine($"Count = {scores.Count}, median = {Median (scores)}, mean = {Mean (scores)}");
            Console.WriteLine($"Variance = {Variance (scores)}");
            Console.WriteLine($"Standard deviation = {StandardDeviation (scores)}");

            Console.WriteLine($"\nLow score: {scores.Min}");
            Console.WriteLine($"High score: {scores.Max}");

            Console.Write("Scores within 1 standard deviation:");
            foreach (var score in scores.ElementsBetween((int)(mean - stddev + 0.5), (int)(mean + stddev + 0.5)))
            {
                Console.Write($" {score}");
            }
            Console.WriteLine();
        }