예제 #1
0
def test_input():
    data = 7
    condition = lambda x: x >= 0
    function_true = lambda x: math.sqrt(x)
    function_false = lambda x: 0
    instance = branching.IfThenApply()
    instance.input(
        dict(data=data,
             condition=condition,
             function_true=function_true,
             function_false=function_false))
    instance.set_output_label('any')

    # case: true
    assert instance.output() == math.sqrt(data)

    # case: false
    data = -34
    instance.reset()
    instance.input(
        dict(data=data,
             condition=condition,
             function_true=function_true,
             function_false=function_false))
    instance.set_output_label('any')
    assert instance.output() == 0
예제 #2
0
def replace_word(text):
    t = value.Value(value=text, name="text")
    s = branching.IfThenApply(condition=lambda x: "hello" in x,
                              function_true=lambda x: x.replace("hello", "ciao"),
                              function_false=lambda x: x.replace(" ", "_"),
                              name="if")
    p = printer.ConsolePrinter()
    g = graph.Graph('replace_word', [t, s, p])

    g.connect(p, s, 'message')
    g.connect(s, t, 'data')

    return g
예제 #3
0
def test_requirements():
    expected = ['data', 'condition', 'function_true', 'function_false']
    instance = branching.IfThenApply()
    assert instance.requirements == expected