util: test improvements

This commit is contained in:
Simon Gardling 2025-03-28 14:27:44 -04:00
parent 0b3abe71ae
commit ec7cce80b4
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -17,10 +17,95 @@ pub const fn index(width: usize, height: usize, x: f32, y: f32) -> usize {
mod test {
use super::*;
#[test]
fn wrap_test() {
assert_eq!(wrap(1.1, 1.0), 0.100000024); // floating point weirdness
assert_eq!(wrap(0.5, 1.0), 0.5);
assert_eq!(wrap(-1.0, 2.0), 1.0);
mod wrap {
use super::*;
#[test]
fn over() {
assert_eq!(wrap(1.1, 1.0), 0.100000024); // floating point weirdness
}
#[test]
fn middle() {
assert_eq!(wrap(0.5, 1.0), 0.5);
}
#[test]
fn under() {
assert_eq!(wrap(-1.0, 2.0), 1.0);
}
}
mod index {
use super::*;
#[test]
fn basic_positive_coordinates() {
let width = 4;
let height = 4;
assert_eq!(index(width, height, 1.5, 2.5), 9);
}
#[test]
fn negative_x_coordinate() {
let width = 8;
let height = 8;
assert_eq!(index(width, height, -3.2, 5.6), 44);
}
#[test]
fn exact_boundary_values() {
let width = 16;
let height = 16;
assert_eq!(index(width, height, 16.0, 0.0), 0);
}
#[test]
fn large_coordinates() {
let width = 2;
let height = 2;
assert_eq!(index(width, height, 1000.0, 2000.0), 0);
}
#[test]
fn negative_x_and_y() {
let width = 4;
let height = 4;
assert_eq!(index(width, height, -1.5, -0.5), 14);
}
#[test]
fn fractional_truncation() {
let width = 4;
let height = 4;
assert_eq!(index(width, height, 3.9, 3.999), 15);
}
#[test]
fn zero_coordinates() {
let width = 4;
let height = 4;
assert_eq!(index(width, height, 0.0, 0.0), 0);
}
#[test]
fn x_equals_width() {
let width = 8;
let height = 8;
assert_eq!(index(width, height, 8.0, 0.0), 0);
}
#[test]
fn y_negative_beyond_height() {
let width = 4;
let height = 4;
assert_eq!(index(width, height, 0.0, -4.5), 0);
}
#[test]
fn width_and_height_one() {
let width = 1;
let height = 1;
assert_eq!(index(width, height, 123.4, -56.7), 0);
}
}
}