argumentation_weighted_bipolar/
types.rs1use crate::error::Error;
7pub use argumentation_weighted::types::{AttackWeight, Budget, WeightedAttack};
8
9#[derive(Debug, Clone, PartialEq)]
16pub struct WeightedSupport<A: Clone + Eq> {
17 pub supporter: A,
19 pub supported: A,
21 pub weight: AttackWeight,
23}
24
25impl<A: Clone + Eq> WeightedSupport<A> {
26 pub fn new(supporter: A, supported: A, weight: f64) -> Result<Self, Error> {
29 if supporter == supported {
30 return Err(Error::IllegalSelfSupport);
31 }
32 let w = AttackWeight::new(weight).map_err(|_| Error::InvalidWeight { weight })?;
33 Ok(Self { supporter, supported, weight: w })
34 }
35}
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
42 fn weighted_support_new_validates_weight() {
43 assert!(WeightedSupport::new("a", "b", 0.5).is_ok());
44 assert!(WeightedSupport::new("a", "b", -1.0).is_err());
45 assert!(WeightedSupport::new("a", "b", f64::NAN).is_err());
46 }
47
48 #[test]
49 fn weighted_support_rejects_self_support() {
50 let err = WeightedSupport::new("a", "a", 0.5).unwrap_err();
51 assert!(matches!(err, Error::IllegalSelfSupport));
52 }
53}