Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More exhaustive testing by property-based testing #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
@@ -1,7 +1,7 @@
env:
global:
- CIBW_TEST_REQUIRES=nose
- CIBW_TEST_COMMAND="nosetests {project}/test"
- CIBW_TEST_COMMAND="pip3 install -r {project}/requirements/test.txt && nosetests {project}/test"
- TWINE_USERNAME=aflc
matrix:
include:
Expand All @@ -15,13 +15,15 @@ matrix:
sudo: required
language: generic

script:
install:
- |
if [ "$TRAVIS_OS_NAME" == "osx" ]; then
sudo pip3 install cibuildwheel==0.10.1 twine
else
pip3 install cibuildwheel==0.10.1 twine
fi

script:
- cibuildwheel --output-dir wheelhouse
- |
if [[ $TRAVIS_TAG ]]; then
Expand Down
9 changes: 9 additions & 0 deletions README.rst
Expand Up @@ -39,6 +39,15 @@ It's quite simple:
editdistance.eval('banana', 'bahama')
# 2L

-----
Test
-----

.. code-block:: bash

pip install -r requirements/test.txt
pytest test/


----------------
Simple Benchmark
Expand Down
9 changes: 6 additions & 3 deletions appveyor.yml
@@ -1,12 +1,15 @@
environment:
TWINE_USERNAME: aflc
CIBW_SKIP: cp27-*
CIBW_TEST_REQUIRES: nose
CIBW_TEST_COMMAND: "nosetests {project}/test"
CIBW_TEST_COMMAND: "python -m pip install -r {project}\\requirements\\test.txt && nosetests {project}\\test"


install:
- python -m pip install cibuildwheel==1.1.0

build_script:
- pip install cibuildwheel==0.9.4
- cibuildwheel --output-dir wheelhouse
- python -m cibuildwheel --output-dir wheelhouse
- ps: >-
if ($env:APPVEYOR_REPO_TAG -eq "true") {
python -m pip install twine
Expand Down
3 changes: 3 additions & 0 deletions requirements/test.txt
@@ -0,0 +1,3 @@
pytest==5.3.5
hypothesis==5.4.2
textdistance==4.1.5
83 changes: 79 additions & 4 deletions test/test_editdistance.py
@@ -1,10 +1,85 @@
# -*- coding: utf-8 -*-

import unicodedata
import unittest

from hypothesis import given, strategies as st

from textdistance import Levenshtein


REFERENCE = Levenshtein().distance # as a test oracle


MIN_LENGTH = 0
MAX_LENGTH = 16


class TestEditDistance(unittest.TestCase):
def test_editdistance(self):
@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(self, str0, str1):
norm_str0 = unicodedata.normalize('NFKC', str0)
norm_str1 = unicodedata.normalize('NFKC', 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(self, str0, str1):
norm_str0 = unicodedata.normalize('NFKC', str0)
norm_str1 = unicodedata.normalize('NFKC', str1)

import editdistance
self.assertEqual(1, editdistance.eval('abc', 'aec'))

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(self, str0, str1):
norm_str0 = unicodedata.normalize('NFKC', str0)
norm_str1 = unicodedata.normalize('NFKC', 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__])