From 19ffcada4af7290776027f1180b6bd14b9aa32e1 Mon Sep 17 00:00:00 2001 From: xfy Date: Mon, 15 Jun 2026 11:26:24 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E7=A7=BB=E9=99=A4=E8=84=86=E5=BC=B1?= =?UTF-8?q?=E6=96=AD=E8=A8=80=E4=B8=8E=E5=87=91=E6=95=B0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=EF=BC=88review=20=E4=BF=AE=E6=AD=A3=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对本次新增测试自审后的清理: 1. webp: encode_lower_quality_produces_smaller_or_equal_bytes 原断言“低质量体积 <= 高质量体积”是 WebP 的统计趋势而非 确定性不变量,依赖底层 libwebp 量化策略,纯色图上高低差异 接近 0,未来库升级易变为 flaky。改为验证两个质量档位都能 成功编码并产生可被本模块解码的合法 WebP。 2. theme: theme_is_copy Copy 语义由编译器在编译期保证,运行期断言永真,不测任何 运行逻辑,属凑数。 3. webp: webp_config_default_quality_and_method 构造 struct 再断言字段等于构造时填入的值,是同义反复。 净减 2 个测试(292 → 290),全部通过。 --- src/theme.rs | 10 ---------- src/webp.rs | 31 +++++++++---------------------- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/src/theme.rs b/src/theme.rs index c34e40b..54d2e9a 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -226,16 +226,6 @@ mod tests { assert_ne!(Theme::Light, Theme::Dark); } - #[test] - fn theme_is_copy() { - // 确认 Theme 实现了 Copy,赋值后原值仍可用。 - let a = Theme::Light; - let b = a; - assert_eq!(a, b); - // 再次使用 a,若未实现 Copy 则编译失败。 - let _ = a.toggle(); - } - #[test] fn theme_preload_script_adds_dark_class() { // 预加载脚本必须包含给 documentElement 添加 dark class 的逻辑。 diff --git a/src/webp.rs b/src/webp.rs index ac2aacc..b1987a2 100644 --- a/src/webp.rs +++ b/src/webp.rs @@ -276,20 +276,18 @@ mod tests { } #[test] - fn encode_lower_quality_produces_smaller_or_equal_bytes() { - // 对同一张随机内容图,更低质量通常不产生更大的输出。 - // 使用固定尺寸的纯色图保证可复现:低质量下体积应 <= 高质量体积。 + fn encode_lower_quality_does_not_explode_on_solid_color() { + // 纯色图是 WebP 的极端情况(信息熵接近 0),确保高低质量都能编码成功 + // 而非 panic,且产物是合法非空字节流。不假设低质量体积一定更小, + // 因为这依赖底层 libwebp 的量化策略,非确定性不变量。 let img = image::DynamicImage::new_rgb8(64, 64); let high = encode(&img, 95.0, 4).unwrap(); let low = encode(&img, 10.0, 4).unwrap(); - assert!( - low.len() <= high.len(), - "lower quality ({}) should not exceed higher quality ({}); got low={} high={}", - 10.0, - 95.0, - low.len(), - high.len() - ); + assert!(!high.is_empty()); + assert!(!low.is_empty()); + // 两者都应是合法的 WebP(能被本模块解码回来)。 + assert!(decode(&high).is_ok()); + assert!(decode(&low).is_ok()); } #[test] @@ -323,15 +321,4 @@ mod tests { assert_eq!(decoded.width(), 16); assert_eq!(decoded.height(), 9); } - - #[test] - fn webp_config_default_quality_and_method() { - // 未设置环境变量时,默认 quality=85.0、method=2(见 WEBP_CONFIG 文档)。 - let config = WebpConfig { - quality: 85.0, - method: 2, - }; - assert_eq!(config.quality, 85.0); - assert_eq!(config.method, 2); - } }