blob: 94b371230071993be223848b08c928ad8a5ec0ea (
plain) (
blame)
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
|
package damm
import (
"log"
"testing"
"github.com/neonxp/checksum"
)
func TestDamm(t *testing.T) {
samples := map[string]error{
"456126121234546": checksum.ErrInvalidChecksum,
"A56126121234546": checksum.ErrInvalidNumber,
"5724": nil,
}
for num, result := range samples {
if err := Check(num); err != result {
t.Errorf("Expected %+v actual %+v for %s", result, err, num)
}
}
num := "572"
checksum, err := Generate(num)
if err != nil {
t.Error(err)
}
numberWithChecksum := num + checksum
log.Println(numberWithChecksum)
if err := Check(numberWithChecksum); err != nil {
t.Errorf("Expected no error actual %+v for %s", err, numberWithChecksum)
}
}
|