Skip to content

Instantly share code, notes, and snippets.

@marklap
Last active August 29, 2015 14:01
Show Gist options
  • Save marklap/9df458b8494760bb94f7 to your computer and use it in GitHub Desktop.
Save marklap/9df458b8494760bb94f7 to your computer and use it in GitHub Desktop.
Messing around with unit testing in Go
package main
import "testing"
func TestMain(t *testing.T) {
something := -1
if testing.Short() {
t.Skip("Skipping this stupid test")
}
if something > 0 {
t.Errorf("This freakin' thing is more than zero!")
} else if something < 0 {
t.Errorf("Crap! Less than zero!")
}
}
func BenchmarkAppendAuto(b *testing.B) {
j := []int{}
for i := 0; i < b.N; i++ {
j = append(j, i)
}
}
func BenchmarkAppendStatic(b *testing.B) {
j := make([]int, b.N, b.N)
for i := 0; i < b.N; i++ {
j[i] = i
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment