From 02521dca0b0058954e3f288183e75c1c4008da45 Mon Sep 17 00:00:00 2001 From: Nishi Davidson Date: Mon, 30 Mar 2020 17:14:58 -0700 Subject: [PATCH] add table driven test format --- static-array/static-array_test.go | 33 ++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/static-array/static-array_test.go b/static-array/static-array_test.go index fac39fb..08db07d 100644 --- a/static-array/static-array_test.go +++ b/static-array/static-array_test.go @@ -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") + } + }) } } -