Example #1
0
def test_post_empty(capsys):
    """Correct empty ouput."""
    a = K()
    a.post_order(lambda n: print(n.__str__()))
    sys.stderr.write("")
    out, err = capsys.readouterr()
    assert out == err
Example #2
0
def test_breadth_empty(capsys):
    """Correct empty ouput."""
    a = K()
    a.breadth_first_traversal(lambda n: print(n.__str__()))
    sys.stderr.write("")
    out, err = capsys.readouterr()
    assert out == err
Example #3
0
def test_matches_many():
    """All matches."""
    k = K()
    k.insert(1)
    k.insert(2, 1)
    k.insert(2, 1)
    k.insert(2, 1)
    k = fm(k, 2)
    for each in k:
        assert each.val == 2
Example #4
0
def test_post_no_operation(capsys):
    """Raise error if missing lambda."""
    a = K()
    with pytest.raises(TypeError):
        assert a.post_order()
Example #5
0
def test_breadth_no_operation(capsys):
    """Raise error if missing lambda."""
    a = K()
    with pytest.raises(TypeError):
        assert a.breadth_first_traversal()
Example #6
0
def test_plo_single(tree):
    """No children."""
    k = K()
    k.insert(1)
    assert plo(k) == '1'
Example #7
0
def test_plo_empty():
    """No nodes."""
    k = K()
    with pytest.raises(AttributeError):
        assert plo(k)