specifically test that the long sequence underflows to 0

This commit is contained in:
Robyn Speer 2021-02-18 15:09:31 -05:00
parent bd57b64d00
commit 6b97d093b6

View File

@ -1,4 +1,4 @@
from wordfreq import tokenize, word_frequency from wordfreq import tokenize, word_frequency, zipf_frequency
import pytest import pytest
@ -80,8 +80,10 @@ def test_alternate_codes():
def test_unreasonably_long(): def test_unreasonably_long():
# This crashed earlier versions of wordfreq # This crashed earlier versions of wordfreq due to an overflow in
# exponentiation. We've now changed the sequence of operations so it
# will underflow instead.
lots_of_ls = 'l' * 800 lots_of_ls = 'l' * 800
assert word_frequency(lots_of_ls, 'zh') < 1e-300 assert word_frequency(lots_of_ls, 'zh') == 0.
assert zipf_frequency(lots_of_ls, 'zh') == 0. assert zipf_frequency(lots_of_ls, 'zh') == 0.