More test cases
This commit is contained in:
parent
b38c102c1d
commit
045313f076
12
src/lib.rs
12
src/lib.rs
@ -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)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user