entrenar/integrity/behavioral/
builder.rs1use super::metrics::BehavioralIntegrity;
6use super::violation::MetamorphicViolation;
7
8#[derive(Debug, Clone)]
10pub struct BehavioralIntegrityBuilder {
11 equivalence_score: f64,
12 syscall_match: f64,
13 timing_variance: f64,
14 semantic_equiv: f64,
15 violations: Vec<MetamorphicViolation>,
16 test_count: u32,
17 model_id: String,
18}
19
20impl BehavioralIntegrityBuilder {
21 pub fn new(model_id: impl Into<String>) -> Self {
23 Self {
24 equivalence_score: 0.0,
25 syscall_match: 0.0,
26 timing_variance: 1.0,
27 semantic_equiv: 0.0,
28 violations: Vec::new(),
29 test_count: 0,
30 model_id: model_id.into(),
31 }
32 }
33
34 pub fn equivalence_score(mut self, score: f64) -> Self {
36 self.equivalence_score = score;
37 self
38 }
39
40 pub fn syscall_match(mut self, score: f64) -> Self {
42 self.syscall_match = score;
43 self
44 }
45
46 pub fn timing_variance(mut self, variance: f64) -> Self {
48 self.timing_variance = variance;
49 self
50 }
51
52 pub fn semantic_equiv(mut self, score: f64) -> Self {
54 self.semantic_equiv = score;
55 self
56 }
57
58 pub fn violation(mut self, violation: MetamorphicViolation) -> Self {
60 self.violations.push(violation);
61 self
62 }
63
64 pub fn test_count(mut self, count: u32) -> Self {
66 self.test_count = count;
67 self
68 }
69
70 pub fn build(self) -> BehavioralIntegrity {
72 let mut integrity = BehavioralIntegrity::new(
73 self.equivalence_score,
74 self.syscall_match,
75 self.timing_variance,
76 self.semantic_equiv,
77 self.model_id,
78 );
79 integrity.violations = self.violations;
80 integrity.test_count = self.test_count;
81 integrity
82 }
83}