Last active
April 14, 2017 17:07
-
-
Save mattmc3/6c6cd13bb96c0e7a20ca285ad7762ee8 to your computer and use it in GitHub Desktop.
Go: unittest file template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"reflect" | |
"testing" | |
) | |
func TestMath(t *testing.T) { | |
var tests = []struct { | |
input []int | |
expected int | |
}{ | |
{[]int{2, 2}, 4}, | |
{[]int{1, 2, 3}, 6}, | |
} | |
for _, tt := range tests { | |
actual := 0 | |
for _, item := range tt.input { | |
actual += item | |
} | |
if !reflect.DeepEqual(actual, tt.expected) { | |
t.Errorf(`Sum(%#v) == %#v; want %#v`, tt.input, actual, tt.expected) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment