From 0420551036549f21eab1c1849eb68fe3440f408a Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 8 Apr 2015 00:58:37 +0200 Subject: Tweak testing --- ops_test.go | 32 ++++++++++++++++++++++++++++---- verify.go | 13 ++++++------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/ops_test.go b/ops_test.go index cd907b3..2945447 100644 --- a/ops_test.go +++ b/ops_test.go @@ -3,25 +3,49 @@ package main import "testing" func TestAdd(t *testing.T) { - if !verify("+", add) { + if _, ok := verify("+", add); !ok { t.Error("add failed") } } +func BenchmarkAdd(b *testing.B) { + for i := 0; i < b.N; i++ { + verify("+", add) + } +} + func TestSub(t *testing.T) { - if !verify("-", sub) { + if _, ok := verify("-", sub); !ok { t.Error("sub failed") } } +func BenchmarkSub(b *testing.B) { + for i := 0; i < b.N; i++ { + verify("-", sub) + } +} + func TestTimes(t *testing.T) { - if !verify("*", times) { + if _, ok := verify("*", times); !ok { t.Error("times failed") } } +func BenchmarkTimes(b *testing.B) { + for i := 0; i < b.N; i++ { + verify("*", times) + } +} + func TestPot(t *testing.T) { - if !verify("^", pot) { + if _, ok := verify("^", pot); !ok { t.Error("pot failed") } } + +func BenchmarkPot(b *testing.B) { + for i := 0; i < b.N; i++ { + verify("^", pot) + } +} diff --git a/verify.go b/verify.go index 0212391..db616ca 100644 --- a/verify.go +++ b/verify.go @@ -15,7 +15,7 @@ func init() { } // verify perfoms tests -func verify(op string, f function) bool { +func verify(op string, f function) (string, bool) { var mm, nn, rr int switch op { case "+": @@ -43,13 +43,12 @@ func verify(op string, f function) bool { r := f(m, n) expected := scan(rr) ok := r.Value == expected.Value - fmt.Println(m.Value, op, n.Value, "=", r.Value, ok) - return ok + return fmt.Sprint(m.Value, op, n.Value, "=", r.Value), ok } func verifyAll() { - verify("+", add) - verify("-", sub) - verify("*", times) - verify("^", pot) + fmt.Println(verify("+", add)) + fmt.Println(verify("-", sub)) + fmt.Println(verify("*", times)) + fmt.Println(verify("^", pot)) } -- cgit v1.2.3