Init
This commit is contained in:
152
tests/forth/arithmetic.rs
Normal file
152
tests/forth/arithmetic.rs
Normal file
@@ -0,0 +1,152 @@
|
||||
use super::harness::*;
|
||||
|
||||
#[test]
|
||||
fn add_integers() {
|
||||
expect_int("2 3 +", 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_floats() {
|
||||
expect_int("2.5 3.5 +", 6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_mixed() {
|
||||
expect_float("2 3.5 +", 5.5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sub() {
|
||||
expect_int("10 3 -", 7);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sub_negative() {
|
||||
expect_int("3 10 -", -7);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mul() {
|
||||
expect_int("4 5 *", 20);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mul_floats() {
|
||||
expect_int("2.5 4 *", 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn div() {
|
||||
expect_int("10 2 /", 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn div_float_result() {
|
||||
expect_float("7 2 /", 3.5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modulo() {
|
||||
expect_int("7 3 mod", 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modulo_exact() {
|
||||
expect_int("9 3 mod", 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn neg_int() {
|
||||
expect_int("5 neg", -5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn neg_float() {
|
||||
expect_float("3.5 neg", -3.5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn neg_double() {
|
||||
expect_int("-5 neg", 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn abs_positive() {
|
||||
expect_int("5 abs", 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn abs_negative() {
|
||||
expect_int("-5 abs", 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn abs_float() {
|
||||
expect_float("-3.5 abs", 3.5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn floor() {
|
||||
expect_int("3.7 floor", 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn floor_negative() {
|
||||
expect_int("-3.2 floor", -4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ceil() {
|
||||
expect_int("3.2 ceil", 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ceil_negative() {
|
||||
expect_int("-3.7 ceil", -3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_down() {
|
||||
expect_int("3.4 round", 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_up() {
|
||||
expect_int("3.6 round", 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_half() {
|
||||
expect_int("3.5 round", 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn min() {
|
||||
expect_int("3 5 min", 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn min_reverse() {
|
||||
expect_int("5 3 min", 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn max() {
|
||||
expect_int("3 5 max", 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn max_reverse() {
|
||||
expect_int("5 3 max", 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chain() {
|
||||
// (2 + 3) * 4 - 1 = 19
|
||||
expect_int("2 3 + 4 * 1 -", 19);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn underflow() {
|
||||
expect_error("1 +", "stack underflow");
|
||||
}
|
||||
Reference in New Issue
Block a user