Words and universal macOS installer
This commit is contained in:
@@ -176,3 +176,80 @@ fn logrand_requires_positive() {
|
||||
fn rand_equal_bounds() {
|
||||
expect_float("5.0 5.0 rand", 5.0);
|
||||
}
|
||||
|
||||
// bounce
|
||||
|
||||
#[test]
|
||||
fn bounce_sequence() {
|
||||
let expected = [60, 64, 67, 72, 67, 64, 60, 64];
|
||||
for (runs, &exp) in expected.iter().enumerate() {
|
||||
let ctx = ctx_with(|c| c.runs = runs);
|
||||
let f = run_ctx("60 64 67 72 4 bounce", &ctx);
|
||||
assert_eq!(stack_int(&f), exp, "bounce at runs={}", runs);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bounce_single() {
|
||||
for runs in 0..5 {
|
||||
let ctx = ctx_with(|c| c.runs = runs);
|
||||
let f = run_ctx("42 1 bounce", &ctx);
|
||||
assert_eq!(stack_int(&f), 42, "bounce single at runs={}", runs);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bounce_zero_count() {
|
||||
expect_error("1 2 3 0 bounce", "bounce count must be > 0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bounce_underflow() {
|
||||
expect_error("1 2 5 bounce", "stack underflow");
|
||||
}
|
||||
|
||||
// wchoose
|
||||
|
||||
#[test]
|
||||
fn wchoose_all_weight_one_item() {
|
||||
for _ in 0..10 {
|
||||
let f = forth_seeded(42);
|
||||
f.evaluate("10 0.0 20 1.0 2 wchoose", &default_ctx())
|
||||
.unwrap();
|
||||
assert_eq!(stack_int(&f), 20);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wchoose_deterministic() {
|
||||
let f1 = forth_seeded(99);
|
||||
let f2 = forth_seeded(99);
|
||||
f1.evaluate("60 0.6 64 0.3 67 0.1 3 wchoose", &default_ctx())
|
||||
.unwrap();
|
||||
f2.evaluate("60 0.6 64 0.3 67 0.1 3 wchoose", &default_ctx())
|
||||
.unwrap();
|
||||
assert_eq!(f1.stack(), f2.stack());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wchoose_zero_count() {
|
||||
expect_error("0 wchoose", "wchoose count must be > 0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wchoose_underflow() {
|
||||
expect_error("10 0.5 2 wchoose", "stack underflow");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wchoose_negative_weight() {
|
||||
expect_error("10 -0.5 20 1.0 2 wchoose", "negative weight");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wchoose_quotation() {
|
||||
let f = forth_seeded(42);
|
||||
f.evaluate("{ 10 } 0.0 { 20 } 1.0 2 wchoose", &default_ctx())
|
||||
.unwrap();
|
||||
assert_eq!(stack_int(&f), 20);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user