예제 #1
0
 def test_even(self) -> None:
     """Calculate even parity check digit."""
     assert parity.calculate("0110") == "0"
     assert parity.calculate("0") == "0"
     assert parity.calculate("01101") == "1"
예제 #2
0
 def test_odd(self) -> None:
     """Calculate odd parity check digit."""
     assert parity.calculate("0110", False) == "1"
     assert parity.calculate("0", False) == "1"
     assert parity.calculate("01101", False) == "0"
예제 #3
0
# checkdigit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with checkdigit.  If not, see <http://www.gnu.org/licenses/>.

from error404 import test

import checkdigit.isbn as isbn
import checkdigit.luhn as luhn
import checkdigit.parity as parity
import checkdigit.upc as upc

# Even parity
test(parity.calculate("0110"), "01100")
test(parity.calculate("0"), "00")
test(parity.calculate("01101"), "011011")

# Odd parity
test(parity.calculate("0110", False), "01101")
test(parity.calculate("0", False), "01")
test(parity.calculate("01101", False), "011010")

# ISBN-10 Check digit
test(isbn.calculate10("006196436"), "0")
test(isbn.calculate10("190592105"), "5")
test(isbn.calculate10("043942089"), "X")

# Validate ISBN-10
test(isbn.validate10("0205080057"))