aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-09-09 00:58:28 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-09-09 00:58:28 +0200
commit20159c986ff904e7f23ba69337c767ced25951d2 (patch)
tree652c6da69e4b46fd1ba80aaadb4ec18f76b74315
parent79189d25ecd077cc308d24c8c0919d2094cf8be3 (diff)
...
-rw-r--r--ops_test.go53
1 files changed, 26 insertions, 27 deletions
diff --git a/ops_test.go b/ops_test.go
index a20ea3f..b0338fb 100644
--- a/ops_test.go
+++ b/ops_test.go
@@ -11,55 +11,54 @@ func TestOp(t *testing.T) {
rand.Seed(time.Now().UnixNano())
testCases := map[string]struct {
- function func(Element, Element) Element
- expect func(int, int) int
+ f func(Element, Element) Element
+ ref func(int, int) int
maxm, maxn int
- order bool
+ ordered bool
}{
"+": {
- function: Add,
- expect: func(m, n int) int { return m + n },
- maxm: 100,
- maxn: 100,
- order: false,
+ f: Add,
+ ref: func(m, n int) int { return m + n },
+ maxm: 100,
+ maxn: 100,
+ ordered: false,
},
"*": {
- function: Mul,
- expect: func(m, n int) int { return m * n },
- maxm: 10,
- maxn: 10,
- order: false,
+ f: Mul,
+ ref: func(m, n int) int { return m * n },
+ maxm: 10,
+ maxn: 10,
+ ordered: false,
},
"^": {
- function: Pow,
- expect: func(m, n int) int { return int(math.Pow(float64(m), float64(n))) },
- maxm: 10,
- maxn: 3,
- order: false,
+ f: Pow,
+ ref: func(m, n int) int { return int(math.Pow(float64(m), float64(n))) },
+ maxm: 10,
+ maxn: 3,
+ ordered: false,
},
"-": {
- function: Sub,
- expect: func(m, n int) int { return m - n },
- maxm: 100,
- maxn: 100,
- order: true,
+ f: Sub,
+ ref: func(m, n int) int { return m - n },
+ maxm: 100,
+ maxn: 100,
+ ordered: true,
},
}
for op, tc := range testCases {
t.Run(op, func(t *testing.T) {
-
m := rand.Intn(tc.maxm)
n := rand.Intn(tc.maxn)
- if tc.order && n > m {
+ if tc.ordered && n > m {
m, n = n, m
}
- e := tc.expect(m, n)
+ e := tc.ref(m, n)
me := Index(m)
ne := Index(n)
ee := Index(e)
- re := tc.function(me, ne)
+ re := tc.f(me, ne)
if !re.Equals(ee) {
t.Errorf("%v %v %v: got %v, want %v", me, op, ne, re, ee)