aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJJ2023-04-06 22:08:58 +0000
committerJJ2023-04-06 22:08:58 +0000
commit4183e659af29571110dfff91b89b58de7c8dd449 (patch)
tree3182577a0407f13ac426bfa88653774a24f46dc5 /tests
parent95ce33948581a10c2d55793b6317c7ce273f936a (diff)
refactor execute to not panic and write tests
Diffstat (limited to 'tests')
-rw-r--r--tests/test_execution.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_execution.rs b/tests/test_execution.rs
new file mode 100644
index 0000000..dd1b038
--- /dev/null
+++ b/tests/test_execution.rs
@@ -0,0 +1,21 @@
+use chrysanthemum::ast::*;
+use chrysanthemum::simple::*;
+use chrysanthemum::util::*;
+
+#[test]
+fn test_simple() {
+ assert_eq!(execute(Context::new(), Const(0, Type::Boolean)), Ok(Term(0, Type::Boolean)));
+ assert_eq!(execute(Context::new(), Const(123, Type::Natural)), Ok(Term(123, Type::Natural)));
+ assert_eq!(execute(Context::new(), Const(123, Type::Integer)), Ok(Term(123, Type::Integer)));
+ assert!(execute(Context::new(), Var("x")).is_err());
+}
+
+#[test]
+fn test_complex() {
+ let mut context = Context::new();
+ context.insert(String::from("x"), Term(413, Type::Natural));
+ context.insert(String::from("y"), Term(1, Type::Boolean));
+ assert_eq!(execute(context.clone(), Var("x")), Ok(Term(413, Type::Natural)));
+ assert_eq!(execute(context.clone(), Cond(Var("y"), Const(612, Type::Integer), Var("x"))), Ok(Term(612, Type::Integer)));
+ assert_eq!(execute(context.clone(), App(Abs("z", Cond(Const(0, Type::Boolean), Var("x"), Var("z"))), Const(1025, Type::Integer))), Ok(Term(1025, Type::Integer)));
+}