use symplex::prelude::*;
#[test]
fn simplify_exp_ln() {
let ctx = Context::new();
let x = ctx.symbol("x");
let expr = x.ln().exp();
assert_eq!(format!("{}", expr.simplify()), "x");
}
#[test]
fn simplify_ln_exp() {
let ctx = Context::new();
let x = ctx.symbol_with("x", &[Assumption::Real]);
let expr = x.exp().ln();
assert_eq!(format!("{}", expr.simplify()), "x");
}
#[test]
fn simplify_abs_abs() {
let ctx = Context::new();
let x = ctx.symbol("x");
let expr = x.abs().abs();
assert_eq!(format!("{}", expr.simplify()), "abs(x)");
}
#[test]
fn simplify_pythagorean_in_larger_sum() {
let ctx = Context::new();
let x = ctx.symbol("x");
let expr = &x.sin().powi(2) + &x.cos().powi(2) + 3;
let simplified = expr.simplify();
assert_eq!(format!("{simplified}"), "4");
}
#[test]
fn simplify_pythagorean_in_sum_with_symbols() {
let ctx = Context::new();
let (x, y) = (ctx.symbol("x"), ctx.symbol("y"));
let expr = &y + &x.sin().powi(2) + &x.cos().powi(2);
let simplified = expr.simplify();
assert_eq!(format!("{simplified}"), "y + 1");
}
#[test]
fn simplify_no_sub_match_when_not_applicable() {
let ctx = Context::new();
let x = ctx.symbol("x");
let expr = &x.sin().powi(2) + &x.sin().powi(2);
let simplified = expr.simplify();
let s = format!("{simplified}");
assert!(
!s.contains("1") || s.contains("sin"),
"should not reduce to 1: {s}"
);
}
#[test]
fn eval_sin_pi_over_6() {
let ctx = Context::new();
let expr = (&ctx.pi() / 6).sin();
let result = expr.eval();
assert_eq!(format!("{result}"), "1/2");
}
#[test]
fn eval_cos_pi_over_3() {
let ctx = Context::new();
let expr = (&ctx.pi() / 3).cos();
let result = expr.eval();
assert_eq!(format!("{result}"), "1/2");
}
#[test]
fn eval_tan_pi_over_4() {
let ctx = Context::new();
let expr = (&ctx.pi() / 4).tan();
let result = expr.eval();
assert_eq!(format!("{result}"), "1");
}
#[test]
fn eval_sqrt_nine_fourths() {
let ctx = Context::new();
let expr = ctx.rational(9, 4).sqrt();
let result = expr.eval();
assert_eq!(format!("{result}"), "3/2");
}
#[test]
fn eval_combined_workflow() {
let ctx = Context::new();
let pi_6 = &ctx.pi() / 6;
let expr = &pi_6.sin().powi(2) + &pi_6.cos().powi(2);
let _result = expr.simplify();
let _evaled = expr.eval();
let simplified = expr.simplify();
assert_eq!(
format!("{simplified}"),
"1",
"sin²+cos² should still be 1 via Pythagorean identity"
);
}