test: 移除脆弱断言与凑数测试(review 修正)
对本次新增测试自审后的清理: 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),全部通过。
This commit is contained in:
parent
263208b930
commit
19ffcada4a
10
src/theme.rs
10
src/theme.rs
@ -226,16 +226,6 @@ mod tests {
|
|||||||
assert_ne!(Theme::Light, Theme::Dark);
|
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]
|
#[test]
|
||||||
fn theme_preload_script_adds_dark_class() {
|
fn theme_preload_script_adds_dark_class() {
|
||||||
// 预加载脚本必须包含给 documentElement 添加 dark class 的逻辑。
|
// 预加载脚本必须包含给 documentElement 添加 dark class 的逻辑。
|
||||||
|
|||||||
31
src/webp.rs
31
src/webp.rs
@ -276,20 +276,18 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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 img = image::DynamicImage::new_rgb8(64, 64);
|
||||||
let high = encode(&img, 95.0, 4).unwrap();
|
let high = encode(&img, 95.0, 4).unwrap();
|
||||||
let low = encode(&img, 10.0, 4).unwrap();
|
let low = encode(&img, 10.0, 4).unwrap();
|
||||||
assert!(
|
assert!(!high.is_empty());
|
||||||
low.len() <= high.len(),
|
assert!(!low.is_empty());
|
||||||
"lower quality ({}) should not exceed higher quality ({}); got low={} high={}",
|
// 两者都应是合法的 WebP(能被本模块解码回来)。
|
||||||
10.0,
|
assert!(decode(&high).is_ok());
|
||||||
95.0,
|
assert!(decode(&low).is_ok());
|
||||||
low.len(),
|
|
||||||
high.len()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -323,15 +321,4 @@ mod tests {
|
|||||||
assert_eq!(decoded.width(), 16);
|
assert_eq!(decoded.width(), 16);
|
||||||
assert_eq!(decoded.height(), 9);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user