Skip to content

Instantly share code, notes, and snippets.

@Imater
Created August 26, 2014 03:20
Show Gist options
  • Save Imater/03ea28d5aaa52127b28e to your computer and use it in GitHub Desktop.
Save Imater/03ea28d5aaa52127b28e to your computer and use it in GitHub Desktop.
Table tests for go
package main
import (
"testing"
)
func TestAdd(t *testing.T) {
if add(2,3,4,5,6) != 20 {
t.Error("Bad test")
}
}
func TestAdd2(t *testing.T) {
tests := []struct {
a, b, answer int
}{
{1, 2, 3},
{2, 5, 7},
{3, 5, 8},
}
for _, test := range tests {
if add(test.a, test.b) != test.answer {
t.Errorf("Error in %v", test)
}
}
}
func ExampleMain() {
main()
// Output: v%!(EXTRA int=20)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment