Skip to content

Commit

Permalink
Merge pull request #6 from dilowagner/issue-5
Browse files Browse the repository at this point in the history
Ajustando Validacao do estado de SP
  • Loading branch information
dilowagner authored May 11, 2023
2 parents b634884 + 651a194 commit 676c3b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,20 @@ func TestValidatorSPValid(t *testing.T) {
assert.True(t, result)
}

func TestValidatorSPValidWithMod10(t *testing.T) {

validator := NewIEValidator()

validator.IE = "330.062.780.110" // Valido
validator.UF = validators.SP

result, err := validator.Validate()
if err != nil {
t.Error("Erro na validacao do estado de São Paulo")
}
assert.True(t, result)
}

func TestValidatorSPValidWithPLetter(t *testing.T) {

validator := NewIEValidator()
Expand Down
2 changes: 1 addition & 1 deletion validators/sp.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (v SaoPaulo) IsValid(insc string) bool {
weights = []int{3, 2, 10, 9, 8, 7, 6, 5, 4, 3, 2}
total = rule.CalculateTotal(firstBase+firstDigit+secondBase, 11, weights)
mod = rule.CalculateMod(total, 11)
secondDigit := strconv.Itoa(mod)
secondDigit := strconv.Itoa(mod % 10)

return insc == firstBase+firstDigit+secondBase+secondDigit
}

0 comments on commit 676c3b8

Please sign in to comment.