public void MaxSubArrayTest()
        {
            foreach (SearchInRotatedSortedArrayTestData testData in TestDataList)
            {
                Console.WriteLine("Test iutput: " + string.Join(",", testData.InputArray));

                Assert.AreEqual(testData.OutputInt, SearchInRotatedSortedArray.Search(testData.InputArray, testData.InputInt));
            }
        }
Example #2
0
        public void SearchInRotatedArraySuccessTest(int[] nums, int target, int expectedFoundIdx)
        {
            // arrange
            // act
            int foundIdx = SearchInRotatedSortedArray.Search(nums, target);

            // assert
            Assert.AreEqual(
                expectedFoundIdx, foundIdx,
                $"Couldn't find { target } at index { expectedFoundIdx } in array: { String.Join(" ", nums) }"
                );
        }
Example #3
0
        public void SearchTest()
        {
            int[] arr = new int[] { 4, 5, 6, 7, 0, 1, 2 };
            SearchInRotatedSortedArray l = new SearchInRotatedSortedArray();

            Assert.AreEqual(2, l.Search(arr, 6));

            Assert.AreEqual(-1, l.Search(arr, 40));

            Assert.AreEqual(6, l.Search(arr, 2));

            Assert.AreEqual(4, l.Search(arr, 0));

            Assert.AreEqual(0, l.Search(arr, 4));

            Assert.AreEqual(-1, l.Search(new int[] { }, 5));

            Assert.AreEqual(-1, l.Search(new int[] { 1 }, 0));

            Assert.AreEqual(-1, l.Search(new int[] { 1, 2 }, 0));

            Assert.AreEqual(-1, l.Search(new int[] { 1, 2, 3 }, 0));

            Assert.AreEqual(0, l.Search(new int[] { 1, 3 }, 1));

            Assert.AreEqual(1, l.Search(new int[] { 3, 1 }, 1));

            //var x = l.FindPivotInSortedArray(new int[] { 1, 3, 5 });

            //x = l.FindPivotInSortedArray(new int[] { 3, 5, 1 });

            //x = l.FindPivotInSortedArray(new int[] { 5, 1, 3 });

            //x = l.FindPivotInSortedArray(new int[] { 1, 2, 3, 4 });

            //x = l.FindPivotInSortedArray(new int[] { 2, 3, 4, 1 });

            //x = l.FindPivotInSortedArray(new int[] { 3, 4, 1, 2 });
        }
 public void Setup()
 {
     _kata = new SearchInRotatedSortedArray();
 }
Example #5
0
 public void BeforeEach()
 {
     SearchInRotatedSortedArray = new SearchInRotatedSortedArray();
 }
        public void TestSolution(int[] input1, int input2, int expectedResult)
        {
            var result = new SearchInRotatedSortedArray().Resolve(input1, input2);

            Assert.AreEqual(expectedResult, result);
        }