Skip to content

Commit

Permalink
ci: ajustes formatação brazilian-utils#430 is_valid_renavam
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasAlvws committed Oct 23, 2024
1 parent b287349 commit 347fb94
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
14 changes: 7 additions & 7 deletions brutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@
remove_symbols as remove_symbols_pis,
)

# RENAVAM Imports
from brutils.renavam import (
is_valid_renavam,
)

# Voter ID Imports
from brutils.voter_id import (
format_voter_id,
Expand All @@ -122,11 +127,6 @@
is_valid as is_valid_voter_id,
)

# RENAVAM Imports
from brutils.renavam import (
is_valid_renavam,
)

# Defining __all__ to expose the public methods
__all__ = [
# CEP
Expand Down Expand Up @@ -178,5 +178,5 @@
# IBGE
"convert_code_to_uf",
# RENAVAM
'is_valid_renavam',
]
"is_valid_renavam",
]
7 changes: 5 additions & 2 deletions brutils/renavam.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ def is_valid_renavam(renavam): # type: (str) -> bool
renavam_digitis = [int(d) for d in renavam]
renavam_digitis = renavam_digitis[:-1]
multipliers = [2, 3, 4, 5, 6, 7, 8, 9, 2, 3]
sum_digits = sum(digit * multipliers[i] for i, digit in enumerate(renavam_digitis[::-1]))
sum_digits = sum(
digit * multipliers[i]
for i, digit in enumerate(renavam_digitis[::-1])
)
remainder_division = sum_digits % 11
if remainder_division <= 1:
check_digit_calculated = 0
else:
check_digit_calculated = 11 - remainder_division
if check_digit == check_digit_calculated:
return True
return False
return False
51 changes: 27 additions & 24 deletions tests/test_renavam.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
from unittest import TestCase

from brutils.renavam import is_valid_renavam


class TestRENAVAM(TestCase):
def test_is_valid_renavam(self):
# Testes para RENAVAM válidos
self.assertFalse(is_valid_renavam('12345678901'))
self.assertFalse(is_valid_renavam('09945438645'))
self.assertFalse(is_valid_renavam('94521237655'))
self.assertFalse(is_valid_renavam('45403264305'))
self.assertFalse(is_valid_renavam('45403471665'))
self.assertFalse(is_valid_renavam('34743721835'))
self.assertFalse(is_valid_renavam('69277208515'))
self.assertFalse(is_valid_renavam("12345678901"))
self.assertFalse(is_valid_renavam("09945438645"))
self.assertFalse(is_valid_renavam("94521237655"))
self.assertFalse(is_valid_renavam("45403264305"))
self.assertFalse(is_valid_renavam("45403471665"))
self.assertFalse(is_valid_renavam("34743721835"))
self.assertFalse(is_valid_renavam("69277208515"))

self.assertTrue(is_valid_renavam('12345678900'))
self.assertTrue(is_valid_renavam('92876838150'))
self.assertTrue(is_valid_renavam('65720648534'))
self.assertTrue(is_valid_renavam('63601073019'))
self.assertTrue(is_valid_renavam('09945438641'))
self.assertTrue(is_valid_renavam('94521237651'))
self.assertTrue(is_valid_renavam('45403264308'))
self.assertTrue(is_valid_renavam('45403471664'))
self.assertTrue(is_valid_renavam('34743721831'))
self.assertTrue(is_valid_renavam('69277208510'))
self.assertTrue(is_valid_renavam("12345678900"))
self.assertTrue(is_valid_renavam("92876838150"))
self.assertTrue(is_valid_renavam("65720648534"))
self.assertTrue(is_valid_renavam("63601073019"))
self.assertTrue(is_valid_renavam("09945438641"))
self.assertTrue(is_valid_renavam("94521237651"))
self.assertTrue(is_valid_renavam("45403264308"))
self.assertTrue(is_valid_renavam("45403471664"))
self.assertTrue(is_valid_renavam("34743721831"))
self.assertTrue(is_valid_renavam("69277208510"))

# Testes para entradas inválidas
self.assertFalse(is_valid_renavam('1234567890a')) # Contém letra
self.assertFalse(is_valid_renavam('12345678 901')) # Contém espaço
self.assertFalse(is_valid_renavam('12345678')) # Menos de 11 dígitos
self.assertFalse(is_valid_renavam('')) # String vazia
self.assertFalse(is_valid_renavam('123456789012')) # Mais de 11 dígitos
self.assertFalse(is_valid_renavam('abcdefghijk')) # Apenas letras
self.assertFalse(is_valid_renavam('12345678901!')) # Contém caractere especial
self.assertFalse(is_valid_renavam("1234567890a")) # Contém letra
self.assertFalse(is_valid_renavam("12345678 901")) # Contém espaço
self.assertFalse(is_valid_renavam("12345678")) # Menos de 11 dígitos
self.assertFalse(is_valid_renavam("")) # String vazia
self.assertFalse(is_valid_renavam("123456789012")) # Mais de 11 dígitos
self.assertFalse(is_valid_renavam("abcdefghijk")) # Apenas letras
self.assertFalse(
is_valid_renavam("12345678901!")
) # Contém caractere especial
self.assertFalse(is_valid_renavam(None)) # Contém caractere especial

0 comments on commit 347fb94

Please sign in to comment.