diff options
author | bnewbold <bnewbold@robocracy.org> | 2016-12-17 18:34:47 -0800 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2016-12-17 18:34:47 -0800 |
commit | 9f82aceb9fbdb42f332d68f4a423123bd0788b2c (patch) | |
tree | c082b9795be8e9e9d286c8f8f1345d22f3ec1b59 /tests/modelica_ast.rs | |
parent | f6364ebcac0d0a88a3cc6812fd2120c97b42cc26 (diff) | |
download | modelthing-9f82aceb9fbdb42f332d68f4a423123bd0788b2c.tar.gz modelthing-9f82aceb9fbdb42f332d68f4a423123bd0788b2c.zip |
refactor modelica parser into separate crate
Diffstat (limited to 'tests/modelica_ast.rs')
-rw-r--r-- | tests/modelica_ast.rs | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/tests/modelica_ast.rs b/tests/modelica_ast.rs deleted file mode 100644 index d39615e..0000000 --- a/tests/modelica_ast.rs +++ /dev/null @@ -1,78 +0,0 @@ - -extern crate modelthing; - -use std::collections::HashSet; -use std::iter::FromIterator; -use modelthing::modelica_ast::*; - -fn set_eq(a: Vec<String>, b: Vec<String>) -> bool { - let set_a: HashSet<String> = HashSet::from_iter(a); - let set_b: HashSet<String> = HashSet::from_iter(b); - return set_a == set_b; -} - -#[test] -fn test_expr_identifiers() { - use modelthing::modelica_ast::Expr::*; - - assert!(set_eq( - vec![], - Integer(0).identifiers())); - assert!(set_eq( - vec!["x".to_string()], - Ident("x".to_string()).identifiers())); - assert!(set_eq( - vec!["x".to_string(), "y".to_string(), "z".to_string()], - BinExpr(BinOperator::Add, - Box::new(Abs(Box::new(Ident("z".to_string())))), - Box::new(BinExpr(BinOperator::Add, - Box::new(Abs(Box::new(Ident("x".to_string())))), - Box::new(Abs(Box::new(Ident("y".to_string()))))))).identifiers())); - assert!(set_eq( - vec!["z".to_string()], - BinExpr(BinOperator::Add, - Box::new(Ident("z".to_string())), - Box::new(Ident("z".to_string()))).identifiers())); -} - -#[test] -fn test_eqn_identifiers() { - use modelthing::modelica_ast::Expr::*; - - assert!(set_eq( - vec![], - SimpleEquation{ - lhs: Integer(0), - rhs: Integer(0), - }.identifiers())); - assert!(set_eq( - vec!["z".to_string()], - SimpleEquation{ - lhs: Ident("z".to_string()), - rhs: BinExpr(BinOperator::Add, - Box::new(Ident("z".to_string())), - 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()); - -} |