1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| package main
import ( "testing"
"github.com/stretchr/testify/assert" )
type question struct { p parameter a answer }
type parameter struct { first []int second int }
type answer struct { first []int }
func TestProblem(t *testing.T) { questions := []question{ question{ p: parameter{ first: []int{2, 7, 11, 15}, second: 9, }, a: answer{ first: []int{0, 1}, }, }, question{ p: parameter{ first: []int{2, 7, 11, 15}, second: 8, }, a: answer{ first: []int{}, }, }, }
for _, q := range questions { a, p := q.a, q.p assert.Equal(t, a.first, twoSum(p.first, p.second)) } }
|