Feat: lots of things, preparing for live gig

This commit is contained in:
2026-02-15 11:23:11 +01:00
parent cfaadd9d33
commit 160546d64d
59 changed files with 1414 additions and 96 deletions

View File

@@ -59,29 +59,29 @@ fn iter() {
#[test]
fn every_true_on_zero() {
let ctx = ctx_with(|c| c.iter = 0);
let f = run_ctx("4 every", &ctx);
assert_eq!(stack_int(&f), 1);
let f = run_ctx("{ 100 } 4 every", &ctx);
assert_eq!(stack_int(&f), 100);
}
#[test]
fn every_true_on_multiple() {
let ctx = ctx_with(|c| c.iter = 8);
let f = run_ctx("4 every", &ctx);
assert_eq!(stack_int(&f), 1);
let f = run_ctx("{ 100 } 4 every", &ctx);
assert_eq!(stack_int(&f), 100);
}
#[test]
fn every_false_between() {
for i in 1..4 {
let ctx = ctx_with(|c| c.iter = i);
let f = run_ctx("4 every", &ctx);
assert_eq!(stack_int(&f), 0, "iter={} should be false", i);
let f = run_ctx("{ 100 } 4 every", &ctx);
assert!(f.stack().is_empty(), "iter={} should not execute quotation", i);
}
}
#[test]
fn every_zero_count() {
expect_error("0 every", "every count must be > 0");
expect_error("{ 1 } 0 every", "every count must be > 0");
}
#[test]
@@ -97,3 +97,77 @@ fn context_in_computation() {
let f = run_ctx("60 step +", &ctx);
assert_eq!(stack_int(&f), 63);
}
// bjork (runs-based)
#[test]
fn bjork_tresillo() {
// Bresenham(3,8) hits at positions 0, 2, 5
for runs in 0..8 {
let ctx = ctx_with(|c| c.runs = runs);
let f = run_ctx("{ 100 } 3 8 bjork", &ctx);
let hit = ((runs + 1) * 3) / 8 != (runs * 3) / 8;
if hit {
assert_eq!(stack_int(&f), 100, "runs={} should hit", runs);
} else {
assert!(f.stack().is_empty(), "runs={} should miss", runs);
}
}
}
#[test]
fn bjork_hit_count() {
// Bjorklund(3,8) should produce exactly 3 hits
let mut hit_count = 0;
for runs in 0..8 {
let ctx = ctx_with(|c| c.runs = runs);
let f = run_ctx("{ 100 } 3 8 bjork", &ctx);
if !f.stack().is_empty() {
hit_count += 1;
}
}
assert_eq!(hit_count, 3);
}
#[test]
fn bjork_all_hits() {
let ctx = ctx_with(|c| c.runs = 0);
let f = run_ctx("{ 100 } 8 8 bjork", &ctx);
assert_eq!(stack_int(&f), 100);
}
#[test]
fn bjork_zero_hits() {
let ctx = ctx_with(|c| c.runs = 0);
let f = run_ctx("{ 100 } 0 8 bjork", &ctx);
assert!(f.stack().is_empty());
}
#[test]
fn bjork_invalid() {
expect_error("{ 1 } 3 0 bjork", "bjork");
}
// pbjork (iter-based)
#[test]
fn pbjork_cinquillo() {
let mut hit_count = 0;
for iter in 0..8 {
let ctx = ctx_with(|c| c.iter = iter);
let f = run_ctx("{ 100 } 5 8 pbjork", &ctx);
if !f.stack().is_empty() {
hit_count += 1;
}
}
assert_eq!(hit_count, 5);
}
#[test]
fn pbjork_wraps() {
let ctx0 = ctx_with(|c| c.iter = 0);
let ctx8 = ctx_with(|c| c.iter = 8);
let f0 = run_ctx("{ 100 } 3 8 pbjork", &ctx0);
let f8 = run_ctx("{ 100 } 3 8 pbjork", &ctx8);
assert_eq!(f0.stack().is_empty(), f8.stack().is_empty());
}