Created
August 26, 2014 03:20
-
-
Save Imater/03ea28d5aaa52127b28e to your computer and use it in GitHub Desktop.
Table tests for go
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 ( | |
"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