use pnc_engine::{parse, value::Value};
#[test]
fn add_two_ints() {
let mut stack = Vec::new();
parse::eval_line(&mut stack, "2 3 +").unwrap();
assert_eq!(stack, vec![Value::Int(5.into())]);
}
#[test]
fn div_exact_stays_int() {
let mut stack = Vec::new();
parse::eval_line(&mut stack, "4 2 /").unwrap();
assert_eq!(stack, vec![Value::Int(2.into())]);
}
#[test]
fn div_inexact_becomes_rational() {
let mut stack = Vec::new();
parse::eval_line(&mut stack, "15 2 /").unwrap();
assert_eq!(
stack,
vec![Value::Rational(num_rational::BigRational::new(
15.into(),
2.into()
))]
);
}
#[test]
fn promotion_int_times_rational() {
let mut stack = Vec::new();
parse::eval_line(&mut stack, "1 2 / 3 *").unwrap();
assert_eq!(
stack,
vec![Value::Rational(num_rational::BigRational::new(
3.into(),
2.into()
))]
);
}