Esempio n. 1
0
def test_run():

    model = LPyModel(code=code_run())
    assert model is not None
    assert model.outputs == []
    result = model()

    true_result = "_(0.01)-(90)F(0.111111111111)+F(0.111111111111)--F(0.111111111111)+F(0.111111111111)+F(0.111111111111)+F(0.111111111111)--F(0.111111111111)+F(0.111111111111)--F(0.111111111111)+F(0.111111111111)--F(0.111111111111)+F(0.111111111111)+F(0.111111111111)+F(0.111111111111)--F(0.111111111111)+F(0.111111111111)"
    assert str(model.outputs) == true_result
    assert str(result) == true_result

    result = model("_(0.01)-(90)F(1)", 0)
    assert result == "_(0.01)-(90)F(1)"

    result = model(N=0)
    assert result == "_(0.01)-(90)F(1)"

    true_result2 = "F(0.111111111111)+F(0.111111111111)--F(0.111111111111)+F(0.111111111111)+F(0.111111111111)+F(0.111111111111)--F(0.111111111111)+F(0.111111111111)--F(0.111111111111)+F(0.111111111111)--F(0.111111111111)+F(0.111111111111)+F(0.111111111111)+F(0.111111111111)--F(0.111111111111)+F(0.111111111111)"
    result = model.run("F(1)")
    assert str(result) == true_result2

    result = model(N=0, lstring="F(1)")
    assert result == "F(1)"

    result = model(lstring="F(5)", N=0)
    assert result == "F(5)"
Esempio n. 2
0
def test_model_get_documentation():
    model_src = '''"""
input = lstring="_(0.01)-(90)F(1)"
output = lstring
"""
N = 2

derivation length: N

production:

F(x) :
  produce  F(x/3.0)+F(x/3.0)--F(x/3.0)+F(x/3.0)

endlsystem
'''
    model = LPyModel(code=model_src)
    assert model.get_documentation() == """input = lstring="_(0.01)-(90)F(1)"
output = lstring"""

    assert model.repr_code() == model_src
Esempio n. 3
0
def test_magic():
    model_src = '''"""
input = lstring="_(0.01)-(90)F(1)", a=1
output = lstring
"""

%pylab inline
N = 2

derivation length: N

production:

F(x) :
  produce  F(x/3.0)+F(x/3.0)--F(x/3.0)+F(x/3.0)

endlsystem
'''
    model = LPyModel(code=model_src)
    assert model.repr_code() == model_src
    assert len(model.inputs_info) == 2
    assert len(model.outputs_info) == 1
Esempio n. 4
0
def test_model_inputs_info():
    model_src = '''"""
input = lstring="_(0.01)-(90)F(1)", a=1
output = lstring
"""
N = 2

derivation length: N

production:

F(x) :
  produce  F(x/3.0)+F(x/3.0)--F(x/3.0)+F(x/3.0)

endlsystem
'''
    model = LPyModel(code=model_src)
    assert len(model.inputs_info) == 2
    assert len(model.outputs_info) == 1
    assert model.inputs_info[0].name == "lstring"
    assert eval(model.inputs_info[0].default) == "_(0.01)-(90)F(1)"
    assert model.inputs_info[1].name == "a"
    assert model.inputs_info[1].default == "1"
    assert model.outputs_info[0].name == "lstring"
Esempio n. 5
0
def test_default_in_out_lstring():
    # Issue 5, part 4

    model = LPyModel(code=code_no_lstring())
    result = model("F(1)")
    assert str(result) == "F(1)+F(1)+F(1)+F(1)"
Esempio n. 6
0
def test_step_copy():
    import copy
    model = LPyModel(code=code_step())
    model2 = copy.copy(model)
    run_step(model2)
Esempio n. 7
0
def test_step():
    model = LPyModel(code=code_step())
    run_step(model)