ys1r/
pac.rs

1/// Represents a Pac instance with a name and a list of elements.
2#[derive(Debug)]
3pub struct Pac {
4    /// The name of the Pac instance.
5    pub name: String,
6    /// A vector of strings representing the elements of the Pac instance.
7    pub elements: Vec<String>,
8}
9
10impl Pac {
11    /// Returns a string representation of the Pac instance.
12    /// Format: "name,element1,element2,..."
13    pub fn inspect(&self) -> String {
14        let elements_str = self.elements.join(",");
15        format!("{},{}", self.name, elements_str)
16    }
17
18    /// Returns the number of elements in the Pac instance.
19    pub fn num_of_ele(&self) -> usize {
20        self.elements.len()
21    }
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn test_inspect() {
30        let pac = Pac {
31            name: String::from("Test - Pac"),
32            elements: vec![String::from("element_1"), String::from("element_2")],
33        };
34        assert_eq!(pac.inspect(), "Test - Pac,element_1,element_2");
35    }
36
37    #[test]
38    fn test_num_of_ele() {
39        let pac = Pac {
40            name: String::from("Test - Pac"),
41            elements: vec![String::from("element_1"), String::from("element_2")],
42        };
43        assert_eq!(pac.num_of_ele(), 2);
44    }
45}