59 lines
1.3 KiB
Rust
59 lines
1.3 KiB
Rust
use subject_source::vec::compute::*;
|
|
|
|
#[test]
|
|
pub fn compute_empty() {
|
|
assert_eq!(compute(&[]), Err(ComputeError::NotEnoughData));
|
|
}
|
|
|
|
#[test]
|
|
pub fn compute_too_many_ops() {
|
|
assert_eq!(
|
|
compute(&[Operation::Push(1.0), Operation::Binary(Binary::Add)]),
|
|
Err(ComputeError::NotEnoughData)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
pub fn compute_division_by_zero_push() {
|
|
assert_eq!(
|
|
compute(&[
|
|
Operation::Push(1.0),
|
|
Operation::Push(0.0),
|
|
Operation::Binary(Binary::Div)
|
|
]),
|
|
Err(ComputeError::DivisionByZero)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
pub fn compute_division_by_zero_operation() {
|
|
assert_eq!(
|
|
compute(&[
|
|
Operation::Push(1.0),
|
|
Operation::Push(1.0),
|
|
Operation::Push(1.0),
|
|
Operation::Binary(Binary::Sub),
|
|
Operation::Binary(Binary::Div)
|
|
]),
|
|
Err(ComputeError::DivisionByZero)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
pub fn compute_all_ops() {
|
|
assert_eq!(
|
|
compute(&[
|
|
Operation::Push(1.0),
|
|
Operation::Push(3.0),
|
|
Operation::Push(2.0),
|
|
Operation::Binary(Binary::Sub),
|
|
Operation::Push(5.0),
|
|
Operation::Binary(Binary::Mul),
|
|
Operation::Binary(Binary::Add),
|
|
Operation::Push(2.0),
|
|
Operation::Binary(Binary::Div),
|
|
]),
|
|
Ok(3.0),
|
|
);
|
|
}
|