public void ValidatedRotatedtArray(int[] nums, int target, int expected)
        {
            var sol    = new RotatedArray();
            var actual = sol.Search(nums, target);

            Assert.Equal(expected, actual);
        }
Beispiel #2
0
        public void NormalTest()
        {
            Assert.Equal(1, RotatedArray.FindMin(new[] { 4, 5, 6, 7, 1, 2, 3 }));
            Assert.Equal(1, RotatedArray.FindMin(new[] { 3, 3, 6, 7, 1, 2, 3 }));

            Assert.Equal(0, RotatedArray.FindMin(new[] { 1, 1, 1, 1, 0, 1 }));
            Assert.Equal(1, RotatedArray.FindMin(new[] { 1 }));
            Assert.Equal(1, RotatedArray.FindMin(new[] { 1, 2, 3, 4, 5, 6 }));
            Assert.Equal(1, RotatedArray.FindMin(new[] { 1, 1, 1, 1, 1, 1 }));
        }
        public void RotatedArrays_FindElement_ShouldReturnCorrectId()
        {
            // Should work without rotation (rotation could be on last element)
            Assert.AreEqual(4, RotatedArray.FindElement(new[] { 1, 2, 5, 6, 8, 9, 10, 11 }, 8));     // even length
            Assert.AreEqual(-1, RotatedArray.FindElement(new[] { 1, 2, 5, 6, 8, 9, 10, 11 }, 7));    // not there
            Assert.AreEqual(-1, RotatedArray.FindElement(new[] { 1, 2, 5, 6, 8, 9, 10, 11 }, 12));   // outside bounds
            Assert.AreEqual(4, RotatedArray.FindElement(new[] { 1, 2, 5, 6, 8, 9, 10, 11, 12 }, 8)); // odd length

            // Rotation
            Assert.AreEqual(7, RotatedArray.FindElement(new[] { 10, 11, 1, 2, 5, 6, 8, 9 }, 8));     // even length
            Assert.AreEqual(-1, RotatedArray.FindElement(new[] { 10, 11, 1, 2, 5, 6, 8, 9 }, 7));    // not there
            Assert.AreEqual(-1, RotatedArray.FindElement(new[] { 10, 11, 1, 2, 5, 6, 8, 9 }, 12));   // outside bounds
            Assert.AreEqual(8, RotatedArray.FindElement(new[] { 10, 11, 12, 1, 2, 5, 6, 8, 9 }, 8)); // odd length

            // Tests to include
            Assert.AreEqual(1, RotatedArray.FindElement(new[] { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 1)); // odd length
        }
Beispiel #4
0
 public void ExceptionTest()
 {
     Assert.Throws <ArgumentException>(() => RotatedArray.FindMin(new int[0]));
     Assert.Throws <ArgumentException>(() => RotatedArray.FindMin(null));
 }