Beispiel #1
0
def test_canonical_sequence():
    ax = USet(2, "a")

    s = hd.Sequences(ax, 0, 4)
    bf_check(s)

    s = hd.Sequences(ax * ax, 0, 4)
    bf_check(s)
Beispiel #2
0
def test_sequence_operator():
    r = hd.Range(3)

    s1 = hd.Sequences(r, 4)
    s2 = r**4

    assert list(s1) == list(s2)
Beispiel #3
0
def test_sequence_to_values():
    s = hd.Sequences(hd.Range(3), 0, 2)

    v = s.to_values()

    assert isinstance(v, hd.Values)
    assert list(s) == list(v)
Beispiel #4
0
def test_sequence_to_values_maxsize():
    s = hd.Sequences(hd.Range(3), 0, 2)

    v = s.to_values(max_size=3)

    assert isinstance(v, hd.Sequences)
    assert isinstance(v.domain, hd.Values)
    assert list(s) == list(v)
Beispiel #5
0
def test_sequence_generate():
    s = hd.Sequences(hd.Range(3), 5)
    result = list(s.generate(200))
    assert len(result)
    for r in result:
        assert len(r) == 5
        for x in r:
            assert 0 <= x < 3
Beispiel #6
0
def test_sequence_iterate():
    s = hd.Sequences(hd.Range(3), 0, 2)

    expected = [(), (0, ), (1, ), (2, ), (0, 0), (0, 1), (0, 2), (1, 0),
                (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]

    result = list(s)
    assert set(result) == set(expected)
    assert len(result) == len(expected)
    assert s.size == len(expected)
Beispiel #7
0
def test_sequence_flags():
    a = hd.USet(4, "a")
    f = a.filter(lambda x: True)
    m = a.map(lambda x: True)

    p1 = hd.Sequences(a, 2)
    p2 = hd.Sequences(f, 2)
    p3 = hd.Sequences(m, 2)

    assert not p1.filtered
    assert p2.filtered
    assert not p3.filtered

    assert p1.step_jumps
    assert p2.step_jumps
    assert p3.step_jumps

    assert p1.strict
    assert not p2.strict
    assert not p3.strict
Beispiel #8
0
def test_sequence_iter_set():
    r2 = hd.Range(4)
    p = hd.Sequences(r2, 3)

    a = list(p)
    b = []
    for i in xrange(p.size + 10):
        it = p.create_iter(i)
        result = list(it)
        if result:
            b.append(result[0])
    assert a == b
Beispiel #9
0
def test_domain_filter():
    def fn(x):
        return x > 2 and x < 5

    r = hd.Range(6)
    d = r.filter(fn)
    result = list(d)
    assert result == [3, 4]

    result = list(d.generate(5))
    assert len(result) == 5
    for x in result:
        assert x in [3, 4]

    assert d.filtered
    assert not r.filtered
    assert d.size == 6

    p = d * d
    result = list(p)
    assert set(result) == {(3, 3), (4, 3), (3, 4), (4, 4)}

    assert p.filtered
    assert not (r * r).filtered

    assert hd.Sequences(d, 2).filtered
    assert not hd.Sequences(r, 2).filtered

    assert not hd.Mappings(d, r).filtered
    assert hd.Mappings(r, d).filtered
    assert not hd.Mappings(r, r).filtered

    assert hd.Product((d, d), unordered=True).filtered
    assert not hd.Product((r, r), unordered=True).filtered

    result = list(hd.Product((d, d), unordered=True))
    assert set(result) == {(4, 3)}
Beispiel #10
0
def test_sequence_name():
    s = hd.Sequences(hd.Range(10), 2, name="TestSequence")
    assert s.name == "TestSequence"
Beispiel #11
0
def test_sequence_iterate_empty():
    assert list(hd.Sequences(hd.Range(3), 0)) == [()]