예제 #1
0
        public void TestIsLocalMax1()
        {
            bool localMax = CheckIfElementIsLocalMax.IsLocalMax(new int[] { 1, 5, 7, 6, 9, 90, 234, -346 }, 6);

            bool expectedAnswer = true;

            Assert.AreEqual(expectedAnswer, localMax);
        }
예제 #2
0
        public void TestIsLocalMax4()
        {
            bool localMax = CheckIfElementIsLocalMax.IsLocalMax(new int[] { 1, 5 }, 0);

            bool expectedAnswer = false;

            Assert.AreEqual(expectedAnswer, localMax);
        }
예제 #3
0
    public static int GetIndexOfFirstLocalMax <T>(T[] array) where T : IComparable <T>
    {
        if (array == null || array.Length == 0)
        {
            throw new ArgumentException("The array is null or empty.");
        }

        int n = array.Length;

        for (int i = 0; i < n; i++)
        {
            if (CheckIfElementIsLocalMax.IsLocalMax(array, i))
            {
                return(i);
            }
        }

        return(-1);
    }
예제 #4
0
        public void TestIsLocalMax6_ThrowsException()
        {
            bool localMax = CheckIfElementIsLocalMax.IsLocalMax((int[])null, 1);

            Assert.Fail();
        }
예제 #5
0
        public void TestIsLocalMax5_ThrowsException()
        {
            bool localMax = CheckIfElementIsLocalMax.IsLocalMax(new int[0], 25);

            Assert.Fail();
        }
예제 #6
0
        public void TestIsLocalMax3_ThrowsException()
        {
            bool localMax = CheckIfElementIsLocalMax.IsLocalMax(new int[] { 1, 5 }, 10);

            Assert.Fail();
        }