-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
32 additions
and
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,24 @@ | ||
""" | ||
Tests the 2 helper functions (clean_ascii and compare_text) in summary_mixin.py | ||
Tests the get_summary function in summary_mixin.py | ||
""" | ||
from puterbot.strategies.summary_mixin import clean_ascii, compare_text | ||
from fuzzywuzzy import fuzz | ||
|
||
from puterbot.strategies.demo import DemoReplayStrategy | ||
from puterbot.models import Recording, Screenshot | ||
|
||
################################################################ | ||
# Clean ASCII tests | ||
################################################################ | ||
RECORDING = Recording() | ||
REPLAY = DemoReplayStrategy(RECORDING) | ||
|
||
|
||
def test_clean_ascii_empty(): | ||
def test_summary_empty(): | ||
empty_text = "" | ||
expected = "" | ||
actual = clean_ascii(empty_text) | ||
assert actual == expected | ||
|
||
|
||
def test_clean_ascii_no_symbols_or_stopwords(): | ||
no_symbols = "wow no symbols" | ||
expected = "wow no symbols" | ||
actual = clean_ascii(no_symbols) | ||
assert actual == expected | ||
|
||
|
||
def test_clean_ascii_some_symbols_and_stopwords(): | ||
many_symbols = "wow this! has some... symbols" | ||
expected = "wow has some symbols" | ||
actual = clean_ascii(many_symbols) | ||
assert actual == expected | ||
|
||
|
||
def test_clean_ascii_all_symbols_and_stopwords(): | ||
all_symbols = "&*@#($)#!| ~~ this \\" | ||
expected = "" | ||
actual = clean_ascii(all_symbols) | ||
assert actual == expected | ||
|
||
|
||
################################################################ | ||
# Compare text tests | ||
################################################################ | ||
|
||
|
||
def test_compare_text_empty(): | ||
text1 = "" | ||
text2 = "" | ||
expected = 0 | ||
actual = compare_text(text1, text2) | ||
assert actual == expected | ||
|
||
|
||
def test_compare_text_similar(): | ||
text1 = "I love sunshine so much." | ||
text2 = "I adore the sun." | ||
expected = 50 | ||
actual = compare_text(text1, text2) | ||
assert actual > expected | ||
actual = REPLAY.get_summary(empty_text, 1) | ||
assert len(actual) == 0 | ||
|
||
|
||
def test_compare_text_not_similar(): | ||
text1 = "I love sunshine so much" | ||
text2 = "Once upon a time, there was a princess." | ||
expected = 50 | ||
actual = compare_text(text1, text2) | ||
assert actual < expected | ||
def test_summary_sentence(): | ||
story = "However, this bottle was not marked “poison,” so Alice ventured to taste it, \ | ||
and finding it very nice, (it had, in fact, a sort of mixed flavour of cherry-tart, \ | ||
custard, pine-apple, roast turkey, toffee, and hot buttered toast,) \ | ||
she very soon finished it off." | ||
actual = REPLAY.get_summary(story, 1) | ||
assert fuzz.WRatio(actual, story) > 50 |