diff options
| author | Yuval Adam <_@yuv.al> | 2019-03-18 17:11:16 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2019-03-18 17:11:16 +0200 |
| commit | a8b24243e19b5e80373940931fbfb0dea5e8eb8d (patch) | |
| tree | d4418933a74d5e9223bf79baa50485c70337c126 | |
| parent | fa17f132e23118dd88f4726613e8722c8a38f464 (diff) | |
Basic tests
| -rw-r--r-- | src/lib.rs | 37 |
1 files changed, 29 insertions, 8 deletions
@@ -1,17 +1,30 @@ pub struct BCH { - n: u32, + m: u32, } impl BCH { - pub fn new(n: u32) -> BCH { - BCH { - n + 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.n + return self.m } } @@ -20,8 +33,16 @@ mod tests { use super::*; #[test] - fn it_works() { - let bch = BCH::new(3); - assert_eq!(bch.decode(), 3); + 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); } } |
