Corrigido calculo DV

master
Paulo Simão 2021-09-30 17:18:47 -03:00
parent aa95d54618
commit ca32d00e35
2 changed files with 14 additions and 3 deletions

View File

@ -39,8 +39,12 @@ func Check(s string) bool {
d1 = d1 + (v * mul)
mul--
}
mod1 := (d1 * 10) % 11
mod1 := (d1) % 11
if mod1 < 2 {
mod1 = 0
} else {
mod1 = 11 - mod1
}
d2 := 0
mul = 11
for _, v := range nums[0 : len(nums)-2] {
@ -49,6 +53,11 @@ func Check(s string) bool {
}
d2 = d2 + (mod1 * mul)
mod2 := (d2 * 10) % 11
mod2 := (d2) % 11
if mod2 < 2 {
mod2 = 0
} else {
mod2 = 11 - mod2
}
return mod1 == nums[len(nums)-2] && mod2 == nums[len(nums)-1]
}

View File

@ -15,6 +15,8 @@ func TestCheck(t *testing.T) {
"377.100.400-46",
"845.846.910-37",
"845.846.910-17",
"39412818602",
"768.974.608-00",
} {
ret := Check(v)
log.Printf("%s=>%v", v, ret)