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
43
44
45
46
47
48
use std::sync::Mutex;

use crate::{Error, LaserScan2D, Scan2D};

#[derive(Debug, Default)]
pub struct DummyLaserScan2D {
    scan: Mutex<Scan2D>,
}

impl DummyLaserScan2D {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn set_scan(&self, scan: Scan2D) {
        *self.scan.lock().unwrap() = scan;
    }
}

impl LaserScan2D for DummyLaserScan2D {
    fn current_scan(&self) -> Result<Scan2D, Error> {
        Ok(self.scan.lock().unwrap().clone())
    }
}

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

    #[test]
    fn test_scan() {
        let laser_scan = DummyLaserScan2D::new();
        assert_eq!(laser_scan.current_scan().unwrap(), Scan2D::default());
        laser_scan.set_scan(Scan2D {
            angle_min: 1.0,
            angle_max: 2.0,
            ..Default::default()
        });
        assert_eq!(
            laser_scan.current_scan().unwrap(),
            Scan2D {
                angle_min: 1.0,
                angle_max: 2.0,
                ..Default::default()
            }
        );
    }
}