ps_ecc/polynomial/implementations/
debug.rs1use std::fmt::{self, Debug};
2
3use crate::Polynomial;
4
5impl Debug for Polynomial {
6 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7 f.debug_struct("Polynomial")
8 .field("coefficients", &self.coefficients())
9 .field("degree", &self.degree)
10 .finish()
11 }
12}
13
14#[cfg(test)]
15#[allow(clippy::expect_used)]
16mod tests {
17 use crate::Polynomial;
18
19 #[test]
20 fn debug_shows_trimmed_coefficients() {
21 let p = Polynomial::try_from(&[1u8, 2, 3][..]).expect("valid");
22
23 let debug = format!("{p:?}");
24
25 assert!(debug.contains("[1, 2, 3]"));
26 assert!(!debug.contains("[1, 2, 3, 0"));
27 }
28
29 #[test]
30 fn debug_shows_degree() {
31 let p = Polynomial::try_from(&[1u8, 2, 3][..]).expect("valid");
32
33 let debug = format!("{p:?}");
34
35 assert!(debug.contains("degree: 2"));
36 }
37
38 #[test]
39 fn debug_zero_polynomial() {
40 let p = Polynomial::default();
41
42 let debug = format!("{p:?}");
43
44 assert!(debug.contains("[0]"));
45 assert!(debug.contains("degree: 0"));
46 }
47
48 #[test]
49 fn debug_alternate_format() {
50 let p = Polynomial::try_from(&[1u8, 2, 3][..]).expect("valid");
51
52 let debug = format!("{p:#?}");
53
54 assert!(debug.contains("Polynomial"));
55 assert!(debug.contains("coefficients"));
56 assert!(debug.contains("degree"));
57 }
58}