From 63f5f4a3af01ea80c4883644bc9ab69d906625da Mon Sep 17 00:00:00 2001 From: Hoanh An Date: Sun, 13 Oct 2019 14:56:56 -0400 Subject: [PATCH] use custom test assert helper --- interviewcake/2nd_largest_item_bst_test.go | 7 +++---- interviewcake/apple_stocks_test.go | 5 +---- interviewcake/balanced_binary_tree_test.go | 5 +---- interviewcake/binary_search_tree_test.go | 7 +++---- interviewcake/bracket_validator_test.go | 3 ++- interviewcake/fibonacci_number_test.go | 7 +++---- interviewcake/find_rotation_point_test.go | 7 +++---- interviewcake/graph_coloring_test.go | 5 +---- interviewcake/highest_product_of_three_test.go | 5 +---- interviewcake/inflight_test.go | 7 +++---- interviewcake/inplace_shuffle_test.go | 5 +---- interviewcake/making_change_test.go | 13 ++++--------- interviewcake/merge_meetings_test.go | 5 +---- interviewcake/merge_sorted_arrays_test.go | 7 +++---- interviewcake/permutation_palindrome_test.go | 7 +++---- interviewcake/product_of_others_test.go | 7 +++---- interviewcake/recursive_string_permutation_test.go | 7 +++---- interviewcake/reverse_string_test.go | 7 +++---- interviewcake/reverse_word_test.go | 7 +++---- interviewcake/top_scores_test.go | 7 +++---- interviewcake/word_cloud_test.go | 7 +++---- other/balanced_binary_tree_test.go | 7 ++----- other/binary_tree_traverse_test.go | 5 +---- 23 files changed, 54 insertions(+), 95 deletions(-) diff --git a/interviewcake/2nd_largest_item_bst_test.go b/interviewcake/2nd_largest_item_bst_test.go index 94a24db..128887c 100644 --- a/interviewcake/2nd_largest_item_bst_test.go +++ b/interviewcake/2nd_largest_item_bst_test.go @@ -33,8 +33,9 @@ package interviewcake import ( - "reflect" "testing" + + "github.com/hoanhan101/algo/common" ) func Test2ndLargestItem(t *testing.T) { @@ -88,9 +89,7 @@ func Test2ndLargestItem(t *testing.T) { for _, tt := range tests { result := findSecondLargest(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/apple_stocks_test.go b/interviewcake/apple_stocks_test.go index 33f4ba9..6b2682b 100644 --- a/interviewcake/apple_stocks_test.go +++ b/interviewcake/apple_stocks_test.go @@ -16,7 +16,6 @@ package interviewcake import ( - "reflect" "testing" "github.com/hoanhan101/algo/common" @@ -37,9 +36,7 @@ func TestGetMaxProfit(t *testing.T) { for _, tt := range tests { result := getMaxProfit(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/balanced_binary_tree_test.go b/interviewcake/balanced_binary_tree_test.go index 6429bba..03b955f 100644 --- a/interviewcake/balanced_binary_tree_test.go +++ b/interviewcake/balanced_binary_tree_test.go @@ -29,7 +29,6 @@ package interviewcake import ( - "reflect" "testing" "github.com/hoanhan101/algo/common" @@ -83,9 +82,7 @@ func TestIsSuperBalanced(t *testing.T) { for _, tt := range tests { result := isSuperBalanced(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/binary_search_tree_test.go b/interviewcake/binary_search_tree_test.go index ac260a4..1b1b315 100644 --- a/interviewcake/binary_search_tree_test.go +++ b/interviewcake/binary_search_tree_test.go @@ -29,8 +29,9 @@ package interviewcake import ( "math" - "reflect" "testing" + + "github.com/hoanhan101/algo/common" ) func TestIsBinarySearchTree(t *testing.T) { @@ -78,9 +79,7 @@ func TestIsBinarySearchTree(t *testing.T) { for _, tt := range tests { result := isBinarySearchTree(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/bracket_validator_test.go b/interviewcake/bracket_validator_test.go index d6f05fa..5ad44b2 100644 --- a/interviewcake/bracket_validator_test.go +++ b/interviewcake/bracket_validator_test.go @@ -39,7 +39,8 @@ func TestValidateBracket(t *testing.T) { } for _, tt := range tests { - common.Equal(t, tt.expected, validateBracket(tt.sentence)) + result := validateBracket(tt.sentence) + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/fibonacci_number_test.go b/interviewcake/fibonacci_number_test.go index 881056b..17e3878 100644 --- a/interviewcake/fibonacci_number_test.go +++ b/interviewcake/fibonacci_number_test.go @@ -16,8 +16,9 @@ package interviewcake import ( - "reflect" "testing" + + "github.com/hoanhan101/algo/common" ) func TestFib(t *testing.T) { @@ -36,9 +37,7 @@ func TestFib(t *testing.T) { for _, tt := range tests { result := fib(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/find_rotation_point_test.go b/interviewcake/find_rotation_point_test.go index 0ebb7e5..0931190 100644 --- a/interviewcake/find_rotation_point_test.go +++ b/interviewcake/find_rotation_point_test.go @@ -31,8 +31,9 @@ package interviewcake import ( - "reflect" "testing" + + "github.com/hoanhan101/algo/common" ) func TestFindRotationPoint(t *testing.T) { @@ -103,9 +104,7 @@ func TestFindRotationPoint(t *testing.T) { for _, tt := range tests { result := findRotationPoint(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/graph_coloring_test.go b/interviewcake/graph_coloring_test.go index 5aeebeb..f1b6ae7 100644 --- a/interviewcake/graph_coloring_test.go +++ b/interviewcake/graph_coloring_test.go @@ -21,7 +21,6 @@ package interviewcake import ( - "reflect" "testing" "github.com/hoanhan101/algo/common" @@ -132,9 +131,7 @@ func TestColorGraph(t *testing.T) { result = append(result, g.color) } - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/highest_product_of_three_test.go b/interviewcake/highest_product_of_three_test.go index 9908b36..0c0497c 100644 --- a/interviewcake/highest_product_of_three_test.go +++ b/interviewcake/highest_product_of_three_test.go @@ -20,7 +20,6 @@ package interviewcake import ( - "reflect" "testing" "github.com/hoanhan101/algo/common" @@ -38,9 +37,7 @@ func TestHighestProductOfThree(t *testing.T) { for _, tt := range tests { result := highestProductOfThree(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/inflight_test.go b/interviewcake/inflight_test.go index 273c3e3..94909eb 100644 --- a/interviewcake/inflight_test.go +++ b/interviewcake/inflight_test.go @@ -20,8 +20,9 @@ package interviewcake import ( - "reflect" "testing" + + "github.com/hoanhan101/algo/common" ) func TestFillFlight(t *testing.T) { @@ -41,9 +42,7 @@ func TestFillFlight(t *testing.T) { for _, tt := range tests { result := fillFlight(tt.in1, tt.in2) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/inplace_shuffle_test.go b/interviewcake/inplace_shuffle_test.go index 9fd621d..c581820 100644 --- a/interviewcake/inplace_shuffle_test.go +++ b/interviewcake/inplace_shuffle_test.go @@ -15,7 +15,6 @@ package interviewcake import ( - "reflect" "testing" "github.com/hoanhan101/algo/common" @@ -33,9 +32,7 @@ func TestInplaceShuffle(t *testing.T) { for _, tt := range tests { result := inplaceShuffle(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/making_change_test.go b/interviewcake/making_change_test.go index b0d7d2e..2a8575a 100644 --- a/interviewcake/making_change_test.go +++ b/interviewcake/making_change_test.go @@ -25,8 +25,9 @@ package interviewcake import ( - "reflect" "testing" + + "github.com/hoanhan101/algo/common" ) func TestMakeChange(t *testing.T) { @@ -82,14 +83,8 @@ func TestMakeChange(t *testing.T) { for _, tt := range tests { r1, r2 := makeChange(tt.in1, tt.in2) - - if !reflect.DeepEqual(r1, tt.expected1) { - t.Errorf("should be %v instead %v", tt.expected1, r1) - } - - if !reflect.DeepEqual(r2, tt.expected2) { - t.Errorf("should be %v instead %v", tt.expected2, r2) - } + common.Equal(t, tt.expected1, r1) + common.Equal(t, tt.expected2, r2) } } diff --git a/interviewcake/merge_meetings_test.go b/interviewcake/merge_meetings_test.go index d158942..c7f6058 100644 --- a/interviewcake/merge_meetings_test.go +++ b/interviewcake/merge_meetings_test.go @@ -21,7 +21,6 @@ package interviewcake import ( - "reflect" "sort" "testing" @@ -44,9 +43,7 @@ func TestMergeMeetings(t *testing.T) { for _, tt := range tests { result := mergeMeetings(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/merge_sorted_arrays_test.go b/interviewcake/merge_sorted_arrays_test.go index 83e1f5f..7076461 100644 --- a/interviewcake/merge_sorted_arrays_test.go +++ b/interviewcake/merge_sorted_arrays_test.go @@ -15,8 +15,9 @@ package interviewcake import ( - "reflect" "testing" + + "github.com/hoanhan101/algo/common" ) func TestMergeSortedArray(t *testing.T) { @@ -49,9 +50,7 @@ func TestMergeSortedArray(t *testing.T) { for _, tt := range tests { result := mergeSortedArray(tt.in1, tt.in2) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/permutation_palindrome_test.go b/interviewcake/permutation_palindrome_test.go index f2ef708..5181b1e 100644 --- a/interviewcake/permutation_palindrome_test.go +++ b/interviewcake/permutation_palindrome_test.go @@ -23,8 +23,9 @@ package interviewcake import ( - "reflect" "testing" + + "github.com/hoanhan101/algo/common" ) func TestHasPalindromePermutation(t *testing.T) { @@ -44,9 +45,7 @@ func TestHasPalindromePermutation(t *testing.T) { for _, tt := range tests { result := hasPalindromePermutation(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/product_of_others_test.go b/interviewcake/product_of_others_test.go index 7ce02fc..e0e56d6 100644 --- a/interviewcake/product_of_others_test.go +++ b/interviewcake/product_of_others_test.go @@ -18,8 +18,9 @@ package interviewcake import ( - "reflect" "testing" + + "github.com/hoanhan101/algo/common" ) func TestGetProductOfOthers(t *testing.T) { @@ -35,9 +36,7 @@ func TestGetProductOfOthers(t *testing.T) { for _, tt := range tests { result := getProductOfOthers(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/recursive_string_permutation_test.go b/interviewcake/recursive_string_permutation_test.go index be3cc19..c673ec1 100644 --- a/interviewcake/recursive_string_permutation_test.go +++ b/interviewcake/recursive_string_permutation_test.go @@ -17,9 +17,10 @@ package interviewcake import ( - "reflect" "strings" "testing" + + "github.com/hoanhan101/algo/common" ) func TestPermuteString(t *testing.T) { @@ -35,9 +36,7 @@ func TestPermuteString(t *testing.T) { for _, tt := range tests { result := permuteString(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/reverse_string_test.go b/interviewcake/reverse_string_test.go index 4d8cc03..90bb44a 100644 --- a/interviewcake/reverse_string_test.go +++ b/interviewcake/reverse_string_test.go @@ -15,8 +15,9 @@ package interviewcake import ( - "reflect" "testing" + + "github.com/hoanhan101/algo/common" ) func TestReverseString(t *testing.T) { @@ -33,9 +34,7 @@ func TestReverseString(t *testing.T) { for _, tt := range tests { result := reverseString(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/reverse_word_test.go b/interviewcake/reverse_word_test.go index 4fcde80..8d44525 100644 --- a/interviewcake/reverse_word_test.go +++ b/interviewcake/reverse_word_test.go @@ -17,8 +17,9 @@ package interviewcake import ( - "reflect" "testing" + + "github.com/hoanhan101/algo/common" ) func TestReverseWord(t *testing.T) { @@ -34,9 +35,7 @@ func TestReverseWord(t *testing.T) { for _, tt := range tests { result := reverseWord(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/top_scores_test.go b/interviewcake/top_scores_test.go index 001e2c9..82bec58 100644 --- a/interviewcake/top_scores_test.go +++ b/interviewcake/top_scores_test.go @@ -19,8 +19,9 @@ package interviewcake import ( - "reflect" "testing" + + "github.com/hoanhan101/algo/common" ) func TestSortScores(t *testing.T) { @@ -36,9 +37,7 @@ func TestSortScores(t *testing.T) { for _, tt := range tests { result := sortScores(tt.in1, tt.in2) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/interviewcake/word_cloud_test.go b/interviewcake/word_cloud_test.go index c3f1a58..019520f 100644 --- a/interviewcake/word_cloud_test.go +++ b/interviewcake/word_cloud_test.go @@ -19,10 +19,11 @@ package interviewcake import ( - "reflect" "regexp" "strings" "testing" + + "github.com/hoanhan101/algo/common" ) func TestBuildWordCloud(t *testing.T) { @@ -43,9 +44,7 @@ func TestBuildWordCloud(t *testing.T) { for _, tt := range tests { result := buildWordCloud(tt.in) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } } diff --git a/other/balanced_binary_tree_test.go b/other/balanced_binary_tree_test.go index 3849527..b9876d1 100644 --- a/other/balanced_binary_tree_test.go +++ b/other/balanced_binary_tree_test.go @@ -25,7 +25,6 @@ package other import ( - "reflect" "testing" "github.com/hoanhan101/algo/common" @@ -74,10 +73,8 @@ func TestIsBalanced(t *testing.T) { for _, tt := range tests { h := height(tt.in) b := isBalanced(tt.in) - if !reflect.DeepEqual(h, tt.height) && !reflect.DeepEqual(b, tt.balanced) { - t.Errorf("should be %v instead %v", tt.height, h) - t.Errorf("should be %v instead %v", tt.balanced, b) - } + common.Equal(t, tt.height, h) + common.Equal(t, tt.balanced, b) } } diff --git a/other/binary_tree_traverse_test.go b/other/binary_tree_traverse_test.go index 2e247d8..3b7507d 100644 --- a/other/binary_tree_traverse_test.go +++ b/other/binary_tree_traverse_test.go @@ -7,7 +7,6 @@ package other import ( - "reflect" "testing" "github.com/hoanhan101/algo/common" @@ -67,9 +66,7 @@ func TestBinaryTreeTraverse(t *testing.T) { for _, tt := range tests { result := common.ChanToSlice(tt.c) - if !reflect.DeepEqual(result, tt.expected) { - t.Errorf("should be %v instead %v", tt.expected, result) - } + common.Equal(t, tt.expected, result) } }