I'm trying to write a simple test to get a better understanding of golang testing but the test case doesn't seem to execute and I'm expecting it to fail.
In my main.go
I have:
package main
import "fmt"
func main() {
fmt.Println("run")
}
func twoSum(nums []int, target int) []int {
lookup := make(map[int]int)
for i, n := range nums {
c := target - n
if j, ok := lookup[c]; ok {
return []int{j, i}
}
lookup[n] = i
}
return []int{}
}
and then in my main_test.go
I have this:
package main
import (
"reflect"
"testing"
)
var twoSumsCases = []struct{
input []int
target int
expected []int
} {
{
[]int{2,7,11,15},
9,
[]int{0,3},
},
}
func TesttwoSum(t *testing.T) {
for _, tc := range twoSumsCases {
actual := twoSum(tc.input, tc.target)
eq := reflect.DeepEqual(actual, tc.expected)
if eq {
t.Log("expected: ", tc.expected, " actual: ", actual)
} else {
t.Error("expected: ", tc.expected, " actual: ", actual)
}
}
}
then when I run go test -v
...it tells me that testing: warning: no tests to run
. I looked at this as an example: https://blog.alexellis.io/golang-writing-unit-tests/...and I think i got everything I need to but not sure why the test isn't executing.