From 91e758a6eca4cc806e34a8be5d030138b7dae910 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 1 Dec 2016 20:25:28 -0800 Subject: equation rebalancing --- tests/modelica_ast.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/modelica_ast.rs b/tests/modelica_ast.rs index b6233f3..d39615e 100644 --- a/tests/modelica_ast.rs +++ b/tests/modelica_ast.rs @@ -54,3 +54,25 @@ fn test_eqn_identifiers() { Box::new(Ident("z".to_string()))), }.identifiers())); } + +#[test] +fn test_rebalance_for() { + use modelthing::modelica_ast::Expr::*; + + // z = a - 1.2345 + // a = z + 1.2345 + let done = SimpleEquation{ + lhs: Ident("z".to_string()), + rhs: BinExpr(BinOperator::Subtract, + Box::new(Ident("a".to_string())), + Box::new(Float(1.2345)))}; + assert_eq!(done, + done.rebalance_for("z".to_string()).unwrap()); + assert_eq!(SimpleEquation{ + lhs: Ident("a".to_string()), + rhs: BinExpr(BinOperator::Add, + Box::new(Ident("z".to_string())), + Box::new(Float(1.2345)))}, + done.rebalance_for("a".to_string()).unwrap()); + +} -- cgit v1.2.3