extern crate rcalc;
#[cfg(test)]
mod operators {
use rcalc::Interpreter;
#[test]
fn it_does_addition() {
assert_eq!(Interpreter::process("3+4").unwrap(), 7.);
}
#[test]
fn it_does_subtraction() {
assert_eq!(Interpreter::process("3-4").unwrap(), -1.);
}
#[test]
fn it_does_multiplication() {
assert_eq!(Interpreter::process("3*4").unwrap(), 12.);
}
mod division {
use rcalc::Interpreter;
#[test]
fn it_does_division() {
assert_eq!(Interpreter::process("3/4").unwrap(), 0.75);
}
#[test]
fn it_does_integer_division() {
assert_eq!(Interpreter::process("3./4").unwrap(), 0.);
}
#[test]
fn it_does_modulo_division() {
assert_eq!(Interpreter::process("10%3").unwrap(), 1.);
}
}
mod factorial {
use rcalc::Interpreter;
#[test]
fn it_does_factorial() {
assert_eq!(Interpreter::process("5!").unwrap(), 120.);
}
#[test]
fn it_does_factorial_with_even_negative() {
use std::f64;
assert_eq!(Interpreter::process("-2!").unwrap(), f64::INFINITY);
}
#[test]
fn it_does_factorial_with_odd_negative() {
use std::f64;
assert_eq!(Interpreter::process("-3!").unwrap(), -f64::INFINITY);
}
}
#[test]
fn it_handles_unary_operators() {
assert_eq!(Interpreter::process("-5 - + - 7").unwrap(), 2.);
}
}