コード例 #1
0
        public void IndexFinder_StringArray_Index()
        {
            string[] array    = new string[] { "45", "top", "dfr", "pop", "seq" };
            string   key      = "dfr";
            int      actual   = IndexFinder.BinarySearch <string>(array, key, null);
            int      expected = 2;

            Assert.AreEqual(actual, expected);
        }
コード例 #2
0
        public void IndexFinder_IntArray_Index()
        {
            int[] array    = new int[] { -9, 6, 45, 78, 495687 };
            int   key      = 78;
            int   actual   = IndexFinder.BinarySearch <int>(array, key, null);
            int   expected = 3;

            Assert.AreEqual(actual, expected);
        }
コード例 #3
0
 public void IndexFinder_UnsortedArray_ThrowArgumentException()
 {
     Assert.Throws <ArgumentException>(() => IndexFinder.BinarySearch <int>(new int[] { 5, 67, -5, 123 }, 0, null));
 }
コード例 #4
0
 public void IndexFinder_InvalidKey_ThrowArgumentException()
 {
     Assert.Throws <ArgumentException>(() => IndexFinder.BinarySearch <int>(new int[] { 5, 67, 65, 123 }, 0, null));
 }
コード例 #5
0
 public void IndexFinder_ArrayIsNull_ThrowArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => IndexFinder.BinarySearch <int>(null, 5, null));
 }
コード例 #6
0
 public void IndexFinder_EmptyArray_ThrowArgumentException()
 {
     Assert.Throws <ArgumentException>(() => IndexFinder.BinarySearch <int>(new int[] { }, 5, null));
 }