~mendelmaleh/checksum

ref: e71e2f6f91dd70e3fd9fce07672614204fce5348 checksum/verhoeff_test.go -rw-r--r-- 705 bytes
e71e2f6fMendel E Initial commit 1 year, 3 months ago
                                                                                
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
package checksum

import (
	"math/rand"
	"testing"
)

func TestVerhoeff(t *testing.T) {
	cases := []int{2363}

	for i, test := range cases {
		if !Verhoeff(test) {
			t.Errorf("Verhoeff [%d] (%d) failed", i, test)
		}
	}
}

func TestGetVerhoeff(t *testing.T) {
	cases := []struct {
		num, check int
	}{
		{236, 3},
	}

	for i, test := range cases {
		if res := GetVerhoeff(test.num); res != test.check {
			t.Errorf("GetVerhoeff [%d] (%d): expected check %d, got %d", i, test.num, test.check, res)
		}
	}
}

func BenchmarkVerhoeff(b *testing.B) {
	for n := 0; n < b.N; n++ {
		Verhoeff(rand.Int())
	}
}

func BenchmarkGetVerhoeff(b *testing.B) {
	for n := 0; n < b.N; n++ {
		GetVerhoeff(rand.Int())
	}
}