-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce property-based testing using hypothesis
- Loading branch information
Showing
5 changed files
with
111 additions
and
12 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
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,3 @@ | ||
pytest==4.6.9 | ||
hypothesis==4.57.1 | ||
textdistance==4.1.5 |
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 |
---|---|---|
@@ -1,10 +1,89 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import unicodedata | ||
import unittest | ||
|
||
class TestEditDistance(unittest.TestCase): | ||
def test_editdistance(self): | ||
import editdistance | ||
self.assertEqual(1, editdistance.eval('abc', 'aec')) | ||
|
||
from hypothesis import event, given, strategies as st | ||
|
||
from textdistance import Levenshtein | ||
|
||
|
||
MIN_LENGTH = 0 | ||
MAX_LENGTH = 16 | ||
|
||
|
||
REFERENCE = Levenshtein().distance | ||
|
||
|
||
@given( | ||
str0=st.text( | ||
alphabet=st.characters( | ||
min_codepoint=0, | ||
max_codepoint=127), | ||
min_size=MIN_LENGTH, | ||
max_size=MAX_LENGTH), | ||
str1=st.text( | ||
alphabet=st.characters( | ||
min_codepoint=0, | ||
max_codepoint=127), | ||
min_size=MIN_LENGTH, | ||
max_size=MAX_LENGTH)) | ||
def test_ascii_codes(str0, str1): | ||
norm_str0 = unicodedata.normalize('NFKC', str0) | ||
norm_str1 = unicodedata.normalize('NFKC', str1) | ||
event('eval("{}", "{}")'.format(norm_str0, norm_str1)) | ||
|
||
import editdistance | ||
assert REFERENCE(norm_str0, norm_str1) == \ | ||
editdistance.eval(norm_str0, norm_str1) | ||
|
||
|
||
@given( | ||
str0=st.text( | ||
alphabet=st.characters( | ||
min_codepoint=12354, # あ | ||
max_codepoint=12435), # ん | ||
min_size=MIN_LENGTH, | ||
max_size=MAX_LENGTH), | ||
str1=st.text( | ||
alphabet=st.characters( | ||
min_codepoint=12354, | ||
max_codepoint=12435), | ||
min_size=MIN_LENGTH, | ||
max_size=MAX_LENGTH)) | ||
def test_japanese_hiraganas(str0, str1): | ||
norm_str0 = unicodedata.normalize('NFKC', str0) | ||
norm_str1 = unicodedata.normalize('NFKC', str1) | ||
event('eval("{}", "{}")'.format(norm_str0, norm_str1)) | ||
|
||
import editdistance | ||
assert REFERENCE(norm_str0, norm_str1) == \ | ||
editdistance.eval(norm_str0, norm_str1) | ||
|
||
|
||
@given( | ||
str0=st.text( | ||
alphabet=st.characters( | ||
min_codepoint=12450, # ア | ||
max_codepoint=12531), # ン | ||
min_size=MIN_LENGTH, | ||
max_size=MAX_LENGTH), | ||
str1=st.text( | ||
alphabet=st.characters( | ||
min_codepoint=12450, | ||
max_codepoint=12531), | ||
min_size=MIN_LENGTH, | ||
max_size=MAX_LENGTH)) | ||
def test_japanese_katakanas(str0, str1): | ||
norm_str0 = unicodedata.normalize('NFKC', str0) | ||
norm_str1 = unicodedata.normalize('NFKC', str1) | ||
event('eval("{}", "{}")'.format(norm_str0, norm_str1)) | ||
|
||
import editdistance | ||
assert REFERENCE(norm_str0, norm_str1) == \ | ||
editdistance.eval(norm_str0, norm_str1) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
import pytest | ||
pytest.main([__file__]) |