1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright © 2026 Mikhail Hogrefe
//
// This file is part of Malachite.
//
// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
use core::str::FromStr;
use malachite_base::test_util::generators::unsigned_vector_gen;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
#[test]
fn test_set_zero() {
let test = |s, out| {
let mut v = UnsignedVector::<u8>::from_str(s).unwrap();
v.set_zero();
assert_eq!(v.to_string(), out);
};
test("()", "()");
test("(0)", "(0)");
test("(1, 2, 3)", "(0, 0, 0)");
}
#[test]
fn set_zero_properties() {
unsigned_vector_gen().test_properties(|v| {
let mut x = v.clone();
x.set_zero();
// The dimension is kept, and the result is the zero vector of that dimension.
assert_eq!(x.dimension(), v.dimension());
assert_eq!(x, UnsignedVector::zero(v.dimension()));
assert_eq!(x.pivot_index(), None);
// Doing it again changes nothing.
let mut y = x.clone();
y.set_zero();
assert_eq!(y, x);
// It is the same as emptying the vector and growing it back with zeros.
let mut z = v.clone();
z.set_dimension(0);
z.set_dimension(v.dimension());
assert_eq!(z, x);
});
}