use crate::constraint::{Constraint, ConstraintID, Created, Equality, Provenance, RemovedReason};
use crate::logical_memory::{LogicalMemoryProfile, LogicalMemoryVisitor, Path};
use std::mem::size_of;
impl LogicalMemoryProfile for ConstraintID {
fn visit_logical_memory<V: LogicalMemoryVisitor>(&self, path: &mut Path, visitor: &mut V) {
visitor.visit_leaf(path, size_of::<ConstraintID>());
}
}
impl LogicalMemoryProfile for Equality {
fn visit_logical_memory<V: LogicalMemoryVisitor>(&self, path: &mut Path, visitor: &mut V) {
visitor.visit_leaf(path, size_of::<Equality>());
}
}
impl LogicalMemoryProfile for Provenance {
fn visit_logical_memory<V: LogicalMemoryVisitor>(&self, path: &mut Path, visitor: &mut V) {
visitor.visit_leaf(path, size_of::<Provenance>());
}
}
impl LogicalMemoryProfile for Constraint<Created> {
fn visit_logical_memory<V: LogicalMemoryVisitor>(&self, path: &mut Path, visitor: &mut V) {
self.equality
.visit_logical_memory(path.with("Constraint.equality").as_mut(), visitor);
self.stage
.visit_logical_memory(path.with("Constraint.stage").as_mut(), visitor);
}
}
impl LogicalMemoryProfile for (Constraint<Created>, RemovedReason) {
fn visit_logical_memory<V: LogicalMemoryVisitor>(&self, path: &mut Path, visitor: &mut V) {
self.0
.visit_logical_memory(path.with("RemovedConstraint").as_mut(), visitor);
self.1.visit_logical_memory(
path.with("RemovedConstraint.removed_reason").as_mut(),
visitor,
);
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::logical_memory::logical_memory_to_folded;
use crate::{coeff, linear, Function};
#[test]
fn test_constraint_snapshot() {
let constraint = Constraint::equal_to_zero(Function::Linear(
coeff!(2.0) * linear!(1) + coeff!(3.0) * linear!(2),
));
let folded = logical_memory_to_folded(&constraint);
insta::assert_snapshot!(folded);
}
}