Skip to content

Instantly share code, notes, and snippets.

@jsocol
Created July 22, 2019 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsocol/3ac33fe56bf4bbbc2c0b12e50ba0d748 to your computer and use it in GitHub Desktop.
Save jsocol/3ac33fe56bf4bbbc2c0b12e50ba0d748 to your computer and use it in GitHub Desktop.
#golang test subcases
package ex
import (
"fmt"
"testing"
)
func Multiplier(in int) int {
return in * 2
}
func makeMultiplierTest(input, wanted int) func(*testing.T) {
return func(t *testing.T) {
if Multiplier(input) != wanted {
t.Errorf("Multiplier(%v) == (%v)", input, wanted)
}
}
}
func TestMultiplier(t *testing.T) {
testCases := []struct {
input int
wanted int
}{
{
input: 5,
wanted: 10,
},
{
input: 2,
wanted: 4,
},
{
input: 3,
wanted: 7,
},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("Multiplier(%d)", tc.input), makeMultiplierTest(tc.input, tc.wanted))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment