reputation-types 0.1.0

Core types and data structures for the KnowThat Reputation Engine
Documentation
use std::fmt;
use crate::{AgentData, ReputationScore, ConfidenceLevel};

impl fmt::Display for ConfidenceLevel {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            ConfidenceLevel::Low => write!(f, "Low"),
            ConfidenceLevel::Medium => write!(f, "Medium"),
            ConfidenceLevel::High => write!(f, "High"),
        }
    }
}

impl fmt::Display for AgentData {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "Agent {} - Reviews: {}/{}, Rating: {:.1}",
            self.did,
            self.total_reviews,
            self.total_interactions,
            self.average_rating.unwrap_or(0.0)
        )
    }
}

impl fmt::Display for ReputationScore {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "Score: {:.1}/100 (Confidence: {} - {:.1}%)",
            self.score,
            self.level,
            self.confidence * 100.0
        )
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{AgentDataBuilder, ScoreComponents, PriorBreakdown};
    use chrono::Utc;

    #[test]
    fn test_confidence_level_display() {
        assert_eq!(format!("{}", ConfidenceLevel::Low), "Low");
        assert_eq!(format!("{}", ConfidenceLevel::Medium), "Medium");
        assert_eq!(format!("{}", ConfidenceLevel::High), "High");
    }

    #[test]
    fn test_agent_data_display() {
        let agent = AgentDataBuilder::new("did:test:123")
            .with_reviews(50, 4.5)
            .total_interactions(100)
            .build()
            .unwrap();
        
        let display = format!("{}", agent);
        assert_eq!(display, "Agent did:test:123 - Reviews: 50/100, Rating: 4.5");
        
        // Test agent with no rating
        let agent_no_rating = AgentDataBuilder::new("did:test:456")
            .total_interactions(10)
            .build()
            .unwrap();
        
        let display = format!("{}", agent_no_rating);
        assert_eq!(display, "Agent did:test:456 - Reviews: 0/10, Rating: 0.0");
    }

    #[test]
    fn test_reputation_score_display() {
        let components = ScoreComponents {
            prior_score: 65.0,
            prior_breakdown: PriorBreakdown {
                base_score: 50.0,
                mcp_bonus: 10.0,
                identity_bonus: 5.0,
                security_audit_bonus: 0.0,
                open_source_bonus: 0.0,
                age_bonus: 0.0,
                total: 65.0,
            },
            empirical_score: 80.0,
            confidence_value: 0.85,
            confidence_level: ConfidenceLevel::High,
            prior_weight: 0.15,
            empirical_weight: 0.85,
        };
        
        let score = ReputationScore {
            score: 77.3,
            confidence: 0.856,
            level: ConfidenceLevel::High,
            components,
            is_provisional: false,
            data_points: 150,
            algorithm_version: "1.0.0".to_string(),
            calculated_at: Utc::now(),
        };
        
        let display = format!("{}", score);
        assert_eq!(display, "Score: 77.3/100 (Confidence: High - 85.6%)");
    }
}