test(magnitude): 3 unit tests — epsilon parity, counterfactual weight, micro-reward scaling

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2026-04-08 17:39:58 +02:00
parent e48f2510d6
commit d0f5e322b1

View File

@@ -170,4 +170,38 @@ mod tests {
"Flat × mag={mag} must be zero");
}
}
#[test]
fn test_magnitude_epsilon_equals_direction() {
let eps_start = 0.20_f64;
let eps_end = 0.02;
let eps_old_mag = eps_end + 0.1 * (eps_start - eps_end);
let eps_new_mag = eps_start;
assert!(eps_new_mag > eps_old_mag * 4.0,
"New magnitude epsilon ({eps_new_mag}) should be >4× old ({eps_old_mag})");
assert!((eps_new_mag - eps_start).abs() < 1e-10,
"Magnitude epsilon should equal direction epsilon");
}
#[test]
fn test_counterfactual_weight() {
let cf_weight = 0.3_f64;
let flat_fraction = 0.58;
let effective = cf_weight * flat_fraction + 1.0 * (1.0 - flat_fraction);
assert!(effective > 0.5, "Effective gradient should be >50%: {effective}");
assert!(effective < 1.0, "Counterfactual must reduce magnitude gradient: {effective}");
let amp = 1.0 / effective;
assert!((amp - 1.68).abs() < 0.1, "Expected ~1.68× amplification, got {amp}");
}
#[test]
fn test_magnitude_micro_reward_scaling() {
let dir_reward = 0.01_f64;
let adaptive_scale = 1.0;
let micro_vol = 0.005;
let small_reward = adaptive_scale * dir_reward * 0.25 / micro_vol;
let full_reward = adaptive_scale * dir_reward * 1.00 / micro_vol;
assert!((full_reward / small_reward - 4.0).abs() < 1e-10,
"Full/Small reward ratio should be 4.0, got {}", full_reward / small_reward);
}
}