from openrgb_hue.color import Color, hsv_lerp, rgb_lerp, rgb_to_hsv def test_color_clamps_out_of_range(): assert Color(300, -10, 128) == Color(255, 0, 128) def test_color_hex_roundtrip(): c = Color(18, 52, 86) assert c.to_hex() == "123456" assert Color.from_hex("#123456") == c def test_rgb_lerp_endpoints_and_midpoint(): a, b = Color(0, 0, 0), Color(100, 200, 50) assert rgb_lerp(a, b, 0.0) == a assert rgb_lerp(a, b, 1.0) == b mid = rgb_lerp(a, b, 0.5) assert mid == Color(50, 100, 25) def test_hsv_lerp_endpoints(): a, b = Color(255, 0, 0), Color(0, 0, 255) assert hsv_lerp(a, b, 0.0) == a assert hsv_lerp(a, b, 1.0) == b def test_hsv_lerp_takes_shortest_hue_path(): # Hue 350deg -> 10deg should pass through 0deg/360deg, not through 180deg. a = Color.from_hex("#ff0022") # hue ~350deg b = Color.from_hex("#ff2200") # hue ~10deg mid = hsv_lerp(a, b, 0.5) mid_h, _, _ = rgb_to_hsv(mid) # Near 0/360deg, not anywhere near 180deg. assert mid_h < 0.05 or mid_h > 0.95 def test_scale_brightness(): c = Color(200, 100, 50) assert c.scale_brightness(0.5) == Color(100, 50, 25) assert c.scale_brightness(0.0) == Color(0, 0, 0) def test_to_openrgb_conversion(): c = Color(1, 2, 3) rgb = c.to_openrgb() assert (rgb.red, rgb.green, rgb.blue) == (1, 2, 3)