Skip to main content

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 { value: 1 };
38
39    /// Returns an instantiation of [`Z`] with value `0`.
40    ///
41    /// # Examples
42    /// ```
43    /// use qfall_math::integer::Z;
44    ///  
45    /// let a: Z = Z::ZERO;
46    /// ```
47    pub const ZERO: Z = Z { value: 0 };
48
49    /// Returns an instantiation of [`Z`] with value `-1`.
50    ///
51    /// # Examples
52    /// ```
53    /// use qfall_math::integer::Z;
54    ///  
55    /// let a: Z = Z::MINUS_ONE;
56    /// ```
57    pub const MINUS_ONE: Z = Z { value: -1 };
58}
59
60#[cfg(test)]
61mod tests_init {
62    use super::Z;
63
64    /// Ensure that [`Default`] initializes [`Z`] with `0`.
65    #[test]
66    fn init_default() {
67        assert_eq!(Z::ZERO, Z::default());
68    }
69
70    /// Ensure that `ZERO` initializes [`Z`] with `0`.
71    #[test]
72    fn init_zero() {
73        assert_eq!(Z::from(0), Z::ZERO);
74    }
75
76    /// Ensure that `ONE` initializes [`Z`] with `1`.
77    #[test]
78    fn init_one() {
79        assert_eq!(Z::from(1), Z::ONE);
80    }
81
82    /// Ensure that `MINUS_ONE` initializes [`Z`] with `-1`.
83    #[test]
84    fn init_minus_one() {
85        assert_eq!(Z::from(-1), Z::MINUS_ONE);
86    }
87}