Skip to content

Commit

Permalink
add table driven test format
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishi Davidson authored and Nishi Davidson committed Mar 31, 2020
1 parent 3751154 commit 02521dc
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions static-array/static-array_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
package main

import (
"testing"
"reflect"
"testing"
)

func TestCreateArr(t *testing.T) {
got := CreateArr()
want:= []int{1,2,5,7,9}
var tests = []struct {
name string
out []int
want bool
}{
{
name: "equals",
out: []int{1, 2, 5, 7, 9},
want: true,
},
{
name: "not equals",
out: []int{1, 1, 4, 7, 9},
want: false,
},
}

if !reflect.DeepEqual(got, want) {
t.Errorf("got %q want %q", got,want)
func TestCreateArr(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := CreateArr()
equals := reflect.DeepEqual(got, tt.out)
if equals != tt.want {
t.Errorf("test failed")
}
})
}
}

0 comments on commit 02521dc

Please sign in to comment.