diff --git a/README.md b/README.md index 5a79dfe..c02606d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Or download the project [here](https://github.com/harens/checkdigit/archive/mast * Extensive __in-code comments and docstrings__ to explain how the functions work * Written in __pure Python__ with __no dependencies__ required to run the program -Check out the [wiki](https://github.com/harens/checkdigit/wiki) for more details on how to use the library +Check out the [documentation](https://github.com/harens/checkdigit/wiki) for more details on how to use the library ## License This project is licensed under the [GNU General Public License v3.0](https://github.com/harens/checkdigit/blob/master/LICENSE) diff --git a/checkdigit/isbn.py b/checkdigit/isbn.py index c4878f7..b2de707 100644 --- a/checkdigit/isbn.py +++ b/checkdigit/isbn.py @@ -49,16 +49,14 @@ def validate10(data: str) -> bool: """ data = cleanse(data) - return ( - calculate10(data[:9]) == data[-1] - ) # Determines if calculated Check Digit of the data is the last digit given + return calculate10(data[:-1]) == data[-1] def calculate13(data: str, barcode: str = "isbn") -> str: """Calculates ISBN-13 Check Digit Args: - data: A string of 10 characters + data: A string of 12 characters barcode: The type of code (either isbn or upc) Returns: @@ -86,21 +84,21 @@ def validate13(data: str) -> bool: data: A string of characters representing a full ISBN-13 code Returns: - bool: A boolean representing if the check digit validates the data + bool: A boolean representing whether the check digit validates the data """ data = cleanse(data) - return calculate13(data[:12]) == data[-1] + return calculate13(data[:-1]) == data[-1] def missing(data: str) -> str: """Calculates a missing digit in an ISBN Code Args: - data: A string of characters representing a full ISBN code with a question mark for a missing character + data: A string of characters representing a full ISBN code with a question mark representing a missing character Returns: - str: The missing value that should be where the question mark is + str: The missing value that should've been where the question mark was """ data = cleanse(data) diff --git a/checkdigit/luhn.py b/checkdigit/luhn.py index 05e8c77..ba53a34 100644 --- a/checkdigit/luhn.py +++ b/checkdigit/luhn.py @@ -55,7 +55,7 @@ def validate(data: str) -> bool: data: A string of characters representing a full luhn code Returns: - bool: A boolean representing if the check digit validates the data + bool: A boolean representing whether the check digit validates the data or not """ data = cleanse(data) @@ -71,7 +71,7 @@ def missing(data: str) -> str: data: A string of characters representing a full luhn code with a question mark for a missing character Returns: - str: The missing value that should be where the question mark is + str: The missing value that should've been where the question mark was """ data = cleanse(data) diff --git a/checkdigit/upc.py b/checkdigit/upc.py index e07fd5a..27216c0 100644 --- a/checkdigit/upc.py +++ b/checkdigit/upc.py @@ -26,10 +26,10 @@ def calculate(data: str) -> str: - """Calculates UPC Check Digit + """Calculates UPC Check Digits Args: - data: A string of UPC digit + data: A string of UPC digits Returns: str: The missing check digit @@ -38,12 +38,12 @@ def calculate(data: str) -> str: def validate(data: str) -> bool: - """Determines if calculated check digit of the data is the last digit given + """Determines if the calculated check digit of the data is the last digit given Args: data: A string of characters representing a full UPC code Returns: - bool: A boolean representing if the check digit validates the data + bool: A boolean representing whether the check digit validates the data or not """ - return calculate(data[:11]) == data[-1] + return calculate(data[:-1]) == data[-1] diff --git a/pyproject.toml b/pyproject.toml index 7cc984d..446c582 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "checkdigit" -version = "1.0.0-alpha.0" +version = "0.1" description = "A check digit library for data validation" authors = ["harens "] maintainers = ["harens "] diff --git a/tests.py b/tests.py index 8caea23..8b903b9 100644 --- a/tests.py +++ b/tests.py @@ -53,6 +53,7 @@ # Validate ISBN-13 test(isbn.validate13("0123456789128")) test(isbn.validate13("9781861978769")) +test(isbn.validate13("9-501101-530003")) test(isbn.validate13("978-1-56619-909-4")) # ISBN-10 Missing Digit @@ -104,6 +105,7 @@ test(luhn.calculate("37266630277430"), "0") test(luhn.calculate("91497796683515"), "3") test(luhn.calculate("10408772972296"), "9") +test(luhn.calculate("950123440000"), "8") # Validate Data test(luhn.validate("541756116585277")) @@ -112,7 +114,12 @@ test(luhn.validate("6011365035868968")) test(luhn.validate("372098369216316")) test(luhn.validate("4556098986775827")) +test(luhn.validate("79927398713")) test(luhn.validate("49927398717"), False) +test(luhn.validate("79927398710"), False) +test(luhn.validate("79927398711"), False) +test(luhn.validate("79927398712"), False) +test(luhn.validate("79927398719"), False) test(luhn.validate("1234567812345678"), False) test(luhn.validate("2222222222222222"), False) test(luhn.validate("111111111111111"), False)