use super::MatPolyOverZ;
use crate::{
integer::{MatZ, PolyOverZ, Z},
macros::compare_base::compare_base_default,
traits::CompareBase,
};
use flint_sys::fmpz_poly_mat::fmpz_poly_mat_equal;
impl PartialEq for MatPolyOverZ {
fn eq(&self, other: &Self) -> bool {
unsafe { 1 == fmpz_poly_mat_equal(&self.matrix, &other.matrix) }
}
}
impl Eq for MatPolyOverZ {}
compare_base_default!(MatPolyOverZ for MatPolyOverZ MatZ PolyOverZ);
impl<Integer: Into<Z>> CompareBase<Integer> for MatPolyOverZ {}
#[cfg(test)]
mod test_partial_eq {
use super::MatPolyOverZ;
use std::str::FromStr;
#[test]
#[allow(clippy::op_ref)]
fn equal_call_methods() {
let mat_1 = "[[2 24 42],[2 24 42]]";
let mat_2 = "[[2 24 42],[2 24 42]]";
let one_1 = MatPolyOverZ::from_str(mat_1).unwrap();
let one_2 = MatPolyOverZ::from_str(mat_2).unwrap();
assert!(one_1 == one_2);
assert!(&one_1 == &one_2);
assert!(one_1.eq(&one_2));
assert!(MatPolyOverZ::eq(&one_1, &one_2));
assert_eq!(one_1, one_2);
}
#[test]
#[allow(clippy::op_ref)]
fn not_equal_call_methods() {
let mat_1 = "[[2 24 42],[2 24 42]]";
let mat_2 = "[[2 24 42],[3 24 42 17]]";
let one = MatPolyOverZ::from_str(mat_1).unwrap();
let two = MatPolyOverZ::from_str(mat_2).unwrap();
assert!(one != two);
assert!(&one != &two);
assert!(one.ne(&two));
assert!(MatPolyOverZ::ne(&one, &two));
assert_ne!(one, two);
}
#[test]
fn equal_small() {
let mat_small_1 = "[[1 10],[3 24 42 17]]";
let mat_small_2 = "[[1 10],[3 24 42 17]]";
let mat_negative = "[[1 -10],[3 24 42 17]]";
let small_1 = MatPolyOverZ::from_str(mat_small_1).unwrap();
let small_2 = MatPolyOverZ::from_str(mat_small_2).unwrap();
let negative = MatPolyOverZ::from_str(mat_negative).unwrap();
assert!(small_1 == small_2);
assert!(small_2 == small_1);
assert!(small_1 == small_1);
assert!(!(small_1 == negative));
assert!(!(negative == small_1));
}
#[test]
fn not_equal_small() {
let mat_small_1 = "[[1 10],[3 24 42 17]]";
let mat_small_2 = "[[1 10],[3 24 42 17]]";
let mat_negative = "[[1 -10],[3 24 42 17]]";
let small_1 = MatPolyOverZ::from_str(mat_small_1).unwrap();
let small_2 = MatPolyOverZ::from_str(mat_small_2).unwrap();
let negative = MatPolyOverZ::from_str(mat_negative).unwrap();
assert!(!(small_1 != small_2));
assert!(!(small_2 != small_1));
assert!(!(small_1 != small_1));
assert!(small_1 != negative);
assert!(negative != small_1);
}
#[test]
fn equal_large() {
let max_str = format!("[[1 {}],[2 17 42]]", u64::MAX);
let min_str = format!("[[1 {}],[2 17 42]]", i64::MIN);
let max_1 = MatPolyOverZ::from_str(&max_str).unwrap();
let max_2 = MatPolyOverZ::from_str(&max_str).unwrap();
let min = MatPolyOverZ::from_str(&min_str).unwrap();
assert!(max_1 == max_2);
assert!(max_2 == max_1);
assert!(max_1 == max_1);
assert!(min == min);
assert!(!(max_1 == min));
assert!(!(min == max_1));
}
#[test]
fn not_equal_large() {
let max_str = format!("[[1 {}],[2 17 42]]", u64::MAX);
let min_str = format!("[[1 {}],[2 17 42]]", i64::MIN);
let max_1 = MatPolyOverZ::from_str(&max_str).unwrap();
let max_2 = MatPolyOverZ::from_str(&max_str).unwrap();
let min = MatPolyOverZ::from_str(&min_str).unwrap();
assert!(!(max_1 != max_2));
assert!(!(max_2 != max_1));
assert!(!(max_1 != max_1));
assert!(!(min != min));
assert!(max_1 != min);
assert!(min != max_1);
}
#[test]
fn equal_large_small() {
let max_str = format!("[[1 {}],[2 17 42]]", u64::MAX);
let min_str = format!("[[1 {}],[2 17 42]]", i64::MIN);
let max = MatPolyOverZ::from_str(&min_str).unwrap();
let min = MatPolyOverZ::from_str(&max_str).unwrap();
let small_positive = MatPolyOverZ::from_str("[[1 1],[2 17 42]]").unwrap();
let small_negative = MatPolyOverZ::from_str("[[1 -1],[2 17 42]]").unwrap();
assert!(!(max == small_negative));
assert!(!(small_negative == max));
assert!(!(max == small_positive));
assert!(!(small_positive == max));
assert!(!(min == small_negative));
assert!(!(small_negative == min));
assert!(!(min == small_positive));
assert!(!(small_positive == min));
}
#[test]
fn not_equal_large_small() {
let max_str = format!("[[1 {}],[2 17 42]]", u64::MAX);
let min_str = format!("[[1 {}],[2 17 42]]", i64::MIN);
let max = MatPolyOverZ::from_str(&min_str).unwrap();
let min = MatPolyOverZ::from_str(&max_str).unwrap();
let small_positive = MatPolyOverZ::from_str("[[1 1],[2 17 42]]").unwrap();
let small_negative = MatPolyOverZ::from_str("[[1 -1],[2 17 42]]").unwrap();
assert!(max != small_negative);
assert!(small_negative != max);
assert!(max != small_positive);
assert!(small_positive != max);
assert!(min != small_negative);
assert!(small_negative != min);
assert!(min != small_positive);
assert!(small_positive != min);
}
}
#[cfg(test)]
mod test_compare_base {
use crate::{
integer::{MatPolyOverZ, MatZ, Z},
traits::CompareBase,
};
use std::str::FromStr;
#[test]
fn availability() {
let one_1 = MatPolyOverZ::from_str("[[2 24 47],[2 24 42]]").unwrap();
assert!(one_1.compare_base(&MatZ::new(1, 1)));
assert!(one_1.compare_base(&MatPolyOverZ::new(1, 1)));
assert!(one_1.compare_base(&Z::ONE));
assert!(one_1.compare_base(&0_i8));
assert!(one_1.compare_base(&0_i16));
assert!(one_1.compare_base(&0_i32));
assert!(one_1.compare_base(&0_i64));
assert!(one_1.compare_base(&0_u8));
assert!(one_1.compare_base(&0_u16));
assert!(one_1.compare_base(&0_u32));
assert!(one_1.compare_base(&0_u64));
assert!(one_1.call_compare_base_error(&MatZ::new(1, 1)).is_none());
assert!(
one_1
.call_compare_base_error(&MatPolyOverZ::new(1, 1))
.is_none()
);
assert!(one_1.call_compare_base_error(&Z::ONE).is_none());
assert!(one_1.call_compare_base_error(&0_i8).is_none());
assert!(one_1.call_compare_base_error(&0_i16).is_none());
assert!(one_1.call_compare_base_error(&0_i32).is_none());
assert!(one_1.call_compare_base_error(&0_i64).is_none());
assert!(one_1.call_compare_base_error(&0_u8).is_none());
assert!(one_1.call_compare_base_error(&0_u16).is_none());
assert!(one_1.call_compare_base_error(&0_u32).is_none());
assert!(one_1.call_compare_base_error(&0_u64).is_none());
}
}