aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ops_test.go27
-rw-r--r--verify.go7
2 files changed, 31 insertions, 3 deletions
diff --git a/ops_test.go b/ops_test.go
new file mode 100644
index 0000000..cd907b3
--- /dev/null
+++ b/ops_test.go
@@ -0,0 +1,27 @@
+package main
+
+import "testing"
+
+func TestAdd(t *testing.T) {
+ if !verify("+", add) {
+ t.Error("add failed")
+ }
+}
+
+func TestSub(t *testing.T) {
+ if !verify("-", sub) {
+ t.Error("sub failed")
+ }
+}
+
+func TestTimes(t *testing.T) {
+ if !verify("*", times) {
+ t.Error("times failed")
+ }
+}
+
+func TestPot(t *testing.T) {
+ if !verify("^", pot) {
+ t.Error("pot failed")
+ }
+}
diff --git a/verify.go b/verify.go
index cedfd98..0212391 100644
--- a/verify.go
+++ b/verify.go
@@ -15,7 +15,7 @@ func init() {
}
// verify perfoms tests
-func verify(op string, f function) {
+func verify(op string, f function) bool {
var mm, nn, rr int
switch op {
case "+":
@@ -42,8 +42,9 @@ func verify(op string, f function) {
n := scan(nn)
r := f(m, n)
expected := scan(rr)
- fmt.Println(m.Value, op, n.Value, "=", r.Value,
- r.Value == expected.Value)
+ ok := r.Value == expected.Value
+ fmt.Println(m.Value, op, n.Value, "=", r.Value, ok)
+ return ok
}
func verifyAll() {