Skip to main content

things3_core/database/
stats.rs

1//! Aggregate database statistics.
2
3use serde::{Deserialize, Serialize};
4
5/// Database statistics
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct DatabaseStats {
8    pub task_count: u64,
9    pub project_count: u64,
10    pub area_count: u64,
11}
12
13impl DatabaseStats {
14    #[must_use]
15    pub fn total_items(&self) -> u64 {
16        self.task_count + self.project_count + self.area_count
17    }
18}
19
20#[cfg(test)]
21mod tests {
22    use super::*;
23
24    #[test]
25    fn test_database_stats_total_items() {
26        let stats = DatabaseStats {
27            task_count: 10,
28            project_count: 5,
29            area_count: 3,
30        };
31        assert_eq!(stats.total_items(), 18);
32
33        let empty_stats = DatabaseStats {
34            task_count: 0,
35            project_count: 0,
36            area_count: 0,
37        };
38        assert_eq!(empty_stats.total_items(), 0);
39    }
40}