Skip to content

Commit e060cec

Browse files
authored
Improved tests and readme
1 parent f3668c6 commit e060cec

File tree

13 files changed

+365
-344
lines changed

13 files changed

+365
-344
lines changed

LeetCodeNet.Tests/G0001_0100/S0012_integer_to_roman/SolutionTest.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,29 @@ namespace LeetCodeNet.G0001_0100.S0012_integer_to_roman {
33
using System;
44
using Xunit;
55

6-
public class SolutionTest
7-
{
6+
public class SolutionTest {
87
[Fact]
9-
public void IntToRoman()
10-
{
8+
public void IntToRoman() {
119
Assert.Equal("III", new Solution().IntToRoman(3));
1210
}
1311

1412
[Fact]
15-
public void IntToRoman2()
16-
{
13+
public void IntToRoman2() {
1714
Assert.Equal("IV", new Solution().IntToRoman(4));
1815
}
1916

2017
[Fact]
21-
public void IntToRoman3()
22-
{
18+
public void IntToRoman3() {
2319
Assert.Equal("IX", new Solution().IntToRoman(9));
2420
}
2521

2622
[Fact]
27-
public void IntToRoman4()
28-
{
23+
public void IntToRoman4() {
2924
Assert.Equal("LVIII", new Solution().IntToRoman(58));
3025
}
3126

3227
[Fact]
33-
public void IntToRoman5()
34-
{
28+
public void IntToRoman5() {
3529
Assert.Equal("MCMXCIV", new Solution().IntToRoman(1994));
3630
}
3731
}

LeetCodeNet.Tests/G0001_0100/S0013_roman_to_integer/SolutionTest.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,29 @@ namespace LeetCodeNet.G0001_0100.S0013_roman_to_integer {
33
using System;
44
using Xunit;
55

6-
public class SolutionTest
7-
{
6+
public class SolutionTest {
87
[Fact]
9-
public void RomanToInt()
10-
{
8+
public void RomanToInt() {
119
Assert.Equal(3, new Solution().RomanToInt("III"));
1210
}
1311

1412
[Fact]
15-
public void RomanToInt2()
16-
{
13+
public void RomanToInt2() {
1714
Assert.Equal(4, new Solution().RomanToInt("IV"));
1815
}
1916

2017
[Fact]
21-
public void RomanToInt3()
22-
{
18+
public void RomanToInt3() {
2319
Assert.Equal(9, new Solution().RomanToInt("IX"));
2420
}
2521

2622
[Fact]
27-
public void RomanToInt4()
28-
{
23+
public void RomanToInt4() {
2924
Assert.Equal(58, new Solution().RomanToInt("LVIII"));
3025
}
3126

3227
[Fact]
33-
public void RomanToInt5()
34-
{
28+
public void RomanToInt5() {
3529
Assert.Equal(1994, new Solution().RomanToInt("MCMXCIV"));
3630
}
3731
}

LeetCodeNet.Tests/G0001_0100/S0014_longest_common_prefix/SolutionTest.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ namespace LeetCodeNet.G0001_0100.S0014_longest_common_prefix {
33
using System;
44
using Xunit;
55

6-
public class SolutionTest
7-
{
6+
public class SolutionTest {
87
[Fact]
9-
public void LongestCommonPrefix()
10-
{
8+
public void LongestCommonPrefix() {
119
Assert.Equal("fl", new Solution().LongestCommonPrefix(new string[] { "flower", "flow", "flight" }));
1210
}
1311

1412
[Fact]
15-
public void LongestCommonPrefix2()
16-
{
13+
public void LongestCommonPrefix2() {
1714
Assert.Equal("", new Solution().LongestCommonPrefix(new string[] { "dog", "racecar", "car" }));
1815
}
1916
}
Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1+
namespace LeetCodeNet.G0001_0100.S0030_substring_with_concatenation_of_all_words {
2+
13
using System.Collections.Generic;
24
using Xunit;
35

4-
namespace LeetCodeNet.G0001_0100.S0030_substring_with_concatenation_of_all_words {
5-
public class SolutionTest {
6-
[Fact]
7-
public void FindSubstring() {
8-
var solution = new Solution();
9-
var result = solution.FindSubstring("barfoothefoobarman", new string[] { "foo", "bar" });
10-
var expected = new List<int> { 0, 9 };
11-
var resultList = new List<int>(result);
12-
resultList.Sort();
13-
expected.Sort();
14-
Assert.Equal(expected, resultList);
15-
}
6+
public class SolutionTest {
7+
[Fact]
8+
public void FindSubstring() {
9+
var solution = new Solution();
10+
var result = solution.FindSubstring("barfoothefoobarman", new string[] { "foo", "bar" });
11+
var expected = new List<int> { 0, 9 };
12+
var resultList = new List<int>(result);
13+
resultList.Sort();
14+
expected.Sort();
15+
Assert.Equal(expected, resultList);
16+
}
1617

17-
[Fact]
18-
public void FindSubstring2() {
19-
var solution = new Solution();
20-
var result = solution.FindSubstring("wordgoodgoodgoodbestword", new string[] { "word", "good", "best", "word" });
21-
Assert.Equal(new List<int>(), result);
22-
}
18+
[Fact]
19+
public void FindSubstring2() {
20+
var solution = new Solution();
21+
var result = solution.FindSubstring("wordgoodgoodgoodbestword", new string[] { "word", "good", "best", "word" });
22+
Assert.Equal(new List<int>(), result);
23+
}
2324

24-
[Fact]
25-
public void FindSubstring3() {
26-
var solution = new Solution();
27-
var result = solution.FindSubstring("barfoofoobarthefoobarman", new string[] { "bar", "foo", "the" });
28-
var expected = new List<int> { 6, 9, 12 };
29-
var resultList = new List<int>(result);
30-
resultList.Sort();
31-
expected.Sort();
32-
Assert.Equal(expected, resultList);
33-
}
25+
[Fact]
26+
public void FindSubstring3() {
27+
var solution = new Solution();
28+
var result = solution.FindSubstring("barfoofoobarthefoobarman", new string[] { "bar", "foo", "the" });
29+
var expected = new List<int> { 6, 9, 12 };
30+
var resultList = new List<int>(result);
31+
resultList.Sort();
32+
expected.Sort();
33+
Assert.Equal(expected, resultList);
3434
}
3535
}
36+
}
Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1+
namespace LeetCodeNet.G0001_0100.S0036_valid_sudoku {
2+
13
using Xunit;
24

3-
namespace LeetCodeNet.G0001_0100.S0036_valid_sudoku {
4-
public class SolutionTest {
5-
[Fact]
6-
public void IsValidSudoku_ValidBoard() {
7-
var solution = new Solution();
8-
var board = new char[][] {
9-
new char[] {'5','3','.','.','7','.','.','.','.'},
10-
new char[] {'6','.','.','1','9','5','.','.','.'},
11-
new char[] {'.','9','8','.','.','.','.','6','.'},
12-
new char[] {'8','.','.','.','6','.','.','.','3'},
13-
new char[] {'4','.','.','8','.','3','.','.','1'},
14-
new char[] {'7','.','.','.','2','.','.','.','6'},
15-
new char[] {'.','6','.','.','.','.','2','8','.'},
16-
new char[] {'.','.','.','4','1','9','.','.','5'},
17-
new char[] {'.','.','.','.','8','.','.','7','9'}
18-
};
19-
Assert.True(solution.IsValidSudoku(board));
20-
}
5+
public class SolutionTest {
6+
[Fact]
7+
public void IsValidSudoku() {
8+
var solution = new Solution();
9+
var board = new char[][] {
10+
new char[] {'5','3','.','.','7','.','.','.','.'},
11+
new char[] {'6','.','.','1','9','5','.','.','.'},
12+
new char[] {'.','9','8','.','.','.','.','6','.'},
13+
new char[] {'8','.','.','.','6','.','.','.','3'},
14+
new char[] {'4','.','.','8','.','3','.','.','1'},
15+
new char[] {'7','.','.','.','2','.','.','.','6'},
16+
new char[] {'.','6','.','.','.','.','2','8','.'},
17+
new char[] {'.','.','.','4','1','9','.','.','5'},
18+
new char[] {'.','.','.','.','8','.','.','7','9'}
19+
};
20+
Assert.True(solution.IsValidSudoku(board));
21+
}
2122

22-
[Fact]
23-
public void IsValidSudoku_InvalidBoard() {
24-
var solution = new Solution();
25-
var board = new char[][] {
26-
new char[] {'8','3','.','.','7','.','.','.','.'},
27-
new char[] {'6','.','.','1','9','5','.','.','.'},
28-
new char[] {'.','9','8','.','.','.','.','6','.'},
29-
new char[] {'8','.','.','.','6','.','.','.','3'},
30-
new char[] {'4','.','.','8','.','3','.','.','1'},
31-
new char[] {'7','.','.','.','2','.','.','.','6'},
32-
new char[] {'.','6','.','.','.','.','2','8','.'},
33-
new char[] {'.','.','.','4','1','9','.','.','5'},
34-
new char[] {'.','.','.','.','8','.','.','7','9'}
35-
};
36-
Assert.False(solution.IsValidSudoku(board));
37-
}
23+
[Fact]
24+
public void IsValidSudoku2() {
25+
var solution = new Solution();
26+
var board = new char[][] {
27+
new char[] {'8','3','.','.','7','.','.','.','.'},
28+
new char[] {'6','.','.','1','9','5','.','.','.'},
29+
new char[] {'.','9','8','.','.','.','.','6','.'},
30+
new char[] {'8','.','.','.','6','.','.','.','3'},
31+
new char[] {'4','.','.','8','.','3','.','.','1'},
32+
new char[] {'7','.','.','.','2','.','.','.','6'},
33+
new char[] {'.','6','.','.','.','.','2','8','.'},
34+
new char[] {'.','.','.','4','1','9','.','.','5'},
35+
new char[] {'.','.','.','.','8','.','.','7','9'}
36+
};
37+
Assert.False(solution.IsValidSudoku(board));
3838
}
3939
}
40+
}

LeetCodeNet.Tests/G0001_0100/S0048_rotate_image/SolutionTest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,15 @@ public void Rotate() {
1010
new Solution().Rotate(input);
1111
Assert.Equal(exected, input);
1212
}
13+
14+
[Fact]
15+
public void Rotate2() {
16+
var input = new int[][] { new int[] { 5, 1, 9, 11 }, new int[] { 2, 4, 8, 10 }, new int[] { 13, 3, 6, 7 },
17+
new int[] { 15, 14, 12, 16 } };
18+
var exected = new int[][] { new int[] { 15, 13, 2, 5 }, new int[] { 14, 3, 4, 1 }, new int[] { 12, 6, 8, 9 },
19+
new int[] { 16, 7, 10, 11 } };
20+
new Solution().Rotate(input);
21+
Assert.Equal(exected, input);
22+
}
1323
}
1424
}
Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1+
namespace LeetCodeNet.G0001_0100.S0050_powx_n {
2+
13
using Xunit;
24

3-
namespace LeetCodeNet.G0001_0100.S0050_powx_n {
4-
public class SolutionTest {
5-
[Fact]
6-
public void MyPow_PositiveExponent() {
7-
Assert.True(System.Math.Abs(new Solution().MyPow(2.0, 10) - 1024.0) < 1e-5);
8-
}
5+
public class SolutionTest {
6+
[Fact]
7+
public void MyPow() {
8+
Assert.True(System.Math.Abs(new Solution().MyPow(2.0, 10) - 1024.0) < 1e-5);
9+
}
910

10-
[Fact]
11-
public void MyPow_DecimalBase() {
12-
Assert.True(System.Math.Abs(new Solution().MyPow(2.1, 3) - 9.261) < 1e-5);
13-
}
11+
[Fact]
12+
public void MyPow2() {
13+
Assert.True(System.Math.Abs(new Solution().MyPow(2.1, 3) - 9.261) < 1e-5);
14+
}
1415

15-
[Fact]
16-
public void MyPow_NegativeExponent() {
17-
Assert.True(System.Math.Abs(new Solution().MyPow(2.0, -2) - 0.25) < 1e-5);
18-
}
16+
[Fact]
17+
public void MyPow3() {
18+
Assert.True(System.Math.Abs(new Solution().MyPow(2.0, -2) - 0.25) < 1e-5);
19+
}
1920

20-
[Fact]
21-
public void MyPow_ZeroExponent() {
22-
Assert.True(System.Math.Abs(new Solution().MyPow(1.0, 0) - 1.0) < 1e-5);
23-
}
21+
[Fact]
22+
public void MyPow4() {
23+
Assert.True(System.Math.Abs(new Solution().MyPow(1.0, 0) - 1.0) < 1e-5);
24+
}
2425

25-
[Fact]
26-
public void MyPow_NegativeBase() {
27-
Assert.True(System.Math.Abs(new Solution().MyPow(-1.0, 1) - (-1.0)) < 1e-5);
28-
}
26+
[Fact]
27+
public void MyPow5() {
28+
Assert.True(System.Math.Abs(new Solution().MyPow(-1.0, 1) - (-1.0)) < 1e-5);
2929
}
3030
}
31+
}
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1+
namespace LeetCodeNet.G0001_0100.S0052_n_queens_ii {
2+
13
using Xunit;
24

3-
namespace LeetCodeNet.G0001_0100.S0052_n_queens_ii {
4-
public class SolutionTest {
5-
[Fact]
6-
public void TotalNQueens_1() {
7-
Assert.Equal(1, new Solution().TotalNQueens(1));
8-
}
5+
public class SolutionTest {
6+
[Fact]
7+
public void TotalNQueens() {
8+
Assert.Equal(1, new Solution().TotalNQueens(1));
9+
}
910

10-
[Fact]
11-
public void TotalNQueens_4() {
12-
Assert.Equal(2, new Solution().TotalNQueens(4));
13-
}
11+
[Fact]
12+
public void TotalNQueens2() {
13+
Assert.Equal(2, new Solution().TotalNQueens(4));
14+
}
1415

15-
[Fact]
16-
public void TotalNQueens_5() {
17-
Assert.Equal(10, new Solution().TotalNQueens(5));
18-
}
16+
[Fact]
17+
public void TotalNQueens3() {
18+
Assert.Equal(10, new Solution().TotalNQueens(5));
19+
}
1920

20-
[Fact]
21-
public void TotalNQueens_8() {
22-
Assert.Equal(92, new Solution().TotalNQueens(8));
23-
}
21+
[Fact]
22+
public void TotalNQueens4() {
23+
Assert.Equal(92, new Solution().TotalNQueens(8));
2424
}
2525
}
26+
}

0 commit comments

Comments
 (0)