Skip to content

Commit

Permalink
v0.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
harens committed Nov 29, 2020
1 parent caf07de commit 2e3c0eb
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 6 additions & 8 deletions checkdigit/isbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions checkdigit/luhn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions checkdigit/upc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
maintainers = ["harens <[email protected]>"]
Expand Down
7 changes: 7 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand All @@ -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)
Expand Down

0 comments on commit 2e3c0eb

Please sign in to comment.