Closed atlv24 closed 1 week ago
Shouldn't this have a unit test for at least a few cases?
edit: I guess new() itself probably has a few tests already
assert_eq!
could've been used, but it doesn't matter at all for this.
assert_eq!
cant be used, it doesnt work in const {}
context
i can add tests, most of the renderer doesnt have any
actually adding tests would require implementing gcd again, and if i hardcode values then the tests would literally be testing to check if an array equals itself. not much point here i think
just leaving this here in case anyone wants to slap it into rust playground just to satisfy the itch
fn main() {
for i in 0..200 {
let a = (4 / gcd(i, 4)) as u32;
let b = [1, 4, 2, 4][i as usize & 3];
assert_eq!(a, b);
}
println!("done");
}
fn gcd(mut a: u64, mut b: u64) -> u64 {
while b != 0 {
let t = b;
b = a % b;
a = t;
}
a
}
Objective
Solution
Testing