bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.4k stars 3.59k forks source link

remove gcd impl from bevy_render #16419

Closed atlv24 closed 1 week ago

atlv24 commented 1 week ago

Objective

Solution

Testing

BenjaminBrienen commented 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

BenjaminBrienen commented 1 week ago

assert_eq! could've been used, but it doesn't matter at all for this.

atlv24 commented 1 week ago

assert_eq! cant be used, it doesnt work in const {} context

atlv24 commented 1 week ago

i can add tests, most of the renderer doesnt have any

atlv24 commented 1 week ago

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

atlv24 commented 1 week ago

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
}