132 lines
3.6 KiB
Rust
132 lines
3.6 KiB
Rust
use hcie_protocol::{BlendMode, Tool};
|
|
|
|
#[test]
|
|
fn test_to_u32_from_u32_roundtrip() {
|
|
let colors = [
|
|
[0, 0, 0, 0],
|
|
[255, 255, 255, 255],
|
|
[128, 64, 32, 200],
|
|
[1, 2, 3, 4],
|
|
[255, 0, 0, 128],
|
|
];
|
|
for &c in &colors {
|
|
let packed = hcie_protocol::colors::to_u32(c);
|
|
let unpacked = hcie_protocol::colors::from_u32(packed);
|
|
assert_eq!(c, unpacked, "round-trip failed for {:?}", c);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_color_constants() {
|
|
assert_eq!(hcie_protocol::colors::TRANSPARENT, [0, 0, 0, 0]);
|
|
assert_eq!(hcie_protocol::colors::BLACK, [0, 0, 0, 255]);
|
|
assert_eq!(hcie_protocol::colors::WHITE, [255, 255, 255, 255]);
|
|
assert_eq!(hcie_protocol::colors::RED, [255, 0, 0, 255]);
|
|
}
|
|
|
|
#[test]
|
|
fn test_lerp_boundaries() {
|
|
assert_eq!(hcie_protocol::lerp(0.0, 100.0, 0.0), 0.0);
|
|
assert_eq!(hcie_protocol::lerp(0.0, 100.0, 1.0), 100.0);
|
|
assert_eq!(hcie_protocol::lerp(0.0, 100.0, 0.5), 50.0);
|
|
}
|
|
|
|
#[test]
|
|
fn test_color_lerp() {
|
|
let a = [0, 0, 0, 0];
|
|
let b = [100, 200, 50, 255];
|
|
let mid = hcie_protocol::colors::lerp(a, b, 0.5);
|
|
assert_eq!(mid[0], 50);
|
|
assert_eq!(mid[1], 100);
|
|
assert_eq!(mid[2], 25);
|
|
assert_eq!(mid[3], 128);
|
|
}
|
|
|
|
#[test]
|
|
fn test_lerp_clamp() {
|
|
assert_eq!(hcie_protocol::lerp(0.0, 100.0, -0.5), 0.0);
|
|
assert_eq!(hcie_protocol::lerp(0.0, 100.0, 1.5), 100.0);
|
|
}
|
|
|
|
#[test]
|
|
fn test_clamp() {
|
|
assert_eq!(hcie_protocol::clamp(5.0, 0.0, 10.0), 5.0);
|
|
assert_eq!(hcie_protocol::clamp(-5.0, 0.0, 10.0), 0.0);
|
|
assert_eq!(hcie_protocol::clamp(15.0, 0.0, 10.0), 10.0);
|
|
}
|
|
|
|
#[test]
|
|
fn test_distance() {
|
|
assert_eq!(hcie_protocol::distance(0.0, 0.0, 3.0, 4.0), 5.0);
|
|
assert_eq!(hcie_protocol::distance(1.0, 1.0, 1.0, 1.0), 0.0);
|
|
}
|
|
|
|
#[test]
|
|
fn test_point_in_rect() {
|
|
assert!(hcie_protocol::point_in_rect(5.0, 5.0, 0.0, 0.0, 10.0, 10.0));
|
|
assert!(!hcie_protocol::point_in_rect(15.0, 5.0, 0.0, 0.0, 10.0, 10.0));
|
|
assert!(hcie_protocol::point_in_rect(5.0, 5.0, 10.0, 10.0, 0.0, 0.0));
|
|
}
|
|
|
|
#[test]
|
|
fn test_thumbnail_nearest() {
|
|
let input = vec![
|
|
255, 0, 0, 255, 0, 255, 0, 255,
|
|
0, 0, 255, 255, 255, 255, 0, 255,
|
|
];
|
|
let thumb = hcie_protocol::thumbnail_nearest(&input, 2, 1, 1, 1);
|
|
assert_eq!(thumb.len(), 4, "should produce 1x1 RGBA");
|
|
assert_eq!(thumb[3], 255, "alpha should be 255");
|
|
}
|
|
|
|
#[test]
|
|
fn test_selection_rect_from_mask() {
|
|
let mask = vec![
|
|
0, 0, 0, 0,
|
|
0, 255, 255, 0,
|
|
0, 255, 255, 0,
|
|
0, 0, 0, 0,
|
|
];
|
|
let rect = hcie_protocol::selection_rect_from_mask(&mask, 4, 4);
|
|
assert_eq!(rect, Some([1, 1, 2, 2]));
|
|
}
|
|
|
|
#[test]
|
|
fn test_blank_mask_no_selection() {
|
|
let mask = vec![0u8; 16];
|
|
assert!(hcie_protocol::selection_rect_from_mask(&mask, 4, 4).is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn test_blend_mode_all_contains_all() {
|
|
assert_eq!(BlendMode::ALL.len(), 28, "should have 28 blend modes");
|
|
}
|
|
|
|
#[test]
|
|
fn test_all_tools_listed() {
|
|
assert_eq!(Tool::ALL.len(), 36, "should have 36 tools");
|
|
}
|
|
|
|
#[test]
|
|
fn test_expand_dirty_bounds() {
|
|
let mut bounds = None;
|
|
hcie_protocol::expand_dirty_bounds(&mut bounds, 10, 10, 5.0, 100, 100);
|
|
assert_eq!(bounds, Some([5, 5, 16, 16]));
|
|
}
|
|
|
|
#[test]
|
|
fn test_version_string_format() {
|
|
let v = hcie_protocol::version_string();
|
|
assert!(v.starts_with("3."), "version should start with 3.x.x");
|
|
}
|
|
|
|
proptest::proptest! {
|
|
#[test]
|
|
fn from_u32_to_u32_roundtrip(r: u8, g: u8, b: u8, a: u8) {
|
|
let rgba = [r, g, b, a];
|
|
let packed = hcie_protocol::colors::to_u32(rgba);
|
|
let unpacked = hcie_protocol::colors::from_u32(packed);
|
|
proptest::prop_assert_eq!(rgba, unpacked);
|
|
}
|
|
}
|