#[cfg(test)]
use super::super::structures::*;
#[test]
fn test_add() {
assert_eq!(Matrix::<1, 1>::new(1.0) + 2.0, Matrix::new(3.0));
assert_eq!(&Matrix::<1, 1>::new(1.0) + 2.0, Matrix::new(3.0));
assert_eq!(1.0 + Matrix::<1, 1>::new(2.0), Matrix::new(3.0));
assert_eq!(1.0 + &Matrix::<1, 1>::new(2.0), Matrix::new(3.0));
assert_eq!(
Matrix::<1, 1>::new(1.0) + Matrix::new(2.0),
Matrix::new(3.0)
);
assert_eq!(
Matrix::<1, 1>::new(1.0) + &Matrix::new(2.0),
Matrix::new(3.0)
);
assert_eq!(
&Matrix::<1, 1>::new(1.0) + Matrix::new(2.0),
Matrix::new(3.0)
);
assert_eq!(
&Matrix::<1, 1>::new(1.0) + &Matrix::new(2.0),
Matrix::new(3.0)
);
}
#[test]
fn test_add_assign() {
let matrix_3 = Matrix::<1, 1>::new(3.0);
let mut matrix = Matrix::<1, 1>::new(1.0);
matrix += 2.0;
assert_eq!(matrix, matrix_3);
let mut matrix = &mut Matrix::<1, 1>::new(1.0);
matrix += 2.0;
assert_eq!(matrix, &matrix_3);
let mut matrix = Matrix::<1, 1>::new(1.0);
matrix += Matrix::<1, 1>::new(2.0);
assert_eq!(matrix, matrix_3);
let mut matrix = Matrix::<1, 1>::new(1.0);
matrix += &Matrix::<1, 1>::new(2.0);
assert_eq!(matrix, matrix_3);
let mut matrix = &mut Matrix::<1, 1>::new(1.0);
matrix += Matrix::<1, 1>::new(2.0);
assert_eq!(matrix, &matrix_3);
let mut matrix = &mut Matrix::<1, 1>::new(1.0);
matrix += &Matrix::<1, 1>::new(2.0);
assert_eq!(matrix, &matrix_3);
}
#[test]
fn test_div() {
let matrix_2 = Matrix::<1, 1>::new(2.0);
assert_eq!(Matrix::<1, 1>::new(6.0) / 3.0, matrix_2);
assert_eq!(&Matrix::<1, 1>::new(6.0) / 3.0, matrix_2);
}
#[test]
fn test_div_assign() {
let matrix_2 = Matrix::<1, 2>::new(2.0);
let mut dividend = Matrix::<1, 2>::new(6.0);
dividend /= 3.0;
assert_eq!(dividend, matrix_2);
let mut dividend = &mut Matrix::<1, 2>::new(6.0);
dividend /= 3.0;
assert_eq!(dividend, &matrix_2);
}
#[test]
fn test_mul() {
let matrix_2 = Matrix::<1, 1>::new(2.0);
assert_eq!(Matrix::<1, 1>::new(1.0) * 2.0, matrix_2);
assert_eq!(&Matrix::<1, 1>::new(1.0) * 2.0, matrix_2);
assert_eq!(2.0 * Matrix::<1, 1>::new(1.0), matrix_2);
assert_eq!(2.0 * &Matrix::<1, 1>::new(1.0), matrix_2);
assert_eq!(
Matrix::<1, 2>::new(1.0) * Matrix::<2, 3>::new(2.0),
Matrix::<1, 3>::new(4.0)
);
assert_eq!(
Matrix::<1, 2>::new(1.0) * &Matrix::<2, 3>::new(2.0),
Matrix::<1, 3>::new(4.0)
);
assert_eq!(
&Matrix::<1, 2>::new(1.0) * Matrix::<2, 3>::new(2.0),
Matrix::<1, 3>::new(4.0)
);
assert_eq!(
&Matrix::<1, 2>::new(1.0) * &Matrix::<2, 3>::new(2.0),
Matrix::<1, 3>::new(4.0)
);
}
#[test]
fn test_mul_assign() {
let mut multiplicand = Matrix::<1, 2>::new(1.0);
multiplicand *= 2.0;
assert_eq!(multiplicand, Matrix::<1, 2>::new(2.0));
let mut multiplicand = &mut Matrix::<1, 2>::new(1.0);
multiplicand *= 2.0;
assert_eq!(multiplicand, &Matrix::<1, 2>::new(2.0));
let mut multiplicand = Matrix::<1, 2>::new(2.0);
let multiplier = Matrix::<2, 2>::new(3.0);
multiplicand *= multiplier;
assert_eq!(multiplicand, Matrix::<1, 2>::new(12.0));
let mut multiplicand = Matrix::<1, 2>::new(2.0);
let multiplier = &Matrix::<2, 2>::new(3.0);
multiplicand *= multiplier;
assert_eq!(multiplicand, Matrix::<1, 2>::new(12.0));
let mut multiplicand = &mut Matrix::<1, 2>::new(2.0);
let multiplier = Matrix::<2, 2>::new(3.0);
multiplicand *= multiplier;
assert_eq!(multiplicand, &Matrix::<1, 2>::new(12.0));
let mut multiplicand = &mut Matrix::<1, 2>::new(2.0);
let multiplier = &Matrix::<2, 2>::new(3.0);
multiplicand *= multiplier;
assert_eq!(multiplicand, &Matrix::<1, 2>::new(12.0));
}
#[test]
fn test_neg() {
assert_eq!(-Matrix::<1, 1>::new(1.0), Matrix::new(-1.0));
assert_eq!(-&Matrix::<1, 1>::new(1.0), Matrix::new(-1.0));
}
#[test]
fn test_sub() {
let matrix_1 = Matrix::<1, 1>::new(1.0);
assert_eq!(Matrix::<1, 1>::new(3.0) - 2.0, matrix_1);
assert_eq!(&Matrix::<1, 1>::new(3.0) - 2.0, matrix_1);
assert_eq!(3.0 - Matrix::<1, 1>::new(2.0), matrix_1);
assert_eq!(3.0 - &Matrix::<1, 1>::new(2.0), matrix_1);
assert_eq!(Matrix::<1, 1>::new(3.0) - Matrix::new(2.0), matrix_1);
assert_eq!(Matrix::<1, 1>::new(3.0) - &Matrix::new(2.0), matrix_1);
assert_eq!(&Matrix::<1, 1>::new(3.0) - Matrix::new(2.0), matrix_1);
assert_eq!(&Matrix::<1, 1>::new(3.0) - &Matrix::new(2.0), matrix_1);
}
#[test]
fn test_sub_assign() {
let matrix_1 = Matrix::<1, 1>::new(1.0);
let mut matrix = Matrix::<1, 1>::new(3.0);
matrix -= 2.0;
assert_eq!(matrix, matrix_1);
let mut matrix = &mut Matrix::<1, 1>::new(3.0);
matrix -= 2.0;
assert_eq!(matrix, &matrix_1);
let mut matrix = Matrix::<1, 1>::new(3.0);
matrix -= Matrix::<1, 1>::new(2.0);
assert_eq!(matrix, matrix_1);
let mut matrix = Matrix::<1, 1>::new(3.0);
matrix -= &Matrix::<1, 1>::new(2.0);
assert_eq!(matrix, matrix_1);
let mut matrix = &mut Matrix::<1, 1>::new(3.0);
matrix -= Matrix::<1, 1>::new(2.0);
assert_eq!(matrix, &matrix_1);
let mut matrix = &mut Matrix::<1, 1>::new(3.0);
matrix -= &Matrix::<1, 1>::new(2.0);
assert_eq!(matrix, &matrix_1);
}