示例#1
0
 public void LowerBoundBinary_Seq()
 {
     for (int i = 1; i < 1000; i++)
     {
         var keys = GenerateKeys(i);
         for (int k = 0; k < keys.Length; k++)
         {
             Assert.AreEqual(SearchHelpers.LowerBoundLinear(keys, keys.Length, keys[k]), SearchHelpers.LowerBoundBinary(keys, keys.Length, keys[k]));
         }
     }
 }
示例#2
0
 public void LowerBoundBinary_Random()
 {
     for (int i = 1; i < 1000; i++)
     {
         var keys = GetSortedRandomKeys(i);
         for (int k = 0; k < keys.Length; k++)
         {
             Assert.AreEqual(SearchHelpers.LowerBoundLinear(keys, keys.Length, keys[k]), SearchHelpers.LowerBoundBinary(keys, keys.Length, keys[k]));
             Assert.AreEqual(SearchHelpers.LowerBoundLinear(keys, keys.Length, keys[k] + 1), SearchHelpers.LowerBoundBinary(keys, keys.Length, keys[k] + 1));
             Assert.AreEqual(SearchHelpers.LowerBoundLinear(keys, keys.Length, keys[k] - 1), SearchHelpers.LowerBoundBinary(keys, keys.Length, keys[k] - 1));
         }
     }
 }
示例#3
0
        public void LowerBoundLinear_ArrayLengthIsOne()
        {
            var keys = new long[] { 1 };

            int index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 0);

            Assert.AreEqual(0, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 1);
            Assert.AreEqual(0, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 2);
            Assert.AreEqual(-1, index);
        }
示例#4
0
        public void LowerBoundLinear_ContainsDuplicates()
        {
            var keys  = new long[] { 1, 2, 3, 3 };
            int index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 0);

            Assert.AreEqual(0, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 1);
            Assert.AreEqual(0, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 2);
            Assert.AreEqual(1, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 3);
            Assert.AreEqual(2, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 4);
            Assert.AreEqual(-1, index);
        }
示例#5
0
        public void LowerBoundLinear_ContainsDuplicates2()
        {
            var keys = new long[] { 1, 3, 3, 5, 7, 7, 9 };

            int index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 0);

            Assert.AreEqual(0, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 1);
            Assert.AreEqual(0, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 2);
            Assert.AreEqual(1, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 3);
            Assert.AreEqual(1, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 4);
            Assert.AreEqual(3, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 5);
            Assert.AreEqual(3, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 6);
            Assert.AreEqual(4, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 7);
            Assert.AreEqual(4, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 8);
            Assert.AreEqual(6, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 9);
            Assert.AreEqual(6, index);

            index = SearchHelpers.LowerBoundLinear(keys, keys.Length, 10);
            Assert.AreEqual(-1, index);
        }