big commit

This commit is contained in:
2026-01-27 01:04:08 +01:00
parent 66933433d1
commit 5456c9414a
15 changed files with 821 additions and 222 deletions

View File

@@ -130,64 +130,64 @@ fn ramp_with_range() {
}
#[test]
fn noise_deterministic() {
fn perlin_deterministic() {
let ctx = ctx_with(|c| c.beat = 2.7);
let f = forth();
f.evaluate("1.0 noise", &ctx).unwrap();
f.evaluate("1.0 perlin", &ctx).unwrap();
let val1 = stack_float(&f);
f.evaluate("1.0 noise", &ctx).unwrap();
f.evaluate("1.0 perlin", &ctx).unwrap();
let val2 = stack_float(&f);
assert!((val1 - val2).abs() < 1e-9, "noise should be deterministic");
assert!((val1 - val2).abs() < 1e-9, "perlin should be deterministic");
}
#[test]
fn noise_in_range() {
fn perlin_in_range() {
for i in 0..100 {
let ctx = ctx_with(|c| c.beat = i as f64 * 0.1);
let f = forth();
f.evaluate("1.0 noise", &ctx).unwrap();
f.evaluate("1.0 perlin", &ctx).unwrap();
let val = stack_float(&f);
assert!(val >= 0.0 && val <= 1.0, "noise out of range: {}", val);
assert!(val >= 0.0 && val <= 1.0, "perlin out of range: {}", val);
}
}
#[test]
fn noise_varies() {
fn perlin_varies() {
let ctx1 = ctx_with(|c| c.beat = 0.5);
let ctx2 = ctx_with(|c| c.beat = 1.5);
let f = forth();
f.evaluate("1.0 noise", &ctx1).unwrap();
f.evaluate("1.0 perlin", &ctx1).unwrap();
let val1 = stack_float(&f);
f.evaluate("1.0 noise", &ctx2).unwrap();
f.evaluate("1.0 perlin", &ctx2).unwrap();
let val2 = stack_float(&f);
assert!((val1 - val2).abs() > 1e-9, "noise should vary with beat");
assert!((val1 - val2).abs() > 1e-9, "perlin should vary with beat");
}
#[test]
fn noise_smooth() {
fn perlin_smooth() {
let f = forth();
let mut prev = 0.0;
for i in 0..100 {
let ctx = ctx_with(|c| c.beat = i as f64 * 0.01);
f.evaluate("1.0 noise", &ctx).unwrap();
f.evaluate("1.0 perlin", &ctx).unwrap();
let val = stack_float(&f);
if i > 0 {
assert!((val - prev).abs() < 0.2, "noise not smooth: jump {} at step {}", (val - prev).abs(), i);
assert!((val - prev).abs() < 0.2, "perlin not smooth: jump {} at step {}", (val - prev).abs(), i);
}
prev = val;
}
}
#[test]
fn noise_with_range() {
fn perlin_with_range() {
let ctx = ctx_with(|c| c.beat = 1.3);
let f = forth();
f.evaluate("1.0 noise 200.0 800.0 range", &ctx).unwrap();
f.evaluate("1.0 perlin 200.0 800.0 range", &ctx).unwrap();
let val = stack_float(&f);
assert!(val >= 200.0 && val <= 800.0, "noise+range out of bounds: {}", val);
assert!(val >= 200.0 && val <= 800.0, "perlin+range out of bounds: {}", val);
}
#[test]
fn noise_underflow() {
expect_error("noise", "stack underflow");
fn perlin_underflow() {
expect_error("perlin", "stack underflow");
}