aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-04-08 00:58:37 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-04-08 00:58:37 +0200
commit0420551036549f21eab1c1849eb68fe3440f408a (patch)
tree36d7649142d9f137d8b07fa351b5792121a9edba
parentff06b99475a8ec7f5673e5f6e6701919e98f8b21 (diff)
Tweak testing
-rw-r--r--ops_test.go32
-rw-r--r--verify.go13
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))
}