46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
import sys
|
||
from pathlib import Path
|
||
|
||
# Добавляем родительскую папку в sys.path для импорта
|
||
scripts_path = Path(__file__).resolve().parent.parent
|
||
if str(scripts_path) not in sys.path:
|
||
sys.path.insert(0, str(scripts_path))
|
||
|
||
from regions import match_location
|
||
|
||
# ----------------------------------------------- Тесты Fuzzy Matcher ------------------------------------------------------------
|
||
|
||
def test_match_exact():
|
||
"""
|
||
Проверяет точное совпадение локации.
|
||
"""
|
||
assert match_location("Toril", "Waterdeep") == "Waterdeep"
|
||
assert match_location("Toril", "Neverwinter") == "Neverwinter"
|
||
|
||
def test_match_fuzzy():
|
||
"""
|
||
Проверяет коррекцию опечаток (fuzzy matching).
|
||
"""
|
||
assert match_location("Toril", "Watterdeep") == "Waterdeep"
|
||
assert match_location("Toril", "Neverwintar") == "Neverwinter"
|
||
assert match_location("Toril", "baldur gate") == "Baldur's Gate"
|
||
|
||
def test_match_unknown_world():
|
||
"""
|
||
Проверяет поведение при передаче неизвестного мира.
|
||
"""
|
||
assert match_location("Unknown", "Waterdeep") == "Waterdeep"
|
||
|
||
def test_match_no_correction_needed():
|
||
"""
|
||
Проверяет поведение для локаций, которых нет в словаре.
|
||
"""
|
||
assert match_location("Toril", "Some Random City") == "Some Random City"
|
||
|
||
if __name__ == "__main__":
|
||
test_match_exact()
|
||
test_match_fuzzy()
|
||
test_match_unknown_world()
|
||
test_match_no_correction_needed()
|
||
print("Все тесты match_location успешно пройдены!")
|