-
Notifications
You must be signed in to change notification settings - Fork 0
/
verhoeff_test.go
55 lines (44 loc) · 1022 Bytes
/
verhoeff_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package checksum
import (
"math/rand"
"strconv"
"testing"
)
func TestVerhoeffCheck(t *testing.T) {
var vh Verhoeff
c, err := vh.Check("2363")
if c != true || err != nil {
t.Errorf("Check(2363) != true, got %v (%v)", c, err)
}
}
func TestVerhoeffCompute(t *testing.T) {
var vh Verhoeff
c, s, err := vh.Compute("236")
if c != 3 || err != nil {
t.Errorf("Compute(236) != 3, got %v, %v (%v)", c, s, err)
}
}
func TestVerhoeffInvalid(t *testing.T) {
var vh Verhoeff
c, err := vh.Check("2A363")
if c != false || err == nil {
t.Errorf("Check(23A63) != false, got %v (%v)", c, err)
}
}
func BenchmarkVerhoeff(b *testing.B) {
var vh Verhoeff
//b.StopTimer()
from := rand.Intn(1000000000) + 1000000000
to := from + b.N
for i := from; i <= to; i++ {
var s, ns string
var checks bool
s = strconv.Itoa(i)
//b.StartTimer()
_, ns, _ = vh.Compute(s)
if checks, _ = vh.Check(ns); checks != true {
b.Errorf("%v: failed, which should never have happened...", i)
}
//b.StopTimer()
}
}