aboutsummaryrefslogtreecommitdiffstats
path: root/tests/rebalance.rs
blob: f365e844def142dbc9db0a78708bbb10fa355fd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

extern crate modelica_parser;
extern crate modelthing;

use modelthing::modelica_model::SimpleEquationExt;
use modelica_parser::ast::*;

#[test]
fn test_rebalance_for() {
    use modelica_parser::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());

}