~mendelmaleh/checksum

checksum/damm_test.go -rw-r--r-- 798 bytes
3c2ecf21Mendel E Luhn optimizations 11 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
43
44
45
46
47
48
49
50
package checksum

import (
	"math/rand"
	"testing"
)

func TestDamm(t *testing.T) {
	cases := []struct {
		num int
		ok  bool
	}{
		{5724, true},
	}

	for i, test := range cases {
		if Damm(test.num) != test.ok {
			t.Errorf("TestDamm [%d] (%d): expected test to return %t", i, test.num, test.ok)
		}
	}
}

func TestGetDamm(t *testing.T) {
	cases := []struct {
		num, check int
	}{
		{5, 9},
		{57, 7},
		{572, 4},
		{5720, 6},
	}

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

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

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