use super::*;
#[test]
fn test_validate_shape_multiple_dims_with_non_power_of_two() {
let result = validate_shape(&[32, 100]);
assert!(matches!(result, Err(TileError::NonPowerOfTwo { dim: 100 })));
}
#[test]
fn test_validate_shape_first_dim_non_power_of_two() {
let result = validate_shape(&[13, 16]);
assert!(matches!(result, Err(TileError::NonPowerOfTwo { dim: 13 })));
}
#[test]
fn test_validate_shape_too_many_elements_exact_boundary() {
assert!(validate_shape(&[4096, 4096]).is_ok());
assert!(matches!(
validate_shape(&[4096, 4096, 2]),
Err(TileError::TooManyElements { .. })
));
}
#[test]
fn test_validate_shape_single_element() {
assert!(validate_shape(&[1]).is_ok());
assert!(validate_shape(&[1, 1]).is_ok());
assert!(validate_shape(&[1, 1, 1]).is_ok());
}
#[test]
fn test_validate_shape_large_valid_multidimensional() {
assert!(validate_shape(&[64, 64, 64]).is_ok()); assert!(validate_shape(&[256, 256, 256]).is_ok()); }
#[test]
fn test_validate_shape_dimension_boundary() {
assert!(validate_shape(&[4096]).is_ok());
assert!(matches!(
validate_shape(&[8192]),
Err(TileError::DimensionTooLarge {
actual: 8192,
max: 4096
})
));
}
#[test]
fn test_validate_shape_zero_dimension_is_ok() {
let result = validate_shape(&[0, 16]);
assert!(result.is_ok());
}
#[test]
fn test_power_of_two_tiles_valid() {
assert!(validate_shape(&[8, 16, 32, 64]).is_ok());
assert!(validate_shape(&[128, 128]).is_ok());
assert!(validate_shape(&[1024, 1024]).is_ok());
assert!(validate_shape(&[4096]).is_ok());
}
#[test]
fn test_non_power_of_two_rejected() {
assert!(matches!(
validate_shape(&[7]),
Err(TileError::NonPowerOfTwo { dim: 7 })
));
assert!(matches!(
validate_shape(&[100]),
Err(TileError::NonPowerOfTwo { dim: 100 })
));
assert!(validate_shape(&[17]).is_err());
assert!(validate_shape(&[1000]).is_err());
}
#[test]
fn test_max_tile_elements_enforced() {
assert!(validate_shape(&[4096, 4096]).is_ok());
assert!(matches!(
validate_shape(&[8192, 4096]),
Err(TileError::TooManyElements { .. })
));
}
#[test]
fn test_max_dimension_enforced() {
assert!(validate_shape(&[4096]).is_ok());
assert!(matches!(
validate_shape(&[8192]),
Err(TileError::DimensionTooLarge { .. })
));
}
#[test]
fn test_validation_catches_invalid_at_build_time() {
let result = validate_shape(&[12345]);
assert!(result.is_err());
}
#[test]
fn test_constraints_backend_agnostic() {
let shape = [32, 32];
assert!(validate_shape(&shape).is_ok());
}
#[test]
fn test_small_tiles_valid() {
assert!(validate_shape(&[4]).is_ok());
assert!(validate_shape(&[8]).is_ok());
assert!(validate_shape(&[2, 2]).is_ok());
}
#[test]
fn test_empty_shape_valid() {
assert!(validate_shape(&[]).is_ok());
}
#[test]
fn test_zero_dimension() {
let result = validate_shape(&[0, 16]);
assert!(result.is_ok() || result.is_err());
}
#[test]
fn test_error_messages_actionable() {
let err = validate_shape(&[17]).unwrap_err();
let msg = err.to_string();
assert!(
msg.contains("17") && msg.contains("power of two"),
"Error message should be actionable: {}",
msg
);
}