Skip to content

Commit a201050

Browse files
add examples to doc comments
1 parent 8b0230b commit a201050

File tree

5 files changed

+131
-3
lines changed

5 files changed

+131
-3
lines changed

src/integer_mod_q/mat_polynomial_ring_zq/cmp.rs

+32
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ impl CompareBase for MatPolynomialRingZq {
1818
/// - `other`: The other objects whose base is compared to `self`
1919
///
2020
/// Returns true if the moduli match and false otherwise.
21+
///
22+
/// # Example
23+
/// ```
24+
/// use qfall_math::{
25+
/// integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq},
26+
/// traits::CompareBase,
27+
/// };
28+
/// use std::str::FromStr;
29+
///
30+
/// let modulus = ModulusPolynomialRingZq::from_str("3 1 0 1 mod 17").unwrap();
31+
/// let one_1 = MatPolynomialRingZq::identity(10, 7, &modulus);
32+
/// let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 23").unwrap();
33+
/// let one_2 = MatPolynomialRingZq::identity(10, 7, &modulus);
34+
///
35+
/// assert!(!one_1.compare_base(&one_2));
36+
/// ```
2137
fn compare_base(&self, other: &Self) -> bool {
2238
self.get_mod() == other.get_mod()
2339
}
@@ -28,6 +44,22 @@ impl CompareBase for MatPolynomialRingZq {
2844
/// - `other`: The other objects whose base is compared to `self`
2945
///
3046
/// Returns a MathError of type [MathError::MismatchingModulus].
47+
///
48+
/// # Example
49+
/// ```
50+
/// use qfall_math::{
51+
/// integer_mod_q::{MatPolynomialRingZq, ModulusPolynomialRingZq},
52+
/// traits::CompareBase,
53+
/// };
54+
/// use std::str::FromStr;
55+
///
56+
/// let modulus = ModulusPolynomialRingZq::from_str("3 1 0 1 mod 17").unwrap();
57+
/// let one_1 = MatPolynomialRingZq::identity(10, 7, &modulus);
58+
/// let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 23").unwrap();
59+
/// let one_2 = MatPolynomialRingZq::identity(10, 7, &modulus);
60+
///
61+
/// assert!(one_1.call_compare_base_error(&one_2).is_some());
62+
/// ```
3163
fn call_compare_base_error(&self, other: &Self) -> Option<MathError> {
3264
Some(MathError::MismatchingModulus(format!(
3365
"The moduli of the matrices mismatch. One of them is {} and the other is {}.

src/integer_mod_q/mat_zq/cmp.rs

+30
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ impl CompareBase for MatZq {
5454
/// - `other`: The other objects whose base is compared to `self`
5555
///
5656
/// Returns true if the moduli match and false otherwise.
57+
///
58+
/// # Example
59+
/// ```
60+
/// use qfall_math::{
61+
/// integer_mod_q::{MatZq, Modulus},
62+
/// traits::CompareBase,
63+
/// };
64+
///
65+
/// let modulus = Modulus::from(17);
66+
/// let one_1 = MatZq::identity(10, 7, &modulus);
67+
/// let modulus = Modulus::from(19);
68+
/// let one_2 = MatZq::identity(10, 7, &modulus);
69+
///
70+
/// assert!(!one_1.compare_base(&one_2));
71+
/// ```
5772
fn compare_base(&self, other: &Self) -> bool {
5873
self.get_mod() == other.get_mod()
5974
}
@@ -64,6 +79,21 @@ impl CompareBase for MatZq {
6479
/// - `other`: The other objects whose base is compared to `self`
6580
///
6681
/// Returns a MathError of type [MathError::MismatchingModulus].
82+
///
83+
/// # Example
84+
/// ```
85+
/// use qfall_math::{
86+
/// integer_mod_q::{MatZq, Modulus},
87+
/// traits::CompareBase,
88+
/// };
89+
///
90+
/// let modulus = Modulus::from(17);
91+
/// let one_1 = MatZq::identity(10, 7, &modulus);
92+
/// let modulus = Modulus::from(19);
93+
/// let one_2 = MatZq::identity(10, 7, &modulus);
94+
///
95+
/// assert!(one_1.call_compare_base_error(&one_2).is_some())
96+
/// ```
6797
fn call_compare_base_error(&self, other: &Self) -> Option<MathError> {
6898
Some(MathError::MismatchingModulus(format!(
6999
"The moduli of the matrices mismatch. One of them is {} and the other is {}.

src/integer_mod_q/poly_over_zq/cmp.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ impl CompareBase for PolyOverZq {
6464
/// - `other`: The other objects whose base is compared to `self`
6565
///
6666
/// Returns true if the moduli match and false otherwise.
67+
///
68+
/// # Example
69+
/// ```
70+
/// use qfall_math::{integer_mod_q::PolyOverZq, traits::CompareBase};
71+
/// use std::str::FromStr;
72+
///
73+
/// let p1 = PolyOverZq::from_str("2 24 1 mod 17").unwrap();
74+
/// let p2 = PolyOverZq::from_str("2 24 1 mod 19").unwrap();
75+
///
76+
/// assert!(!p1.compare_base(&p2));
77+
/// ```
6778
fn compare_base(&self, other: &Self) -> bool {
6879
self.get_mod() == other.get_mod()
6980
}
@@ -72,10 +83,21 @@ impl CompareBase for PolyOverZq {
7283
/// Parameters:
7384
/// - `other`: The other objects whose base is compared to `self`
7485
///
75-
/// Returns a MathError of type [MathError::MismatchingModulus].
86+
/// Returns a MathError of type [MathError::MismatchingModulus].
87+
///
88+
/// # Example
89+
/// ```
90+
/// use qfall_math::{integer_mod_q::PolyOverZq, traits::CompareBase};
91+
/// use std::str::FromStr;
92+
///
93+
/// let p1 = PolyOverZq::from_str("2 24 1 mod 17").unwrap();
94+
/// let p2 = PolyOverZq::from_str("2 24 1 mod 19").unwrap();
95+
///
96+
/// assert!(p1.call_compare_base_error(&p2).is_some())
97+
/// ```
7698
fn call_compare_base_error(&self, other: &Self) -> Option<MathError> {
7799
Some(MathError::MismatchingModulus(format!(
78-
"The moduli of the matrices mismatch. One of them is {} and the other is {}.
100+
"The moduli of the polynomials mismatch. One of them is {} and the other is {}.
79101
The desired operation is not defined and an error is returned.",
80102
self.get_mod(),
81103
other.get_mod()

src/integer_mod_q/polynomial_ring_zq/cmp.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ impl CompareBase for PolynomialRingZq {
1818
/// - `other`: The other objects whose base is compared to `self`
1919
///
2020
/// Returns true if the moduli match and false otherwise.
21+
///
22+
/// # Example
23+
/// ```
24+
/// use qfall_math::{integer_mod_q::PolynomialRingZq, traits::CompareBase};
25+
/// use std::str::FromStr;
26+
///
27+
/// let p1 = PolynomialRingZq::from_str("0 / 3 1 1 2 mod 7").unwrap();
28+
/// let p2 = PolynomialRingZq::from_str("2 7 14 / 2 1 1 mod 7").unwrap();
29+
///
30+
/// assert!(!p1.compare_base(&p2));
31+
/// ```
2132
fn compare_base(&self, other: &Self) -> bool {
2233
self.get_mod() == other.get_mod()
2334
}
@@ -28,9 +39,20 @@ impl CompareBase for PolynomialRingZq {
2839
/// - `other`: The other objects whose base is compared to `self`
2940
///
3041
/// Returns a MathError of type [MathError::MismatchingModulus].
42+
///
43+
/// # Example
44+
/// ```
45+
/// use qfall_math::{integer_mod_q::PolynomialRingZq, traits::CompareBase};
46+
/// use std::str::FromStr;
47+
///
48+
/// let p1 = PolynomialRingZq::from_str("0 / 3 1 1 2 mod 7").unwrap();
49+
/// let p2 = PolynomialRingZq::from_str("2 7 14 / 2 1 1 mod 7").unwrap();
50+
///
51+
/// assert!(p1.call_compare_base_error(&p2).is_some())
52+
/// ```
3153
fn call_compare_base_error(&self, other: &Self) -> Option<MathError> {
3254
Some(MathError::MismatchingModulus(format!(
33-
"The moduli of the matrices mismatch. One of them is {} and the other is {}.
55+
"The moduli of the polynomial ring elements mismatch. One of them is {} and the other is {}.
3456
The desired operation is not defined and an error is returned.",
3557
self.get_mod(),
3658
other.get_mod()

src/integer_mod_q/z_q/cmp.rs

+22
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ impl CompareBase for Zq {
1818
/// - `other`: The other objects whose base is compared to `self`
1919
///
2020
/// Returns true if the moduli match and false otherwise.
21+
///
22+
/// # Example
23+
/// ```
24+
/// use qfall_math::{integer_mod_q::Zq, traits::CompareBase};
25+
/// use std::str::FromStr;
26+
///
27+
/// let v1 = Zq::from_str("2 mod 17").unwrap();
28+
/// let v2 = Zq::from_str("2 mod 19").unwrap();
29+
///
30+
/// assert!(!v1.compare_base(&v2));
31+
/// ```
2132
fn compare_base(&self, other: &Self) -> bool {
2233
self.get_mod() == other.get_mod()
2334
}
@@ -28,6 +39,17 @@ impl CompareBase for Zq {
2839
/// - `other`: The other objects whose base is compared to `self`
2940
///
3041
/// Returns a MathError of type [MathError::MismatchingModulus].
42+
///
43+
/// # Example
44+
/// ```
45+
/// use qfall_math::{integer_mod_q::Zq, traits::CompareBase};
46+
/// use std::str::FromStr;
47+
///
48+
/// let v1 = Zq::from_str("2 mod 17").unwrap();
49+
/// let v2 = Zq::from_str("2 mod 19").unwrap();
50+
///
51+
/// assert!(v1.call_compare_base_error(&v2).is_some())
52+
/// ```
3153
fn call_compare_base_error(&self, other: &Self) -> Option<MathError> {
3254
Some(MathError::MismatchingModulus(format!(
3355
"The moduli of the ring elements mismatch. One of them is {} and the other is {}.

0 commit comments

Comments
 (0)