Skip to content

Commit

Permalink
Add unit tests for LeetCode #35 'Search Insert Position'.
Browse files Browse the repository at this point in the history
  • Loading branch information
eminencegrs committed Dec 23, 2024
1 parent b50ee7e commit b26f150
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Xunit;
using LeetCode.Challenges.Problems00xx.N_0035_SearchInsertPosition;
using Shouldly;

namespace LeetCode.Challenges.UnitTests.Problems00xx.N_0035_SearchInsertPosition;

public class SolutionTests
{
[Theory]
[MemberData(nameof(TestData))]
public void GivenNumbersAndTarget_WhenSearchInsert_ThenResultAsExpected(int[] nums, int target, int expected)
{
var result = Solution.SearchInsert(nums, target);
result.ShouldBe(expected);
}

public static IEnumerable<object[]> TestData()
{
yield return [new[] { 1, 3, 5, 6 }, 5, 2];
yield return [new[] { 1, 3, 5, 6 }, 2, 1];
yield return [new[] { 1, 3, 5, 6 }, 7, 4];
yield return [new[] { 1, 3, 5, 6 }, 0, 0];
yield return [new[] { 1 }, 0, 0];
yield return [new[] { 1 }, 1, 0];
yield return [new[] { 1, 3 }, 2, 1];
}
}

0 comments on commit b26f150

Please sign in to comment.