Repository navigation
[ 測試撰寫 ] LeetCode 167. Two Sum II - Input array is sorted #111
Answered
by
twy30
LPenny-github
asked this question in
Q&A
|
相關 Discussions: LeetCode: 再麻煩 @twy30 給予 測試撰寫的建議 orz 感激不盡 由於我問題太多,也希望讓大大們比較好回答,所以同一題 LeetCode 開了兩個 問題 😅 題目範例: 題目條件: using Sandbox;
using Xunit;
namespace Tests
{
public class UnitTestTwoSum2
{
[Theory]
[InlineData(new []{1,2}, new int[]{2,7,11,15}, 9)]
[InlineData(new []{1,3}, new int[]{2,3,4}, 6)]
[InlineData(new []{1,2}, new int[]{-1,0}, -1)]
public void LeetCodeExample(int[] expected, int[] inputNumbers, int target)
{
Assert.Equal(expected, new TwoSum2().TwoSum(inputNumbers,target));
}
[Fact]
public void minTarget()
{
int[] inputNumbers = new int[]{-1000,-999,-888,0};
Assert.Equal(new []{1,4}, new TwoSum2().TwoSum(inputNumbers,-1000));
}
[Fact]
public void maxTarget()
{
int[] inputNumbers = new int[]{0,10,100,500,1000};
Assert.Equal(new []{1,5}, new TwoSum2().TwoSum(inputNumbers,1000));
}
}
} |
Answered by
twy30
Jan 2, 2021
Replies: 1 comment 1 reply
我覺得「拆開來問,讓每個討論串能聚焦在一個核心問題上」,是很好的選擇 👍 😊 綜合 LeetCode 的 3 個例題及你的 也就是說,
是故,可以加一測試案例:
可以參考看看 😊 |
1 reply
Answer selected by
LPenny-github
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@LPenny-github
我覺得「拆開來問,讓每個討論串能聚焦在一個核心問題上」,是很好的選擇 👍 😊
綜合 LeetCode 的 3 個例題及你的
minTarget,maxTarget, 我會再加一個「兩個 index 都不是邊界值」的測試案例。也就是說,
index1都是 1, 也就是inputNumbers最小的 indexindex2在 LeetCode 範例1的預期答案是 2, 不是inputNumbers最大的 indexindex2在 LeetCode 範例1以外的預期答案 都是inputNumbers最大的 index是故,可以加一測試案例:
inputNumbers:{-1000, -505, 5, 510, 1000}target: 5expected:{2, 4}可以參考看看 😊