Skip to content

Commit

Permalink
Merge pull request #21 from kurtmckee/expand-hypothesis-testing
Browse files Browse the repository at this point in the history
Expand the hypothesis testing; fix target calculation
  • Loading branch information
Pevtrick authored Jul 31, 2024
2 parents f555fd1 + 0465ed5 commit 9b5469e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tests/test_round_trip.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


lists_of_integers = st.lists(elements=st.integers(min_value=0, max_value=sys.maxsize))
min_lengths = st.integers(min_value=1, max_value=100)
min_lengths = st.integers(min_value=0, max_value=255)
alphabets = st.text(
alphabet=st.characters(min_codepoint=0, max_codepoint=0x7f),
min_size=3,
Expand All @@ -16,9 +16,12 @@

@given(numbers=lists_of_integers, min_length=min_lengths, alphabet=alphabets)
def test_round_trip_encoding(numbers, min_length, alphabet):
# Encourage hypothesis to find ideal alphabets.
target(len(alphabet) / len(set(alphabet)))
assume(len(alphabet) == len(set(alphabet)))
# Encourage hypothesis to find ideal alphabets
# by giving unique alphabets a score of 1.0
# and non-unique alphabets a lower score.
target(len(set(alphabet)) / len(alphabet))
# Reject non-unique alphabets without failing the test.
assume(len(set(alphabet)) == len(alphabet))

sqid = sqids.Sqids(min_length=min_length, alphabet=alphabet, blocklist=[])
assert sqid.decode(sqid.encode(numbers)) == numbers

0 comments on commit 9b5469e

Please sign in to comment.