Ejemplo n.º 1
0
def test_fallthrough_with_default(values, results):
    value = values.pop()
    result = results.pop()

    with quandary(value) as q:
        for v, r in zip(values, results):
            q.case(v, r)
        q.default(result)

    assert q.result == result
Ejemplo n.º 2
0
def test_quandary__noniterable_values(values, results):
    value = values.pop()
    result = results.pop()

    with quandary(value) as q:
        q.case(value, result)

        for v, r in zip(values, results):
            q.case(v, r)

    assert q.result == result
Ejemplo n.º 3
0
def test_quandary__expand():
    with quandary(10) as q:
        q.case(range(20), True, force_contains=True)
        q.case(range(20, 40), False, force_contains=True)

    assert q.result
Ejemplo n.º 4
0
def test_unevaluated():
    with pytest.raises(UnevaluatedQuandary):
        with quandary('hello') as q:
            q.result
Ejemplo n.º 5
0
def test_fallthrough_without_default():
    with pytest.raises(NoMatch):
        with quandary('foo') as q:
            q.case('a', 1)
            q.case('b', 2)
            q.case('bar', -1)
Ejemplo n.º 6
0
def quan_using_range(target, end):
    with quandary(target) as q:
        q.case(range(end), lambda x: x, force_contains = True)

    return q.result
Ejemplo n.º 7
0
def quan_lots_of_cases(target, end):
    with quandary(target) as q:
        for i in range(end):
            q.case(i, i)

    return q.result