Пример #1
0
def test_corner_cases():
    with pytest.raises(IndexError):
        EQ().stretch(1)[1]
    with pytest.raises(IndexError):
        (EQ() + RQ(1))[2]
    with pytest.raises(RuntimeError):
        mul(1, 1)
    with pytest.raises(RuntimeError):
        add(1, 1)
    with pytest.raises(RuntimeError):
        stretch(1, 1)
    with pytest.raises(RuntimeError):
        transform(1, 1)
    with pytest.raises(RuntimeError):
        differentiate(1, 1)
    with pytest.raises(RuntimeError):
        select(1, 1)
    with pytest.raises(RuntimeError):
        shift(1, 1)
    assert repr(EQ()) == str(EQ())
    assert EQ().__name__ == 'EQ'
    with pytest.raises(NotImplementedError):
        WrappedElement(1).display(1, lambda x: x)
    with pytest.raises(NotImplementedError):
        JoinElement(1, 2).display(1, 2, lambda x: x)
Пример #2
0
def test_corner_cases():
    yield raises, IndexError, lambda: EQ().stretch(1)[1]
    yield raises, IndexError, lambda: (EQ() + RQ(1))[2]
    yield raises, RuntimeError, lambda: mul(1, 1)
    yield raises, RuntimeError, lambda: add(1, 1)
    yield raises, RuntimeError, lambda: stretch(1, 1)
    yield raises, RuntimeError, lambda: transform(1, 1)
    yield raises, RuntimeError, lambda: differentiate(1, 1)
    yield raises, RuntimeError, lambda: select(1, 1)
    yield raises, RuntimeError, lambda: shift(1, 1)
    yield eq, repr(EQ()), str(EQ())
    yield eq, EQ().__name__, 'EQ'
    yield raises, NotImplementedError, \
          lambda: WrappedElement(1).display(1, lambda x: x)
    yield raises, NotImplementedError, \
          lambda: JoinElement(1, 2).display(1, 2, lambda x: x)
Пример #3
0
def add(a, b):
    return add(new(b, TensorProductFunction)(a), b)
Пример #4
0
def add(a, b):
    return add(a, new(a, TensorProductFunction)(b))
Пример #5
0
def add(a, b): return add(new(b, TensorProductFunction)(a), b)


# Stretch:

@_dispatch(Element, [object])
Пример #6
0
def add(a, b): return add(a, new(a, TensorProductFunction)(b))


@add.extend(PythonFunction, Element, precedence=10)