Beispiel #1
0
        public void TestUpperAndLowerBound()
        {
            BList <int> blist = NewList();

            blist.AddRange(new int[] { 0, 0, 10, 10, 20, 20, 25, 30, 30, 40, 40, 50, 50 });

            int item = 25;

            Assert.AreEqual(blist.FindUpperBound(item), 1 + blist.FindLowerBound(item));

            item = 10;
            Assert.That(blist.FindUpperBound(ref item) == 4 && item == 20);
            item = 0;
            Assert.That(blist.FindUpperBound(ref item) == 2 && item == 10);
            item = 999;
            Assert.That(blist.FindUpperBound(ref item) == blist.Count && item == 999);

            bool found;

            item = 5;
            Assert.That(blist.FindLowerBound(ref item, out found) == 2 && item == 10 && !found);
            item = 20;
            Assert.That(blist.FindLowerBound(ref item, out found) == 4 && item == 20 && found);
            item = 0;
            Assert.That(blist.FindLowerBound(ref item, out found) == 0 && item == 0 && found);
            item = 999;
            Assert.That(blist.FindLowerBound(ref item, out found) == blist.Count && item == 999 && !found);
        }