Example #1
0
def test_redundant_paths():
    fsa = FSA.from_dict({
        "allow_overlap": True,
        "states": {
            "start": {
                "transitions": [
                    { "condition": "a", "target": "s1" },
                    { "condition": "a", "target": "s2" },
                ],
            },
            "s1": {
                "transitions": [
                    { "condition": "b", "target": "s3" },
                ],
            },
            "s2": {
                "transitions": [
                    { "condition": "b", "target": "s3" },
                ],
            },
            "s3": {
                "terminal": True,
            }
        }
    })
    matches = fsa.feed_all("ab")
    assert_equal(1, len(matches))
Example #2
0
def test_even_less_trivial_greedy():
    fsa = FSA.from_dict({
        "allow_overlap": True,
        "states": {
            "start": {
                "transitions": [
                    { "condition": "a", "target": "s1" },
                    { "condition": "a", "target": "s2" },
                ],
            },
            "s1": {
                "terminal": True,
            },
            "s2": {
                "transitions": [
                    { "condition": "b", "target": "s2" },
                    { "condition": "b", "target": "s3" },
                ],
            },
            "s3": {
                "terminal": True,
            }
        }
    })
    matches = fsa.feed_all("abbb")
    assert_equal(2, len(matches))
    histories = [ m['history_events'] for m in matches ]
    assert ["a"] in histories
    assert ["a", "b", "b", "b"] in histories
Example #3
0
def test_issue_7():
    fsa = FSA.from_dict({
        "allow_overlap": True,
        "states": {
            "start": {
                "default_transition": {
                    "target": "s1"
                }
            },
            "s1": {
                "default_transition": {
                    "target": "s2"
                }
            },
            "s2": {
                "terminal": True
            }
        }
    })
    assert_matches(fsa, "ab", ["ab"])
Example #4
0
def test_non_trivial_greedy():
    fsa = FSA.from_dict({
        "allow_overlap": True,
        "states": {
            "start": {
                "transitions": [
                    { "condition": "a", "target": "s2" },
                    { "condition": "a", "target": "s1" },
                ],
            },
            "s1": {
                "transitions": [
                    { "condition": "b", "target": "s1" },
                    { "condition": "b", "target": "s2" },
                ],
            },
            "s2": {
                "terminal": True,
            }
        }
    })
    matches = fsa.feed_all("abbb")
    assert_equal(1, len(matches))
    assert_equal(["a", "b", "b", "b"], matches[0]['history_events'])