Created
December 29, 2010 22:41
-
-
Save fzmaster/759165 to your computer and use it in GitHub Desktop.
Calcular digito verificador do ISBN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
def ISBN(isbn): | |
""" | |
Autor: fzmaster | |
Data: 29/12/2010 | |
Problema: Books for Mars | |
http://codingkata.org/katas/unit/mars-books | |
Calcular digito verificador do ISBN | |
""" | |
return (10-(3*(int(isbn[1]) + int(isbn[3]) + int(isbn[5]) + int(isbn[7]) + int(isbn[9]) + int(isbn[11])) + int(isbn[0]) + int(isbn[2]) + int(isbn[4]) + int(isbn[6]) + int(isbn[8]) + int(isbn[10])) % 10) % 10 | |
class ISBNTestCase(unittest.TestCase): | |
def test_caso1(self): | |
assert ISBN('978030640615') == 7 | |
def test_caso2(self): | |
assert ISBN('978857780013') == 1 | |
def test_caso3(self): | |
assert ISBN('978857522247') == 8 | |
def test_caso4(self): | |
assert ISBN('978857522212') == 6 | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment