Skip to content

Instantly share code, notes, and snippets.

@famasoon
Created April 20, 2019 09:19
Show Gist options
  • Save famasoon/478e41557a16b78ae6588c8c1e42cde7 to your computer and use it in GitHub Desktop.
Save famasoon/478e41557a16b78ae6588c8c1e42cde7 to your computer and use it in GitHub Desktop.
package twosum
import (
"reflect"
"testing"
)
type testCase struct {
array []int
target int
}
func TestTwoSum(t *testing.T) {
tests := []struct {
input testCase
output []int
}{
{testCase{[]int{2, 7, 11, 15}, 9}, []int{0, 1}},
{testCase{[]int{2, 3, 4, 11, 15}, 6}, []int{0, 2}},
}
for i, tt := range tests {
sum := twoSum(tt.input.array, tt.input.target)
if !reflect.DeepEqual(sum, tt.output) {
t.Errorf("tests[%d] failed - input: %+v - answer: %+v output: %d¥n", i, tt.input.array, tt.output, sum)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment