Download rust/crates/hyperkitty-sla/src/conserved.rs from Snapkitty/hyperkitty-constraint-dsl: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/Snapkitty/hyperkitty-constraint-dsl/resolve/main/rust/crates/hyperkitty-sla/src/conserved.rs
- Command line
-
hf download hf://Snapkitty/hyperkitty-constraint-dsl/rust/crates/hyperkitty-sla/src/conserved.rs
-
curl -L -o conserved.rs https://huggingface.co/Snapkitty/hyperkitty-constraint-dsl/resolve/main/rust/crates/hyperkitty-sla/src/conserved.rs
1.27 kB
| //! Conserved value enforcement for ω | |
| use super::ledger::Ledger; | |
| /// Check if omega (conserved value) is consistent | |
| pub fn is_conserved(ledger: &Ledger) -> bool { | |
| // ω must not be zero (reserved value) | |
| ledger.omega != 0 | |
| } | |
| /// Enforce conservation across composition | |
| pub fn conserves_in_composition(a: &Ledger, b: &Ledger) -> bool { | |
| a.omega == b.omega | |
| } | |
| mod tests { | |
| use super::*; | |
| fn nonzero_conserved() { | |
| let ledger = Ledger { | |
| s: 100, | |
| delta: 50, | |
| iota: -50, | |
| omega: 42, | |
| }; | |
| assert!(is_conserved(&ledger)); | |
| } | |
| fn zero_not_conserved() { | |
| let ledger = Ledger { | |
| s: 100, | |
| delta: 50, | |
| iota: -50, | |
| omega: 0, | |
| }; | |
| assert!(!is_conserved(&ledger)); | |
| } | |
| fn composition_conservation() { | |
| let a = Ledger { | |
| s: 100, | |
| delta: 50, | |
| iota: -50, | |
| omega: 42, | |
| }; | |
| let b = Ledger { | |
| s: 50, | |
| delta: 25, | |
| iota: -25, | |
| omega: 42, | |
| }; | |
| assert!(conserves_in_composition(&a, &b)); | |
| } | |
| } | |