Skip to content

Commit 00b0ef5

Browse files
committed
use t.Fatal instead t.Error
1 parent 427dbf4 commit 00b0ef5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+68
-68
lines changed

leetcode/array/generate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func Test_generate(t *testing.T) {
99
for i := 0; i < len(r); i++ {
1010
for j := 0; j < len(r[i]); j++ {
1111
if r[i][j] != result[i][j] {
12-
t.Error(r, result)
12+
t.Fatal(r, result)
1313
}
1414
}
1515
}

leetcode/array/getRow_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_getRow(t *testing.T) {
88
r := getRow(i)
99
for j := 0; j < len(r); j++ {
1010
if r[j] != result[i][j] {
11-
t.Error(i-1, result[i], r)
11+
t.Fatal(i-1, result[i], r)
1212
}
1313
}
1414
}

leetcode/array/majorityElement_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import "testing"
55
func Test_majorityElement(t *testing.T) {
66
nums := []int{1, 2, 3, 4, 2, 2, 2}
77
if r := majorityElement(nums); r != 2 {
8-
t.Error(nums, r)
8+
t.Fatal(nums, r)
99
}
1010
nums = []int{1}
1111
if r := majorityElement(nums); r != 1 {
12-
t.Error(nums, r)
12+
t.Fatal(nums, r)
1313
}
1414
}

leetcode/array/maxSubArray_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import "testing"
55
func Test_maxSubArray(t *testing.T) {
66
nums := []int{-2, 1, -3, 4, -1, 2, 1, -5, 4}
77
if r := maxSubArray(nums); r != 6 {
8-
t.Error(r)
8+
t.Fatal(r)
99
}
1010

1111
nums = []int{-2, -3, -1, -5}
1212
if r := maxSubArray(nums); r != -1 {
13-
t.Error(r)
13+
t.Fatal(r)
1414
}
1515

1616
nums = []int{-1, 2}
1717
if r := maxSubArray(nums); r != 2 {
18-
t.Error(r)
18+
t.Fatal(r)
1919
}
2020
}

leetcode/array/merge_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func Test_merge(t *testing.T) {
1313

1414
for i := 0; i < len(result); i++ {
1515
if result[i] != nums1[i] {
16-
t.Error(result, nums1)
16+
t.Fatal(result, nums1)
1717
}
1818
}
1919
}

leetcode/array/plusOne_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_plusOne(t *testing.T) {
88
r := plusOne(digits)
99
for i := 0; i < len(r); i++ {
1010
if r[i] != result[i] {
11-
t.Error(result, r)
11+
t.Fatal(result, r)
1212
}
1313
}
1414
}

leetcode/array/removeDuplicates_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_removeDuplicates(t *testing.T) {
88
length := removeDuplicates(nums)
99
for i := 0; i < len(dealedNums); i++ {
1010
if length != 6 || nums[i] != dealedNums[i] {
11-
t.Error("return is:", length, nums[i], "!=", dealedNums[i])
11+
t.Fatal("return is:", length, nums[i], "!=", dealedNums[i])
1212
}
1313
}
1414

leetcode/array/removeElement_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_removeElement(t *testing.T) {
88
length := removeElement(input, 3)
99
for i := 0; i < len(result); i++ {
1010
if length != 8 || input[i] != result[i] {
11-
t.Error(length, input[i], result[i])
11+
t.Fatal(length, input[i], result[i])
1212
}
1313
}
1414
}

leetcode/array/rotate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func Test_rotate(t *testing.T) {
99
rotate(nums, 3)
1010
for i := 0; i < len(nums); i++ {
1111
if nums[i] != result[i] {
12-
t.Error(nums, result)
12+
t.Fatal(nums, result)
1313
}
1414
}
1515
}

leetcode/array/searchInsert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_searchInsert(t *testing.T) {
88
results := []int{2, 1, 4, 0}
99
for i := 0; i < len(targets); i++ {
1010
if r := searchInsert(nums, targets[i]); r != results[i] {
11-
t.Error(nums, targets[i], r)
11+
t.Fatal(nums, targets[i], r)
1212
}
1313
}
1414
}

leetcode/array/twoSum2_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ func Test_twoSum2(t *testing.T) {
66
numbers := []int{2, 7, 11, 15}
77
target := 9
88
if r := twoSum2(numbers, target); r[0] != 1 || r[1] != 2 {
9-
t.Error(numbers, target, r)
9+
t.Fatal(numbers, target, r)
1010
}
1111
}

leetcode/array/twoSum_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ func Test_twoSum(t *testing.T) {
66
nums := []int{2, 7, 11, 15}
77
result := twoSum(nums, 9)
88
if result[0] != 0 || result[1] != 1 {
9-
t.Error(result)
9+
t.Fatal(result)
1010
}
1111
}

leetcode/dynamic-programming/climbStairs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ func Test_climbStairs(t *testing.T) {
77
results := []int{0, 0, 1, 2, 3, 5}
88
for i := 0; i < len(nums); i++ {
99
if result := climbStairs(nums[i]); result != results[i] {
10-
t.Error(nums[i], results[i], result)
10+
t.Fatal(nums[i], results[i], result)
1111
}
1212
}
1313
}

leetcode/dynamic-programming/maxProfit2_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_maxProfit2(t *testing.T) {
88

99
for i := 0; i < len(input); i++ {
1010
if r := maxProfit2(input[i]); r != result[i] {
11-
t.Error(input[i], r, "Expected:", result[i])
11+
t.Fatal(input[i], r, "Expected:", result[i])
1212
}
1313
}
1414
}

leetcode/dynamic-programming/maxProfit3_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_maxProfit3(t *testing.T) {
88

99
for i := 0; i < len(input); i++ {
1010
if r := maxProfit3(input[i]); r != result[i] {
11-
t.Error(input[i], r, "Expected:", result[i])
11+
t.Fatal(input[i], r, "Expected:", result[i])
1212
}
1313
}
1414
}

leetcode/dynamic-programming/maxProfit4_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_maxProfit4(t *testing.T) {
88

99
for i := 0; i < len(input); i++ {
1010
if r := maxProfit4(2, input[i]); r != result[i] {
11-
t.Error(input[i], r, "Expected:", result[i])
11+
t.Fatal(input[i], r, "Expected:", result[i])
1212
}
1313
}
1414
}

leetcode/dynamic-programming/maxProfit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_maxProfit(t *testing.T) {
88

99
for i := 0; i < len(input); i++ {
1010
if r := maxProfit(input[i]); r != result[i] {
11-
t.Error(input[i], result[i])
11+
t.Fatal(input[i], result[i])
1212
}
1313
}
1414
}

leetcode/dynamic-programming/rob_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_rob(t *testing.T) {
88

99
for i := 0; i < len(input); i++ {
1010
if r := rob(input[i]); r != result[i] {
11-
t.Error(input[i], result[i], r)
11+
t.Fatal(input[i], result[i], r)
1212
}
1313
}
1414
}

leetcode/hash-table/containsDuplicate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_containsDuplicate(t *testing.T) {
88

99
for i, nums := range input {
1010
if r := containsDuplicate(nums); r != result[i] {
11-
t.Error(nums, r)
11+
t.Fatal(nums, r)
1212
}
1313
}
1414
}

leetcode/hash-table/singleNumber_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_singleNumber(t *testing.T) {
88

99
for i := 0; i < len(input); i++ {
1010
if r := singleNumber(input[i]); r != result[i] {
11-
t.Error(input[i], r)
11+
t.Fatal(input[i], r)
1212
}
1313
}
1414
}

leetcode/linked-list/addTwoNumbers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ func Test_addTwoNumbers(t *testing.T) {
66
l1 := &ListNode{Val: 2, Next: &ListNode{Val: 4, Next: &ListNode{Val: 5}}}
77
l2 := &ListNode{Val: 5, Next: &ListNode{Val: 6, Next: &ListNode{Val: 4}}}
88
if result := addTwoNumbers(l1, l2); result.String() != "7 0 0 1 <nil>" {
9-
t.Error(result)
9+
t.Fatal(result)
1010
}
1111
}

leetcode/linked-list/deleteDuplicates_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import "testing"
55
func Test_deleteDuplicates(t *testing.T) {
66
input := &ListNode{Val: 1, Next: &ListNode{Val: 1, Next: &ListNode{Val: 2, Next: &ListNode{Val: 3, Next: &ListNode{Val: 3, Next: nil}}}}}
77
if result := deleteDuplicates(input); result.String() != "1 2 3 <nil>" {
8-
t.Error(result, "1 2 3 <nil>")
8+
t.Fatal(result, "1 2 3 <nil>")
99
}
1010
}

leetcode/linked-list/mergeTwoLists_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ func Test_mergeTwoLists(t *testing.T) {
66
l1 := &ListNode{Val: 2, Next: &ListNode{Val: 4, Next: &ListNode{Val: 5, Next: &ListNode{Val: 6}}}}
77
l2 := &ListNode{Val: 1, Next: &ListNode{Val: 4, Next: &ListNode{Val: 5}}}
88
if result := mergeTwoLists(l1, l2); result.String() != "1 2 4 4 5 5 6 <nil>" {
9-
t.Error(result)
9+
t.Fatal(result)
1010
}
1111

1212
l1 = nil
1313
l2 = &ListNode{Val: 1}
1414
if result := mergeTwoLists(l1, l2); result.String() != "1 <nil>" {
15-
t.Error(result)
15+
t.Fatal(result)
1616
}
1717
}

leetcode/linked-list/removeElements_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import "testing"
55
func Test_removeElements(t *testing.T) {
66
head := &ListNode{Val: 1, Next: &ListNode{Val: 2, Next: &ListNode{Val: 6, Next: &ListNode{Val: 3, Next: &ListNode{Val: 6}}}}}
77
if r := removeElements(head, 6); r.String() != "1 2 3 <nil>" {
8-
t.Error(r)
8+
t.Fatal(r)
99
}
1010
}

leetcode/linked-list/reverseList_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import "testing"
55
func Test_reverseList(t *testing.T) {
66
head := &ListNode{Val: 1, Next: &ListNode{Val: 2, Next: &ListNode{Val: 6, Next: &ListNode{Val: 3, Next: &ListNode{Val: 6}}}}}
77
if r := reverseList(head); r.String() != "6 3 6 2 1 <nil>" {
8-
t.Error(r)
8+
t.Fatal(r)
99
}
1010
}

leetcode/math/convertToTitle_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_convertToTitle(t *testing.T) {
88

99
for i := 0; i < len(input); i++ {
1010
if r := convertToTitle(input[i]); r != result[i] {
11-
t.Error(input[i], result[i], r)
11+
t.Fatal(input[i], result[i], r)
1212
}
1313
}
1414
}

leetcode/math/countPrimes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_countPrimes(t *testing.T) {
88

99
for i := 0; i < len(nums); i++ {
1010
if r := countPrimes(nums[i]); r != results[i] {
11-
t.Error(nums[i], r)
11+
t.Fatal(nums[i], r)
1212
}
1313
}
1414
}

leetcode/math/isHappy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_isHappy(t *testing.T) {
88

99
for i := 0; i < len(nums); i++ {
1010
if r := isHappy(nums[i]); r != result[i] {
11-
t.Error(nums[i], result[i], r)
11+
t.Fatal(nums[i], result[i], r)
1212
}
1313
}
1414
}

leetcode/math/isPalindrome_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ func Test_isPalindrome(t *testing.T) {
77
results := []bool{false, true, false, true}
88
for index, num := range nums {
99
if r := isPalindrome(num); r != results[index] {
10-
t.Error(num, r, results[index])
10+
t.Fatal(num, r, results[index])
1111
}
1212
}
1313
}

leetcode/math/mySqrt_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ func Test_mySqrt(t *testing.T) {
77
results := []int{0, 1, 1, 2, 2, 3, 90}
88
for i := 0; i < len(nums); i++ {
99
if result := mySqrt(nums[i]); result != results[i] {
10-
t.Error(nums[i], results[i], result)
10+
t.Fatal(nums[i], results[i], result)
1111
}
1212
}
1313
}

leetcode/math/reverse_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ func Test_reverse(t *testing.T) {
77
results := []int{1, 2, 321, 123, 4321, -3543, 0, 0}
88
for index, num := range nums {
99
if r := reverse(num); r != results[index] {
10-
t.Error(num, r, results[index])
10+
t.Fatal(num, r, results[index])
1111
}
1212
}
1313
}

leetcode/math/romanToInt_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ func Test_romanToInt(t *testing.T) {
77
results := []int{621}
88
for index, num := range nums {
99
if r := romanToInt(num); r != results[index] {
10-
t.Error(num, r, results[index])
10+
t.Fatal(num, r, results[index])
1111
}
1212
}
1313
}

leetcode/math/titleToNumber_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_titleToNumber(t *testing.T) {
88

99
for i := 0; i < len(input); i++ {
1010
if r := titleToNumber(input[i]); r != result[i] {
11-
t.Error(input[i], result[i], r)
11+
t.Fatal(input[i], result[i], r)
1212
}
1313
}
1414
}

leetcode/math/trailingZeroes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_trailingZeroes(t *testing.T) {
88

99
for i := 0; i < len(input); i++ {
1010
if r := trailingZeroes(input[i]); r != result[i] {
11-
t.Error(input[i], result[i], r)
11+
t.Fatal(input[i], result[i], r)
1212
}
1313
}
1414
}

leetcode/stack/MinStack_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ func Test_MinStack(t *testing.T) {
99
stack.Push(-3)
1010

1111
if r := stack.GetMin(); r != -3 {
12-
t.Error("GetMin:", r)
12+
t.Fatal("GetMin:", r)
1313
}
1414

1515
stack.Pop()
1616
if r := stack.Top(); r != 0 {
17-
t.Error("Top", r)
17+
t.Fatal("Top", r)
1818
}
1919

2020
if r := stack.GetMin(); r != -2 {
21-
t.Error("GetMin:", r)
21+
t.Fatal("GetMin:", r)
2222
}
2323
}

leetcode/stack/MyStack_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ func Test_MyStack(t *testing.T) {
99
stack.Push(-3)
1010

1111
if r := stack.Empty(); r != false {
12-
t.Error("Empty:", r)
12+
t.Fatal("Empty:", r)
1313
}
1414

1515
stack.Pop()
1616
if r := stack.Top(); r != 0 {
17-
t.Error("Top", r)
17+
t.Fatal("Top", r)
1818
}
1919

2020
stack.Pop()
2121
stack.Pop()
2222
if r := stack.Empty(); r != true {
23-
t.Error("Empty:", r)
23+
t.Fatal("Empty:", r)
2424
}
2525
}

leetcode/string/addBinary_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_addBinary(t *testing.T) {
88
rs := []string{"0", "1", "10", "101", "100", "11110"}
99
for i := 0; i < len(as); i++ {
1010
if r := addBinary(as[i], bs[i]); r != rs[i] {
11-
t.Error(as[i], bs[i], rs[i], r)
11+
t.Fatal(as[i], bs[i], rs[i], r)
1212
}
1313
}
1414
}

leetcode/string/countAndSay_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ func Test_countAndSay(t *testing.T) {
77
results := []string{"1", "11", "21", "1211", "111221"}
88
for i := 1; i < len(nums); i++ {
99
if r := countAndSay(nums[i]); r != results[i] {
10-
t.Error(nums[i], results[i], "output is:", r)
10+
t.Fatal(nums[i], results[i], "output is:", r)
1111
}
1212
}
1313
}

leetcode/string/isPalindrome_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func Test_isPalindrome(t *testing.T) {
88

99
for i := 0; i < len(input); i++ {
1010
if r := isPalindrome(input[i]); r != result[i] {
11-
t.Error(input[i], r)
11+
t.Fatal(input[i], r)
1212
}
1313
}
1414
}

leetcode/string/isValid_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ func Test_isValid(t *testing.T) {
77
results := []bool{false, false, true, true, false}
88
for i := 0; i < len(inputs); i++ {
99
if r := isValid(inputs[i]); r != results[i] {
10-
t.Error(inputs[i], results[i], r)
10+
t.Fatal(inputs[i], results[i], r)
1111
}
1212
}
1313
}

0 commit comments

Comments
 (0)