use sysinfo::Networks;

pub fn get(networks: &Networks) -> (u64, u64) {
    let rx: u64 = networks.values().map(|n| n.total_received()).sum();
    let tx: u64 = networks.values().map(|n| n.total_transmitted()).sum();
    (rx, tx)
}

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

    #[test]
    fn test_network_values_non_negative() {
        let mut nets = Networks::new_with_refreshed_list();
        nets.refresh();
        let (rx, tx) = get(&nets);
        // Les compteurs cumulatifs sont toujours >= 0 (u64)
        let _ = rx;
        let _ = tx;
    }
}
