def test_base_enum():
    e = Enum(operators=frozenset([PLUS, OR, NOT]))
    e.leafs = [0, 'x']
    result = []
    for t in e.base_enum(3):
        print t
        result.append(t)

    expected = sorted([
        ('not', ('not', 0)),
        ('not', ('not', 'x')),
        ('plus', 0, 0),
        ('plus', 0, 'x'),
        ('plus', 'x', 'x'),
        ('or', 0, 0),
        ('or', 0, 'x'),
        ('or', 'x', 'x'),
    ])

    eq_(sorted(result), expected)
def test_with_enum():
    e = Enum(operators=frozenset(
        [NOT, SHL1, SHR4, AND, PLUS, OR, XOR]))
    all_terms = list(e.base_enum(3))

    d = SemanticDict()
    for t in all_terms:
        if t not in d:
            d[t] = t
    print d.to_str()

    unique_terms = list(d.itervalues())

    for i, t1 in enumerate(unique_terms):
        for j in range(i):
            assert not terms_equivalent(t1, unique_terms[j])

    for t in all_terms:
        assert any(terms_equivalent(t, u) for u in unique_terms)

    print len(all_terms), 'terms total'
    print len(unique_terms), 'unique terms'