Example #1
0
 static double Median(RankedBag <int> vals)
 {
     if (vals.Count == 0)
     {
         return(0D);
     }
     if (vals.Count % 2 == 1)
     {
         return((double)vals.ElementAt(vals.Count / 2));
     }
     return((vals.ElementAt(vals.Count / 2 - 1) + vals.ElementAt(vals.Count / 2)) / 2D);
 }
Example #2
0
        public void CrashRbq_ElementAtB_ArgumentOutOfRange()
        {
            var rb = new RankedBag <int>();

#if TEST_BCL
            var zz = Enumerable.ElementAt(rb, 0);
#else
            var zz = rb.ElementAt(0);
#endif
        }
Example #3
0
        public void UnitRbq_ElementAt()
        {
            var rb = new RankedBag <int> {
                Capacity = 5
            };
            int n = 200;

            for (int ii = 0; ii <= n; ++ii)
            {
                rb.Add(ii / 2);
            }

            for (int ii = 0; ii <= n; ++ii)
            {
#if TEST_BCL
                Assert.AreEqual(ii / 2, Enumerable.ElementAt(rb, ii));
#else
                Assert.AreEqual(ii / 2, rb.ElementAt(ii));
#endif
            }
        }