srtree/
params.rs

1#[derive(Clone, Copy)]
2pub struct Params {
3    pub min_number_of_elements: usize,
4    pub max_number_of_elements: usize,
5    pub dimension: usize,
6}
7
8impl Params {
9    #[must_use]
10    pub fn new(min_number_of_elements: usize, max_number_of_elements: usize) -> Option<Params> {
11        if min_number_of_elements > (max_number_of_elements + 1) / 2 {
12            return None;
13        }
14        Some(Params {
15            min_number_of_elements,
16            max_number_of_elements,
17            dimension: 0,
18        })
19    }
20
21    #[must_use]
22    pub fn default_params() -> Params {
23        Params {
24            min_number_of_elements: 8,
25            max_number_of_elements: 20,
26            dimension: 0,
27        }
28    }
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[test]
36    pub fn test_with_invalid_min_num_elements() {
37        let min_num_of_elements_per_node = 6;
38        let max_num_of_elements_per_node = 10;
39        let params = Params::new(min_num_of_elements_per_node, max_num_of_elements_per_node);
40        assert!(params.is_none())
41    }
42
43    #[test]
44    pub fn test_with_valid_params() {
45        let min_num_of_elements_per_node = 4;
46        let max_num_of_elements_per_node = 10;
47        let params = Params::new(min_num_of_elements_per_node, max_num_of_elements_per_node);
48        assert!(params.is_some())
49    }
50}