From 1c9ea7b835fda7238ee042a5e644c4dec38b4f94 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Mon, 20 Jul 2015 12:05:45 +0200 Subject: [PATCH] * Add tests for short string optimization --- tests/vocab/test_intern.py | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/vocab/test_intern.py b/tests/vocab/test_intern.py index a16340c41..21296dd2c 100644 --- a/tests/vocab/test_intern.py +++ b/tests/vocab/test_intern.py @@ -35,3 +35,44 @@ def test_retrieve_id(sstore): assert sstore[1] == 'A' with pytest.raises(IndexError): sstore[2] + + +def test_med_string(sstore): + nine_char_string = sstore[b'0123456789'] + assert sstore[nine_char_string] == b'0123456789' + dummy = sstore[b'A'] + assert sstore[b'0123456789'] == nine_char_string + + +def test_long_string(sstore): + url = u'INFORMATIVE](http://www.google.com/search?as_q=RedditMonkey&hl=en&num=50&btnG=Google+Search&as_epq=&as_oq=&as_eq=&lr=&as_ft=i&as_filetype=&as_qdr=all&as_nlo=&as_nhi=&as_occt=any&as_dt=i&as_sitesearch=&as_rights=&safe=off' + orth = sstore[url] + assert sstore[orth] == url + + +def test_254_string(sstore): + s254 = 'a' * 254 + orth = sstore[s254] + assert sstore[orth] == s254 + +def test_255_string(sstore): + s255 = 'b' * 255 + orth = sstore[s255] + assert sstore[orth] == s255 + +def test_256_string(sstore): + s256 = 'c' * 256 + orth = sstore[s256] + assert sstore[orth] == s256 + + +def test_massive_strings(sstore): + s511 = 'd' * 511 + orth = sstore[s511] + assert sstore[orth] == s511 + s512 = 'e' * 512 + orth = sstore[s512] + assert sstore[orth] == s512 + s513 = '1' * 513 + orth = sstore[s513] + assert sstore[orth] == s513