Skip to content

Commit

Permalink
use custom test assert helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoanh An committed Oct 13, 2019
1 parent f155f88 commit 63f5f4a
Show file tree
Hide file tree
Showing 23 changed files with 54 additions and 95 deletions.
7 changes: 3 additions & 4 deletions interviewcake/2nd_largest_item_bst_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
)

func Test2ndLargestItem(t *testing.T) {
Expand Down Expand Up @@ -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)
}
}

Expand Down
5 changes: 1 addition & 4 deletions interviewcake/apple_stocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
Expand All @@ -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)
}
}

Expand Down
5 changes: 1 addition & 4 deletions interviewcake/balanced_binary_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
Expand Down Expand Up @@ -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)
}
}

Expand Down
7 changes: 3 additions & 4 deletions interviewcake/binary_search_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ package interviewcake

import (
"math"
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
)

func TestIsBinarySearchTree(t *testing.T) {
Expand Down Expand Up @@ -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)
}
}

Expand Down
3 changes: 2 additions & 1 deletion interviewcake/bracket_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
7 changes: 3 additions & 4 deletions interviewcake/fibonacci_number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
)

func TestFib(t *testing.T) {
Expand All @@ -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)
}
}

Expand Down
7 changes: 3 additions & 4 deletions interviewcake/find_rotation_point_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
)

func TestFindRotationPoint(t *testing.T) {
Expand Down Expand Up @@ -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)
}
}

Expand Down
5 changes: 1 addition & 4 deletions interviewcake/graph_coloring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
Expand Down Expand Up @@ -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)
}
}

Expand Down
5 changes: 1 addition & 4 deletions interviewcake/highest_product_of_three_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
Expand All @@ -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)
}
}

Expand Down
7 changes: 3 additions & 4 deletions interviewcake/inflight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
)

func TestFillFlight(t *testing.T) {
Expand All @@ -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)
}
}

Expand Down
5 changes: 1 addition & 4 deletions interviewcake/inplace_shuffle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
Expand All @@ -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)
}
}

Expand Down
13 changes: 4 additions & 9 deletions interviewcake/making_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
)

func TestMakeChange(t *testing.T) {
Expand Down Expand Up @@ -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)
}
}

Expand Down
5 changes: 1 addition & 4 deletions interviewcake/merge_meetings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package interviewcake

import (
"reflect"
"sort"
"testing"

Expand All @@ -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)
}
}

Expand Down
7 changes: 3 additions & 4 deletions interviewcake/merge_sorted_arrays_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
)

func TestMergeSortedArray(t *testing.T) {
Expand Down Expand Up @@ -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)
}
}

Expand Down
7 changes: 3 additions & 4 deletions interviewcake/permutation_palindrome_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
)

func TestHasPalindromePermutation(t *testing.T) {
Expand All @@ -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)
}
}

Expand Down
7 changes: 3 additions & 4 deletions interviewcake/product_of_others_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
)

func TestGetProductOfOthers(t *testing.T) {
Expand All @@ -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)
}
}

Expand Down
7 changes: 3 additions & 4 deletions interviewcake/recursive_string_permutation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package interviewcake

import (
"reflect"
"strings"
"testing"

"github.com/hoanhan101/algo/common"
)

func TestPermuteString(t *testing.T) {
Expand All @@ -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)
}
}

Expand Down
7 changes: 3 additions & 4 deletions interviewcake/reverse_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
)

func TestReverseString(t *testing.T) {
Expand All @@ -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)
}
}

Expand Down
7 changes: 3 additions & 4 deletions interviewcake/reverse_word_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package interviewcake

import (
"reflect"
"testing"

"github.com/hoanhan101/algo/common"
)

func TestReverseWord(t *testing.T) {
Expand All @@ -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)
}
}

Expand Down
Loading

0 comments on commit 63f5f4a

Please sign in to comment.