More test cases

This commit is contained in:
Sebastian Schmidt 2019-03-15 17:18:20 +02:00
parent b38c102c1d
commit 045313f076

View File

@ -16,13 +16,23 @@ pub fn eval(string: &str) -> Result<Value, Error> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::{eval, value::Value}; use crate::{eval, value::Value};
use error::Error;
#[test] #[test]
fn test_simple_examples() { fn test_unary_examples() {
assert_eq!(eval("3"), Ok(Value::Number(3.0))); assert_eq!(eval("3"), Ok(Value::Number(3.0)));
assert_eq!(eval("true"), Ok(Value::Boolean(true)));
assert_eq!(eval("false"), Ok(Value::Boolean(false)));
assert_eq!(eval("blub"), Err(Error::IdentifierNotFound));
}
#[test]
fn test_binary_examples() {
assert_eq!(eval("1+3"), Ok(Value::Number(4.0))); assert_eq!(eval("1+3"), Ok(Value::Number(4.0)));
assert_eq!(eval("3+1"), Ok(Value::Number(4.0))); assert_eq!(eval("3+1"), Ok(Value::Number(4.0)));
assert_eq!(eval("3-5"), Ok(Value::Number(-2.0))); assert_eq!(eval("3-5"), Ok(Value::Number(-2.0)));
assert_eq!(eval("5-3"), Ok(Value::Number(2.0))); assert_eq!(eval("5-3"), Ok(Value::Number(2.0)));
assert_eq!(eval("5 / 4"), Ok(Value::Number(1.25)));
assert_eq!(eval("5 *3"), Ok(Value::Number(15.0)));
} }
} }