From 61f081036cbf7b8e44bc3a05a685101dd5c5b562 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Sun, 22 Sep 2024 14:50:03 +0000 Subject: [PATCH] polynomial: expand unit tests --- src/primitives/polynomial.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/primitives/polynomial.rs b/src/primitives/polynomial.rs index 0c60f584..04860020 100644 --- a/src/primitives/polynomial.rs +++ b/src/primitives/polynomial.rs @@ -359,22 +359,25 @@ impl Iterator for RootIter { #[cfg(test)] mod tests { + use Fe32 as F; + use super::*; use crate::{Fe1024, Fe32}; #[test] #[cfg(feature = "alloc")] fn roots() { - let bip93_poly: Polynomial = { - use Fe32 as F; - [F::S, F::S, F::C, F::M, F::L, F::E, F::E, F::E, F::Q, F::G, F::_3, F::M, F::E, F::P] - } - .iter() - .copied() - .collect(); + #[rustfmt::skip] + let mut bip93_poly = Polynomial::with_monic_leading_term( + &[F::E, F::M, F::_3, F::G, F::Q, F::E, F::E, F::E, F::L, F::M, F::C, F::S, F::S] + ); + assert_eq!(bip93_poly.leading_term(), F::P); + assert!(!bip93_poly.zero_is_root()); assert_eq!(bip93_poly.degree(), 13); + bip93_poly.zero_pad_up_to(1000); // should have no visible effect + let (elem, order, root_indices) = bip93_poly.bch_generator_primitive_element::(); // Basically, only the order and the length of the `root_indices` range are // guaranteed to be consistent across runs. There will be two possible ranges, @@ -422,18 +425,15 @@ mod tests { } #[test] - #[cfg(not(feature = "alloc"))] - fn roots() { + fn roots_bech32() { // Exactly the same test as above, but for bech32 - let bech32_poly: Polynomial = { - use Fe32 as F; - [F::J, F::A, F::_4, F::_5, F::K, F::A, F::P] - } - .iter() - .copied() - .collect(); + let bech32_poly = + Polynomial::with_monic_leading_term(&[F::A, F::K, F::_5, F::_4, F::A, F::J]); - assert_eq!(bech32_poly.degree(), 6); + assert_eq!( + bech32_poly.iter().copied().collect::>(), + [F::J, F::A, F::_4, F::_5, F::K, F::A, F::P], + ); let (elem, order, root_indices) = bech32_poly.bch_generator_primitive_element::(); // As above, only the order and the length of the `root_indices` range are