qfall_math/integer/poly_over_z/default.rs
1// Copyright © 2023 Marvin Beckmann
2//
3// This file is part of qFALL-math.
4//
5// qFALL-math is free software: you can redistribute it and/or modify it under
6// the terms of the Mozilla Public License Version 2.0 as published by the
7// Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>.
8
9//! Default value for a [`PolyOverZ`].
10
11use super::PolyOverZ;
12use flint_sys::fmpz_poly::fmpz_poly_init;
13use std::mem::MaybeUninit;
14
15impl Default for PolyOverZ {
16 /// Initializes a [`PolyOverZ`] with the zero polynomial.
17 ///
18 /// # Examples
19 /// ```
20 /// use qfall_math::integer::PolyOverZ;
21 ///
22 /// let zero = PolyOverZ::default();
23 /// ```
24 fn default() -> Self {
25 let mut poly = MaybeUninit::uninit();
26 unsafe {
27 fmpz_poly_init(poly.as_mut_ptr());
28
29 Self {
30 poly: poly.assume_init(),
31 }
32 }
33 }
34}
35
36/// Ensure that default initializes an empty polynomial
37#[cfg(test)]
38mod test_default {
39 use crate::integer::PolyOverZ;
40
41 /// Check if [`Default`] initializes the zero polynomial appropriately
42 #[test]
43 fn init_zero() {
44 let poly_over_zero = PolyOverZ::default();
45
46 assert_eq!(PolyOverZ::default(), poly_over_zero);
47 }
48}