aboutsummaryrefslogtreecommitdiff
path: root/verify.go
diff options
context:
space:
mode:
Diffstat (limited to 'verify.go')
-rw-r--r--verify.go45
1 files changed, 12 insertions, 33 deletions
diff --git a/verify.go b/verify.go
index 7c2a4c8..ffb4c54 100644
--- a/verify.go
+++ b/verify.go
@@ -22,28 +22,28 @@ func init() {
var cases = map[string]testCase{
"+": testCase{
function: Add,
- expect: testAdd,
+ expect: expectAdd,
maxm: 100,
maxn: 100,
order: false,
},
"*": testCase{
function: Mul,
- expect: testMul,
+ expect: expectMul,
maxm: 10,
maxn: 10,
order: false,
},
"^": testCase{
function: Pot,
- expect: testPot,
+ expect: expectPot,
maxm: 10,
maxn: 3,
order: false,
},
"-": testCase{
function: Sub,
- expect: testSub,
+ expect: expectSub,
maxm: 100,
maxn: 100,
order: true,
@@ -63,42 +63,21 @@ func verify(op string) (string, bool) {
}
e := c.expect(m, n)
- me := scan(m)
- ne := scan(n)
- ee := scan(e)
+ me := Scan(m)
+ ne := Scan(n)
+ ee := Scan(e)
re := c.function(me, ne)
- return fmt.Sprint(me, op, ne, "=", re), re.equals(ee)
+ return fmt.Sprint(me, op, ne, "=", re), re.Equals(ee)
}
-func scan(n int) Element {
- if n > alphabet.Len() {
- log.Fatal("out of range ", n)
- return Element{}
- }
- e := alphabet.Front()
- for i := 0; i < n; i++ {
- e = e.Next()
- }
- return Element{e}
-}
-
-func testAdd(m, n int) int { return m + n }
-func testMul(m, n int) int { return m * n }
-func testPot(m, n int) int { return int(math.Pow(float64(m), float64(n))) }
-func testSub(m, n int) int { return m - n }
+func expectAdd(m, n int) int { return m + n }
+func expectMul(m, n int) int { return m * n }
+func expectPot(m, n int) int { return int(math.Pow(float64(m), float64(n))) }
+func expectSub(m, n int) int { return m - n }
func verifyAll() {
for op := range cases {
fmt.Println(verify(op))
}
}
-
-// String pretty-prints value
-func (m Element) String() string {
- return fmt.Sprint(m.Value)
-}
-
-func (m Element) equals(n Element) bool {
- return m.Value == n.Value
-}