qfall_math/integer/z/
default.rs

1// Copyright © 2023 Marcel Luca Schmidt
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 values for a [`Z`].
10
11use super::Z;
12
13impl Default for Z {
14    /// Returns an instantiation of [`Z`] with value `0`.
15    ///
16    /// # Examples
17    /// ```
18    /// use std::default::Default;
19    /// use qfall_math::integer::Z;
20    ///  
21    /// let a: Z = Z::default();
22    /// ```
23    fn default() -> Self {
24        Z::from(0)
25    }
26}
27
28impl Z {
29    /// Returns an instantiation of [`Z`] with value `1`.
30    ///
31    /// # Examples
32    /// ```
33    /// use qfall_math::integer::Z;
34    ///  
35    /// let a: Z = Z::ONE;
36    /// ```
37    pub const ONE: Z = Z {
38        value: flint_sys::fmpz::fmpz(1),
39    };
40
41    /// Returns an instantiation of [`Z`] with value `0`.
42    ///
43    /// # Examples
44    /// ```
45    /// use qfall_math::integer::Z;
46    ///  
47    /// let a: Z = Z::ZERO;
48    /// ```
49    pub const ZERO: Z = Z {
50        value: flint_sys::fmpz::fmpz(0),
51    };
52
53    /// Returns an instantiation of [`Z`] with value `-1`.
54    ///
55    /// # Examples
56    /// ```
57    /// use qfall_math::integer::Z;
58    ///  
59    /// let a: Z = Z::MINUS_ONE;
60    /// ```
61    pub const MINUS_ONE: Z = Z {
62        value: flint_sys::fmpz::fmpz(-1),
63    };
64}
65
66#[cfg(test)]
67mod tests_init {
68    use super::Z;
69
70    /// Ensure that [`Default`] initializes [`Z`] with `0`.
71    #[test]
72    fn init_default() {
73        assert_eq!(Z::ZERO, Z::default());
74    }
75
76    /// Ensure that `ZERO` initializes [`Z`] with `0`.
77    #[test]
78    fn init_zero() {
79        assert_eq!(Z::from(0), Z::ZERO);
80    }
81
82    /// Ensure that `ONE` initializes [`Z`] with `1`.
83    #[test]
84    fn init_one() {
85        assert_eq!(Z::from(1), Z::ONE);
86    }
87
88    /// Ensure that `MINUS_ONE` initializes [`Z`] with `-1`.
89    #[test]
90    fn init_minus_one() {
91        assert_eq!(Z::from(-1), Z::MINUS_ONE);
92    }
93}