aboutsummaryrefslogtreecommitdiff
path: root/verify.go
diff options
context:
space:
mode:
Diffstat (limited to 'verify.go')
-rw-r--r--verify.go24
1 files changed, 14 insertions, 10 deletions
diff --git a/verify.go b/verify.go
index db616ca..ffdc816 100644
--- a/verify.go
+++ b/verify.go
@@ -1,21 +1,25 @@
package main
import (
- "container/list"
"fmt"
"math"
"math/rand"
"time"
)
-type function func(*list.Element, *list.Element) *list.Element
-
func init() {
rand.Seed(time.Now().Unix())
}
+var f = map[string]func(Element, Element) Element{
+ "+": add,
+ "-": sub,
+ "*": times,
+ "^": pot,
+}
+
// verify perfoms tests
-func verify(op string, f function) (string, bool) {
+func verify(op string) (string, bool) {
var mm, nn, rr int
switch op {
case "+":
@@ -40,15 +44,15 @@ func verify(op string, f function) (string, bool) {
}
m := scan(mm)
n := scan(nn)
- r := f(m, n)
+ r := f[op](m, n)
expected := scan(rr)
ok := r.Value == expected.Value
- return fmt.Sprint(m.Value, op, n.Value, "=", r.Value), ok
+ return fmt.Sprint(m, op, n, "=", r), ok
}
func verifyAll() {
- fmt.Println(verify("+", add))
- fmt.Println(verify("-", sub))
- fmt.Println(verify("*", times))
- fmt.Println(verify("^", pot))
+ fmt.Println(verify("+"))
+ fmt.Println(verify("-"))
+ fmt.Println(verify("*"))
+ fmt.Println(verify("^"))
}