use tabulon::Tabula;
#[test]
fn arithmetic_precedence_mul_before_add() {
let mut eng = Tabula::new();
let c = eng.compile_ref("1 + 2 * 3").unwrap();
assert_eq!(c.eval(&[]).unwrap(), 7.0);
}
#[test]
fn parentheses_override() {
let mut eng = Tabula::new();
let c = eng.compile_ref("(1 + 2) * 3").unwrap();
assert_eq!(c.eval(&[]).unwrap(), 9.0);
}
#[test]
fn unary_minus_precedence() {
let mut eng = Tabula::new();
let c = eng.compile_ref("-A * B").unwrap();
let a = 2.0;
let b = 3.0;
assert_eq!(c.eval(&[&a, &b]).unwrap(), -6.0);
}
#[test]
fn left_associativity_sub() {
let mut eng = Tabula::new();
let c = eng.compile_ref("A - B - C").unwrap();
let a = 10.0;
let b = 2.0;
let d = 3.0;
assert_eq!(c.eval(&[&a, &b, &d]).unwrap(), 5.0);
}
#[test]
fn relational_vs_equality_precedence() {
let mut eng = Tabula::new();
let c = eng.compile_ref("A == B < C").unwrap();
let a = 0.0;
let b = 2.0;
let d = 3.0;
assert_eq!(c.eval(&[&a, &b, &d]).unwrap(), 0.0);
}
#[test]
fn and_has_higher_precedence_than_or() {
let mut eng = Tabula::new();
let c = eng.compile_ref("1 || 0 && 0").unwrap();
assert_eq!(c.eval(&[]).unwrap(), 1.0);
let c2 = eng.compile_ref("(1 || 0) && 0").unwrap();
assert_eq!(c2.eval(&[]).unwrap(), 0.0);
}
#[test]
fn call_primary_with_max_against_mul() {
let mut eng = Tabula::new();
let c = eng.compile_ref("max(1, 2) + 3 * 4").unwrap();
assert_eq!(c.eval(&[]).unwrap(), 14.0);
let c2 = eng.compile_ref("(max(1, 2) + 3) * 4").unwrap();
assert_eq!(c2.eval(&[]).unwrap(), 20.0); }