use crate::model::recall::recency;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ContactOutcome {
Learn,
Stifle,
}
pub fn on_contact(listener_knows: bool) -> ContactOutcome {
if listener_knows {
ContactOutcome::Stifle
} else {
ContactOutcome::Learn
}
}
pub fn telling_weight(valence: f32, belief: f32, hours_since_heard: f32) -> f32 {
valence.abs() * belief * recency(hours_since_heard)
}
pub fn belief_after_hearing(teller_belief: f32, trust_listener_to_teller: f32) -> f32 {
teller_belief * (0.5 + 0.5 * trust_listener_to_teller.clamp(0.0, 1.0))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn telling_someone_who_knows_stifles() {
assert_eq!(on_contact(true), ContactOutcome::Stifle);
assert_eq!(on_contact(false), ContactOutcome::Learn);
}
#[test]
fn fresher_and_stronger_rumors_are_told_first() {
assert!(telling_weight(-0.7, 1.0, 0.0) > telling_weight(-0.3, 1.0, 0.0));
assert!(telling_weight(-0.7, 1.0, 1.0) > telling_weight(-0.7, 1.0, 100.0));
}
#[test]
fn belief_is_scaled_by_trust() {
assert!((belief_after_hearing(1.0, 1.0) - 1.0).abs() < 1e-6);
assert!((belief_after_hearing(1.0, 0.0) - 0.5).abs() < 1e-6);
assert!((belief_after_hearing(1.0, 5.0) - 1.0).abs() < 1e-6);
}
}