1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use super::EnergyMonitor;

#[derive(Copy, Clone, Debug)]
pub struct DummyEnergyMonitor;

pub const DUMMY_ENERGY_MONITOR: DummyEnergyMonitor = DummyEnergyMonitor;

impl EnergyMonitor for DummyEnergyMonitor {
    fn read_uj(&self) -> Result<u64, &'static str> {
        Ok(0)
    }

    fn source(&self) -> String {
        "Dummy Energy Monitor".to_owned()
    }

    fn interval_us(&self) -> u64 {
        1
    }

    fn precision_uj(&self) -> u64 {
        1
    }

    fn is_exclusive(&self) -> bool {
        false
    }
}

#[cfg(test)]
mod test {
    use super::DUMMY_ENERGY_MONITOR;
    use super::super::EnergyMonitor;

    #[test]
    fn test() {
        assert!(DUMMY_ENERGY_MONITOR.interval_us() == 1);
        assert!(DUMMY_ENERGY_MONITOR.precision_uj() == 1);
        assert!(DUMMY_ENERGY_MONITOR.is_exclusive() == false);
        assert!(DUMMY_ENERGY_MONITOR.read_uj().unwrap() == 0);
    }
}