summaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: a6cd2ef755cc1fc3d937ef17804ee904e1d9f728 (plain)
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

pub struct BCH {
    m: u32,
}

impl BCH {
    pub fn new(m: u32, _t: u32, _prim_poly: u32) -> Option<BCH> {
        let _err: u32 = 0;
        let _i: u32;
        let _words: u32;
        let _genpoly: u32;

        const MIN_M: u32 = 5;
        const MAX_M: u32 = 15;

        if (m < MIN_M) || (m > MAX_M) {
            // `m` values must be between5 and 15 in this implementation
            return None
        }

        Some(BCH {
            m
        })
    }

    pub fn decode(self) -> u32{
        return self.m
    }
}

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

    #[test]
    fn test_bch_init() {
        let bch = BCH::new(6, 0, 0).unwrap();
        assert_eq!(bch.decode(), 6);
    }

    #[test]
    fn fail_m_values() {
        let bch = BCH::new(4, 0, 0);
        assert_eq!(bch.is_none(), true);
        let bch = BCH::new(16, 0, 0);
        assert_eq!(bch.is_none(), true);
    }
}