test: test set
This commit is contained in:
86
src/lib.rs
86
src/lib.rs
@@ -1019,4 +1019,90 @@ mod tests {
|
||||
|
||||
assert_eq!(d1, d2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_valid_position() {
|
||||
let mut m = Matrix::new(2, 2, Fraction::from(0)).unwrap();
|
||||
|
||||
m.set(0, 1, Fraction::from(5)).unwrap();
|
||||
|
||||
assert_eq!(*m.get(0, 1).unwrap(), Fraction::from(5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_first_element() {
|
||||
let mut m = Matrix::new(3, 3, Fraction::from(0)).unwrap();
|
||||
|
||||
m.set(0, 0, Fraction::from(9)).unwrap();
|
||||
|
||||
assert_eq!(*m.get(0, 0).unwrap(), Fraction::from(9));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_last_element() {
|
||||
let mut m = Matrix::new(2, 2, Fraction::from(0)).unwrap();
|
||||
|
||||
m.set(1, 1, Fraction::from(7)).unwrap();
|
||||
|
||||
assert_eq!(*m.get(1, 1).unwrap(), Fraction::from(7));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_out_of_bounds_row() {
|
||||
let mut m = Matrix::new(2, 2, Fraction::from(0)).unwrap();
|
||||
|
||||
let result = m.set(2, 0, Fraction::from(1));
|
||||
|
||||
assert!(matches!(result, Err(MatrixError::IndexOutOfRange)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_out_of_bounds_column() {
|
||||
let mut m = Matrix::new(2, 2, Fraction::from(0)).unwrap();
|
||||
|
||||
let result = m.set(0, 2, Fraction::from(1));
|
||||
|
||||
assert!(matches!(result, Err(MatrixError::IndexOutOfRange)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_does_not_affect_other_elements() {
|
||||
let mut m = Matrix::new(2, 2, Fraction::from(1)).unwrap();
|
||||
|
||||
m.set(0, 1, Fraction::from(99)).unwrap();
|
||||
|
||||
// solo cambia ese elemento
|
||||
assert_eq!(*m.get(0, 0).unwrap(), Fraction::from(1));
|
||||
assert_eq!(*m.get(0, 1).unwrap(), Fraction::from(99));
|
||||
assert_eq!(*m.get(1, 0).unwrap(), Fraction::from(1));
|
||||
assert_eq!(*m.get(1, 1).unwrap(), Fraction::from(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_overwrite_value() {
|
||||
let mut m = Matrix::new(2, 2, Fraction::from(3)).unwrap();
|
||||
|
||||
m.set(1, 0, Fraction::from(8)).unwrap();
|
||||
m.set(1, 0, Fraction::from(10)).unwrap();
|
||||
|
||||
assert_eq!(*m.get(1, 0).unwrap(), Fraction::from(10));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_consistency_with_manual_index() {
|
||||
let mut m = Matrix {
|
||||
rows: 3,
|
||||
columns: 3,
|
||||
data: vec![Fraction::from(0); 9],
|
||||
};
|
||||
|
||||
for r in 0..3 {
|
||||
for c in 0..3 {
|
||||
let val = Fraction::from((r * 3 + c) as i64);
|
||||
m.set(r, c, val.clone()).unwrap();
|
||||
|
||||
assert_eq!(*m.get(r, c).unwrap(), val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user