helena 0.1.0

Core types and component interfaces for helena, a latent data-to-waveform generation platform.
Documentation
use super::*;
use crate::provenance::Fingerprint;

#[test]
fn serde_round_trips_and_rejects_degenerate() {
    let norm = LatentNorm::new(vec![1.0, -2.0], vec![3.0, 0.5], LatentNorm::DEFAULT_EPS).unwrap();
    let json = serde_json::to_string(&norm).unwrap();
    let back: LatentNorm = serde_json::from_str(&json).unwrap();
    assert_eq!(norm, back);

    // A persisted statistic is a *finished* one, so the decode gate re-proves
    // the invariants (positive std, equal length) rather than re-flooring.
    let bad = r#"{"mean":[0.0],"std":[0.0]}"#;
    assert!(serde_json::from_str::<LatentNorm>(bad).is_err());
    let bad = r#"{"mean":[0.0,0.0],"std":[1.0]}"#;
    assert!(serde_json::from_str::<LatentNorm>(bad).is_err());
}

#[test]
fn equal_statistics_hash_equally() {
    // Uses the canonical fingerprint path (A6) in place of the old ad-hoc
    // `hash::sha256_hex`: equal values digest identically, different ones do not.
    let a = LatentNorm::new(vec![1.0, 2.0], vec![3.0, 4.0], LatentNorm::DEFAULT_EPS).unwrap();
    let same = LatentNorm::new(vec![1.0, 2.0], vec![3.0, 4.0], LatentNorm::DEFAULT_EPS).unwrap();
    let diff = LatentNorm::new(vec![1.0, 2.0], vec![3.0, 4.5], LatentNorm::DEFAULT_EPS).unwrap();
    assert_eq!(
        Fingerprint::of(&a).unwrap(),
        Fingerprint::of(&same).unwrap()
    );
    assert_ne!(
        Fingerprint::of(&a).unwrap(),
        Fingerprint::of(&diff).unwrap()
    );
}