-
Notifications
You must be signed in to change notification settings - Fork 0
/
damm_test.go
55 lines (44 loc) · 990 Bytes
/
damm_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 TestDammCheck(t *testing.T) {
var dm Damm
c, err := dm.Check("5724")
if c != true || err != nil {
t.Errorf("Check(5724) != true, got %v (%v)", c, err)
}
}
func TestDammCompute(t *testing.T) {
var dm Damm
c, s, err := dm.Compute("572")
if c != 4 || err != nil {
t.Errorf("Compute(572) != 4, got %v, %v (%v)", c, s, err)
}
}
func TestDammInvalid(t *testing.T) {
var dm Damm
c, err := dm.Check("57A24")
if c != false || err == nil {
t.Errorf("Check(57A24) != false, got %v (%v)", c, err)
}
}
func BenchmarkDamm(b *testing.B) {
var dm Damm
//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, _ = dm.Compute(s)
if checks, _ = dm.Check(ns); checks != true {
b.Errorf("%v: failed, which should never have happened...", i)
}
//b.StopTimer()
}
}