-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code and improve documentation
- Loading branch information
1 parent
67aa85a
commit f9001ea
Showing
16 changed files
with
81 additions
and
37 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,4 @@ def isvalidBoolean(self, value)-> bool: | |
return False | ||
|
||
if isinstance(value, bool): | ||
return True | ||
return True |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,3 @@ def toInt(self, value): | |
value = 0 | ||
|
||
return value | ||
|
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class EANCheckSum: | ||
def __init__(self): | ||
pass | ||
|
||
def checksum_ean13(self, value: str) -> bool: | ||
"""Calculate the checksum for the EAN code""" | ||
last_digit = int(value[-1]) | ||
remaining_numbers = value[:-1] | ||
total_sum = sum(int(remaining_numbers[i]) * 3 if i % 2 != 0 else \ | ||
int(remaining_numbers[i]) for i in range(len(remaining_numbers))) | ||
unit_digit = 0 if total_sum % 10 == 0 else 10 - (total_sum % 10) | ||
if unit_digit == last_digit: | ||
return True | ||
|
||
def checksum_ean8(self, value: str) -> bool: | ||
"""Calculate the checksum for the EAN code""" | ||
pass | ||
|
||
def is_valid(self, value: str) -> bool: | ||
"""Check if the EAN code is valid""" | ||
return self.checksum_ean13(value) if len(value) == 13 else self.checksum_ean8(value) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sys | ||
import unittest | ||
sys.path.append('.') | ||
from sanatio import Validator | ||
validator = Validator() | ||
|
||
|
||
class ArrayTest(unittest.TestCase): | ||
def test_isArray_True(self): | ||
self.assertTrue(validator.isArray([])) | ||
self.assertTrue(validator.isArray([1, 2, 3])) | ||
self.assertTrue(validator.isArray(['a', 'b', 'c'])) | ||
|
||
def test_isArray_False(self): | ||
self.assertFalse(validator.isArray('abc')) | ||
self.assertFalse(validator.isArray(123)) | ||
|
||
def test_isLength_True(self): | ||
self.assertTrue(validator.isLength([1, 2, 3], 1, 3)) | ||
self.assertTrue(validator.isLength([1, 2, 3], 3, 3)) | ||
self.assertTrue(validator.isLength([1, 2, 3], 3, 3)) | ||
|
||
def test_isLength_False(self): | ||
self.assertFalse(validator.isLength([1, 2, 3], 1, 2)) | ||
self.assertFalse(validator.isLength([1, 2, 3], 4, 5)) | ||
self.assertFalse(validator.isLength([1, 2, 3], 1, 2)) | ||
|
||
def test_isContains_True(self): | ||
self.assertTrue(validator.isContains([1, 2, 3], 1)) | ||
self.assertTrue(validator.isContains([1, 2, 3], 2)) | ||
self.assertTrue(validator.isContains([1, 2, 3], 3)) | ||
|
||
def test_isContains_False(self): | ||
self.assertFalse(validator.isContains([1, 2, 3], 4)) | ||
self.assertFalse(validator.isContains([1, 2, 3], 5)) | ||
self.assertFalse(validator.isContains([1, 2, 3], 6)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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