set_theory 1.0.0

A comprehensive mathematical set theory library implementing standard set operations, multisets, and set laws verification
Documentation
//! # Pretty Print Utilities
//!
//! Provides custom formatting for sets.

use crate::models::CustomSet;
use std::hash::Hash;

/// Trait for pretty printing sets with custom formatting.
pub trait PrettyPrint {
    /// Returns a pretty-printed string representation.
    fn pretty(&self) -> String;

    /// Returns a compact string representation.
    fn compact(&self) -> String;
}

impl<T: Eq + Hash + Clone + std::fmt::Display> PrettyPrint for CustomSet<T> {
    fn pretty(&self) -> String {
        if self.is_empty() {
            "".to_string()
        } else {
            let elements: Vec<_> = self.iter().collect();
            format!(
                "{{ {} }}",
                elements
                    .iter()
                    .map(|e| e.to_string())
                    .collect::<Vec<_>>()
                    .join(", ")
            )
        }
    }

    fn compact(&self) -> String {
        if self.is_empty() {
            "".to_string()
        } else {
            let elements: Vec<_> = self.iter().collect();
            format!(
                "{{{}}}",
                elements
                    .iter()
                    .map(|e| e.to_string())
                    .collect::<Vec<_>>()
                    .join(",")
            )
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_pretty_print() {
        let set = CustomSet::from(vec![1, 2, 3]);
        let pretty = set.pretty();
        assert!(pretty.contains("1"));
        assert!(pretty.contains("2"));
        assert!(pretty.contains("3"));
    }

    #[test]
    fn test_compact_print() {
        let set = CustomSet::from(vec![1, 2, 3]);
        let compact = set.compact();
        assert!(compact.starts_with("{"));
        assert!(compact.ends_with("}"));
    }

    #[test]
    fn test_empty_pretty() {
        let empty = CustomSet::<i32>::empty();
        assert_eq!(empty.pretty(), "");
        assert_eq!(empty.compact(), "");
    }
}