def test_ExpressionGenerator_2(): #IGNORE:C01111
    msg = 'Test creation of expression strings. Check function call.'
    #py.test.skip(msg)
    print msg
    from math import sin
    from freeode.pygenerator import ExpressionGenerator
    from freeode.interpreter import IFloat, CallableObject
    from freeode.ast import NodeFuncCall

    e_gen = ExpressionGenerator()
    #create a variable
    a = IFloat()
    a.target_name = 'a'
    #create a function
    fsin = CallableObject(None)
    fsin.codegen_name = 'sin' 
    
    #expression: sin(a)
    expr = NodeFuncCall(fsin, (a,))
    expr_str = e_gen.create_expression(expr)
    print expr_str
    assert eval(expr_str, {'a':0, 'sin':sin}) == 0
def test_ExpressionGenerator_1(): #IGNORE:C01111
    msg = 'Test creation of expression strings. Check all operators'
    #py.test.skip(msg)
    print msg
    from numpy import float64
    from freeode.pygenerator import ExpressionGenerator, IFloat
    from freeode.ast import (RoleConstant,
                             NodeOpInfix2, NodeOpPrefix1, NodeParentheses)

    e_gen = ExpressionGenerator()
    #create some variables and numbers
    a = IFloat()
    a.target_name = 'a'
    b = IFloat()
    b.target_name = 'b'
    c = IFloat(2)
    c.role = RoleConstant
    
    #expression a + b * 2
    expr = NodeOpInfix2('+', (a, NodeOpInfix2('*', (b, c))))
    expr_str = e_gen.create_expression(expr)
    print expr_str
    assert eval(expr_str, {'a':1, 'b':2, 'float64':float64}) == 5

    #expression a - b / 2
    expr = NodeOpInfix2('-', (a, NodeOpInfix2('/', (b, c))))
    expr_str = e_gen.create_expression(expr)
    print expr_str
    assert eval(expr_str, {'a':1, 'b':2, 'float64':float64}) == 0

    #expression a ** b % 2
    expr = NodeOpInfix2('**', (a, NodeOpInfix2('%', (b, c))))
    expr_str = e_gen.create_expression(expr)
    print expr_str
    assert eval(expr_str, {'a':2, 'b':3, 'float64':float64}) == 0

    #expression - 2
    expr = NodeOpPrefix1('-', (c,))
    expr_str = e_gen.create_expression(expr)
    print expr_str
    assert eval(expr_str, {'float64':float64}) == -2

    #expression (a + b) * 2
    expr = NodeOpInfix2('*', (NodeParentheses((NodeOpInfix2('+', (a, b)),)
                                              ), 
                              c)
                        )
    expr_str = e_gen.create_expression(expr)
    print expr_str
    assert eval(expr_str, {'a':1, 'b':2, 'float64':float64}) == 6