def test_attribute_arithmetic_div_sub_bracketted(): result = parse( { "op": "eq", "args": [ {"property": "attr"}, { "op": "/", "args": [ 3, {"op": "-", "args": [5, 2]}, ], }, ], } ) assert result == ast.Equal( ast.Attribute("attr"), ast.Div( 3, ast.Sub( 5, 2, ), ), )
def test_arithmetic(): # test possible optimizations result = optimize(parse("attr = 10 + 10")) assert result == ast.Equal( ast.Attribute('attr'), 20 ) result = optimize(parse("attr = 30 - 10")) assert result == ast.Equal( ast.Attribute('attr'), 20 ) result = optimize(parse("attr = 10 * 2")) assert result == ast.Equal( ast.Attribute('attr'), 20 ) result = optimize(parse("attr = 40 / 2")) assert result == ast.Equal( ast.Attribute('attr'), 20 ) # test imppossible optimizations result = optimize(parse("attr = other + 10")) assert result == ast.Equal( ast.Attribute('attr'), ast.Add( ast.Attribute('other'), 10 ), ) result = optimize(parse("attr = other - 10")) assert result == ast.Equal( ast.Attribute('attr'), ast.Sub( ast.Attribute('other'), 10 ), ) result = optimize(parse("attr = other * 2")) assert result == ast.Equal( ast.Attribute('attr'), ast.Mul( ast.Attribute('other'), 2 ), ) result = optimize(parse("attr = other / 2")) assert result == ast.Equal( ast.Attribute('attr'), ast.Div( ast.Attribute('other'), 2 ), )
def test_attribute_arithmetic_sub(): result = parse('attr = 5 - 2') assert result == ast.Equal( ast.Attribute('attr'), ast.Sub( 5, 2, ), )
def test_attribute_arithmetic_sub(): result = parse(['==', ['get', 'attr'], ['-', 5, 2]]) assert result == ast.Equal( ast.Attribute('attr'), ast.Sub( 5, 2, ), )
def test_attribute_arithmetic_div_sub_bracketted(): result = parse('attr = 3 / (5 - 2)') assert result == ast.Equal( ast.Attribute('attr'), ast.Div( 3, ast.Sub( 5, 2, ), ), )
def test_attribute_arithmetic_div_sub(): result = parse('attr = 3 / 5 - 2') assert result == ast.Equal( ast.Attribute('attr'), ast.Sub( ast.Div( 3, 5, ), 2, ), )
def test_attribute_arithmetic_div_sub_bracketted(): result = parse(['==', ['get', 'attr'], ['/', 3, ['-', 5, 2]]]) assert result == ast.Equal( ast.Attribute('attr'), ast.Div( 3, ast.Sub( 5, 2, ), ), )
def test_attribute_arithmetic_sub(): result = parse({ "eq": [ {"property": "attr"}, {"-": [5, 2]} ] }) assert result == ast.Equal( ast.Attribute('attr'), ast.Sub( 5, 2, ), )
def test_attribute_arithmetic_sub(): result = parse( { "op": "eq", "args": [{"property": "attr"}, {"op": "-", "args": [5, 2]}], } ) assert result == ast.Equal( ast.Attribute("attr"), ast.Sub( 5, 2, ), )
def test_attribute_arithmetic_div_sub(): result = parse({ "eq": [ {"property": "attr"}, {"-": [ {"/": [3, 5]}, 2, ]}, ], }) assert result == ast.Equal( ast.Attribute('attr'), ast.Sub( ast.Div( 3, 5, ), 2, ), )