qfall_math/rational/poly_over_q/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 [`PolyOverQ`].
10
11use super::PolyOverQ;
12use flint_sys::fmpq_poly::fmpq_poly_init;
13use std::mem::MaybeUninit;
14
15impl Default for PolyOverQ {
16 /// Initializes a [`PolyOverQ`] as the zero polynomial.
17 ///
18 /// # Examples
19 /// ```
20 /// use qfall_math::rational::PolyOverQ;
21 ///
22 /// let zero = PolyOverQ::default();
23 /// ```
24 fn default() -> Self {
25 let mut poly = MaybeUninit::uninit();
26 unsafe {
27 fmpq_poly_init(poly.as_mut_ptr());
28 let poly = poly.assume_init();
29 Self { poly }
30 }
31 }
32}
33
34/// Ensure that default initializes an empty polynomial
35#[cfg(test)]
36mod test_default {
37 use crate::rational::PolyOverQ;
38
39 /// Ensure that [`Default`] initializes the zero polynomial appropriately
40 #[test]
41 fn init_zero() {
42 let poly_over_zero = PolyOverQ::default();
43
44 assert_eq!(PolyOverQ::default(), poly_over_zero);
45 }
46}