File size: 1,101 Bytes
783c92f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import pytest

from morph_hrr import segment

cases = [
    ("unhappy", ("un", "happy", "")),
    ("unkind", ("un", "kind", "")),
    ("running", ("", "runn", "ing")),      # no undoubling (documented)
    ("walking", ("", "walk", "ing")),
    ("happiness", ("", "happ", "iness")),   # longest suffix "iness"
    ("kingdom", ("", "king", "dom")),
    ("walks", ("", "walk", "s")),
    # Rule-based longest-match can't know "order" is a root: after "pre" it
    # strips "er" too. Documents the (deliberate) imperfectness.
    ("preorder", ("pre", "ord", "er")),
    ("disconnected", ("dis", "connect", "ed")),
    ("happy", ("", "happy", "")),           # no bare-"y" suffix
    ("KING", ("", "king", "")),             # case-insensitive
    ("a", ("", "a", "")),                   # too short -> root only
]


@pytest.mark.parametrize("word,expected", cases)
def test_segment(word, expected):
    assert segment(word) == expected


def test_non_alpha_passthrough():
    p, r, s = segment("123")
    assert r == "123" and p == "" and s == ""


def test_empty():
    assert segment("") == ("", "", "")