Skip to content

Commit fc72b99

Browse files
committed
test: 6 cases changes to run parallel
1 parent c021340 commit fc72b99

File tree

7 files changed

+131
-101
lines changed

7 files changed

+131
-101
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
|41|[First Missing Positive][Solutions-41]|[WindomZ][Solutions-41-Go]|Hard|[12.3 ns/op/6 test cases][Solutions-41-Test]|3 ms|
3535
|40|[Combination Sum II][Solutions-40]|[WindomZ][Solutions-40-Go]|Medium|[203 ns/op/3 test cases][Solutions-40-Test]|3 ms|
3636
|39|[Combination Sum][Solutions-39]|[WindomZ][Solutions-39-Go]|Medium|[165 ns/op/3 test cases][Solutions-39-Test]|6 ms|
37-
|38|[Count and Say][Solutions-38]|[WindomZ][Solutions-38-Go]|Easy|[262 ns/op/4 test cases][Solutions-38-Test]|0 ms|
38-
|37|[Sudoku Solver][Solutions-37]|[WindomZ][Solutions-37-Go]|Hard|[134573 ns/op/2 test cases][Solutions-37-Test]|0 ms|
39-
|36|[Valid Sudoku][Solutions-36]|[WindomZ][Solutions-36-Go]|Medium|[565 ns/op/3 test cases][Solutions-36-Test]|6 ms|
40-
|35|[Search Insert Position][Solutions-35]|[WindomZ][Solutions-35-Go]|Easy|[30.8 ns/op/8 test cases][Solutions-35-Test]|6 ms|
41-
|34|[Search for a Range][Solutions-34]|[WindomZ][Solutions-34-Go]|Medium|[209 ns/op/8 test cases][Solutions-34-Test]|19 ms|
42-
|33|[Search in Rotated Sorted Array][Solutions-33]|[WindomZ][Solutions-33-Go]|Medium|[151 ns/op/8 test cases][Solutions-33-Test]|3 ms|
37+
|38|[Count and Say][Solutions-38]|[WindomZ][Solutions-38-Go]|Easy|[66.8 ns/op/4 test cases][Solutions-38-Test]|0 ms|
38+
|37|[Sudoku Solver][Solutions-37]|[WindomZ][Solutions-37-Go]|Hard|[35497 ns/op/2 test cases][Solutions-37-Test]|0 ms|
39+
|36|[Valid Sudoku][Solutions-36]|[WindomZ][Solutions-36-Go]|Medium|[135 ns/op/3 test cases][Solutions-36-Test]|6 ms|
40+
|35|[Search Insert Position][Solutions-35]|[WindomZ][Solutions-35-Go]|Easy|[7.76 ns/op/8 test cases][Solutions-35-Test]|6 ms|
41+
|34|[Search for a Range][Solutions-34]|[WindomZ][Solutions-34-Go]|Medium|[53.5 ns/op/8 test cases][Solutions-34-Test]|19 ms|
42+
|33|[Search in Rotated Sorted Array][Solutions-33]|[WindomZ][Solutions-33-Go]|Medium|[30.0 ns/op/8 test cases][Solutions-33-Test]|3 ms|
4343
|32|[Longest Valid Parentheses][Solutions-32]|[WindomZ][Solutions-32-Go]|Hard|[221 ns/op/8 test cases][Solutions-32-Test]|3 ms|
4444
|31|[Next Permutation][Solutions-31]|[WindomZ][Solutions-31-Go]|Medium|[11.4 ns/op/4 test cases][Solutions-31-Test]|6 ms|
4545
|30|[Substring with Concatenation of All Words][Solutions-30]|[WindomZ][Solutions-30-Go]|Hard|[1358 ns/op/3 test cases][Solutions-30-Test]|13 ms|

solutions/count_and_say/countAndSay_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ func Test_countAndSay(t *testing.T) {
1616
}
1717

1818
func Benchmark_countAndSay(b *testing.B) {
19-
for i := 0; i < b.N; i++ {
20-
countAndSay(0)
21-
countAndSay(1)
22-
countAndSay(4)
23-
countAndSay(8)
24-
}
19+
b.StopTimer()
20+
b.ReportAllocs()
21+
b.StartTimer()
22+
b.RunParallel(func(pb *testing.PB) {
23+
for pb.Next() {
24+
countAndSay(0)
25+
countAndSay(1)
26+
countAndSay(4)
27+
countAndSay(8)
28+
}
29+
})
2530
}

solutions/search_for_a_range/searchRange_test.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ func Test_searchRange(t *testing.T) {
1818
}
1919

2020
func Benchmark_searchRange(b *testing.B) {
21-
for i := 0; i < b.N; i++ {
22-
searchRange([]int{}, 0)
23-
searchRange([]int{4}, 4)
24-
searchRange([]int{4, 5}, 5)
25-
searchRange([]int{4, 5, 6}, 6)
26-
searchRange([]int{4, 5, 6, 6, 7}, 6)
27-
searchRange([]int{4, 5, 6, 6, 7, 7, 8}, 7)
28-
searchRange([]int{4, 5, 6, 6, 7, 7, 7, 8}, 7)
29-
searchRange([]int{4, 5, 6, 6, 7, 7, 7, 8, 8}, 8)
30-
}
21+
b.StopTimer()
22+
b.ReportAllocs()
23+
b.StartTimer()
24+
b.RunParallel(func(pb *testing.PB) {
25+
for pb.Next() {
26+
searchRange([]int{}, 0)
27+
searchRange([]int{4}, 4)
28+
searchRange([]int{4, 5}, 5)
29+
searchRange([]int{4, 5, 6}, 6)
30+
searchRange([]int{4, 5, 6, 6, 7}, 6)
31+
searchRange([]int{4, 5, 6, 6, 7, 7, 8}, 7)
32+
searchRange([]int{4, 5, 6, 6, 7, 7, 7, 8}, 7)
33+
searchRange([]int{4, 5, 6, 6, 7, 7, 7, 8, 8}, 8)
34+
}
35+
})
3136
}

solutions/search_in_rotated_sorted_array/search_test.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ func Test_search(t *testing.T) {
1818
}
1919

2020
func Benchmark_search(b *testing.B) {
21-
for i := 0; i < b.N; i++ {
22-
search([]int{}, 0)
23-
search([]int{4}, 4)
24-
search([]int{4, 5}, 5)
25-
search([]int{4, 5, 6}, 6)
26-
search([]int{4, 5, 6, 7, 0, 1, 2}, 4)
27-
search([]int{4, 5, 6, 7, 0, 1, 2}, 5)
28-
search([]int{4, 5, 6, 7, 0, 1, 2}, 0)
29-
search([]int{4, 5, 6, 7, 0, 1, 2}, 2)
30-
}
21+
b.StopTimer()
22+
b.ReportAllocs()
23+
b.StartTimer()
24+
b.RunParallel(func(pb *testing.PB) {
25+
for pb.Next() {
26+
search([]int{}, 0)
27+
search([]int{4}, 4)
28+
search([]int{4, 5}, 5)
29+
search([]int{4, 5, 6}, 6)
30+
search([]int{4, 5, 6, 7, 0, 1, 2}, 4)
31+
search([]int{4, 5, 6, 7, 0, 1, 2}, 5)
32+
search([]int{4, 5, 6, 7, 0, 1, 2}, 0)
33+
search([]int{4, 5, 6, 7, 0, 1, 2}, 2)
34+
}
35+
})
3136
}

solutions/search_insert_position/searchInsert_test.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@ func Test_searchInsert(t *testing.T) {
2020
}
2121

2222
func Benchmark_searchInsert(b *testing.B) {
23-
for i := 0; i < b.N; i++ {
24-
searchInsert([]int{}, 0)
25-
searchInsert([]int{4}, 4)
26-
searchInsert([]int{4, 5}, 5)
27-
searchInsert([]int{4, 5, 6}, 6)
28-
searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 2)
29-
searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 3)
30-
searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 7)
31-
searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 8)
32-
}
23+
b.StopTimer()
24+
b.ReportAllocs()
25+
b.StartTimer()
26+
b.RunParallel(func(pb *testing.PB) {
27+
for pb.Next() {
28+
searchInsert([]int{}, 0)
29+
searchInsert([]int{4}, 4)
30+
searchInsert([]int{4, 5}, 5)
31+
searchInsert([]int{4, 5, 6}, 6)
32+
searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 2)
33+
searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 3)
34+
searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 7)
35+
searchInsert([]int{0, 1, 2, 4, 5, 6, 7}, 8)
36+
}
37+
})
3338
}

solutions/sudoku_solver/solveSudoku_test.go

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,33 @@ func Test_solveSudoku(t *testing.T) {
8383
}
8484

8585
func Benchmark_solveSudoku(b *testing.B) {
86-
for i := 0; i < b.N; i++ {
87-
solveSudoku([][]byte{
88-
[]byte("........."),
89-
[]byte("........."),
90-
[]byte("........."),
91-
[]byte("........."),
92-
[]byte("........."),
93-
[]byte("........."),
94-
[]byte("........."),
95-
[]byte("........."),
96-
[]byte("........."),
97-
})
98-
solveSudoku([][]byte{
99-
[]byte("53..7...."),
100-
[]byte("6..195..."),
101-
[]byte(".98....6."),
102-
[]byte("8...6...3"),
103-
[]byte("4..8.3..1"),
104-
[]byte("7...2...6"),
105-
[]byte(".6....28."),
106-
[]byte("...419..5"),
107-
[]byte("....8..79"),
108-
})
109-
}
86+
b.StopTimer()
87+
b.ReportAllocs()
88+
b.StartTimer()
89+
b.RunParallel(func(pb *testing.PB) {
90+
for pb.Next() {
91+
solveSudoku([][]byte{
92+
[]byte("........."),
93+
[]byte("........."),
94+
[]byte("........."),
95+
[]byte("........."),
96+
[]byte("........."),
97+
[]byte("........."),
98+
[]byte("........."),
99+
[]byte("........."),
100+
[]byte("........."),
101+
})
102+
solveSudoku([][]byte{
103+
[]byte("53..7...."),
104+
[]byte("6..195..."),
105+
[]byte(".98....6."),
106+
[]byte("8...6...3"),
107+
[]byte("4..8.3..1"),
108+
[]byte("7...2...6"),
109+
[]byte(".6....28."),
110+
[]byte("...419..5"),
111+
[]byte("....8..79"),
112+
})
113+
}
114+
})
110115
}

solutions/valid_sudoku/isValidSudoku_test.go

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,39 +54,44 @@ func Test_isValidSudoku(t *testing.T) {
5454
}
5555

5656
func Benchmark_isValidSudoku(b *testing.B) {
57-
for i := 0; i < b.N; i++ {
58-
isValidSudoku([][]byte{
59-
[]byte("........."),
60-
[]byte("........."),
61-
[]byte("........."),
62-
[]byte("........."),
63-
[]byte("........."),
64-
[]byte("........."),
65-
[]byte("........."),
66-
[]byte("........."),
67-
[]byte("........."),
68-
})
69-
isValidSudoku([][]byte{
70-
[]byte(".87654321"),
71-
[]byte("2........"),
72-
[]byte("3........"),
73-
[]byte("4........"),
74-
[]byte("5........"),
75-
[]byte("6........"),
76-
[]byte("7........"),
77-
[]byte("8........"),
78-
[]byte("9........"),
79-
})
80-
isValidSudoku([][]byte{
81-
[]byte("53..7...."),
82-
[]byte("6..195..."),
83-
[]byte(".98....6."),
84-
[]byte("8...6...3"),
85-
[]byte("4..8.3..1"),
86-
[]byte("7...2...6"),
87-
[]byte(".6....28."),
88-
[]byte("...419..5"),
89-
[]byte("....8..79"),
90-
})
91-
}
57+
b.StopTimer()
58+
b.ReportAllocs()
59+
b.StartTimer()
60+
b.RunParallel(func(pb *testing.PB) {
61+
for pb.Next() {
62+
isValidSudoku([][]byte{
63+
[]byte("........."),
64+
[]byte("........."),
65+
[]byte("........."),
66+
[]byte("........."),
67+
[]byte("........."),
68+
[]byte("........."),
69+
[]byte("........."),
70+
[]byte("........."),
71+
[]byte("........."),
72+
})
73+
isValidSudoku([][]byte{
74+
[]byte(".87654321"),
75+
[]byte("2........"),
76+
[]byte("3........"),
77+
[]byte("4........"),
78+
[]byte("5........"),
79+
[]byte("6........"),
80+
[]byte("7........"),
81+
[]byte("8........"),
82+
[]byte("9........"),
83+
})
84+
isValidSudoku([][]byte{
85+
[]byte("53..7...."),
86+
[]byte("6..195..."),
87+
[]byte(".98....6."),
88+
[]byte("8...6...3"),
89+
[]byte("4..8.3..1"),
90+
[]byte("7...2...6"),
91+
[]byte(".6....28."),
92+
[]byte("...419..5"),
93+
[]byte("....8..79"),
94+
})
95+
}
96+
})
9297
}

0 commit comments

Comments
 (0)