vision/TEST.md

50 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Testing @go/vision
`go/vision` 拥有完善的单元测试覆盖,确保在各种图像处理场景下的稳定性。
## 运行测试
`vision` 目录下运行标准 Go 测试命令:
```bash
go test -v .
```
## 测试覆盖范围
* **Canvas & Drawing**: 验证基础绘图、颜色解析、图层叠加等功能。
* **Intelligence**:
* `QRCode`: 验证二维码的生成与识别一致性。
* `Barcode`: 验证条形码 (Code128, UPC) 的生成与识别。
* `PHash`: 验证相似图片的指纹距离计算。
* **Captcha**: 验证图形验证码的生成。
* **Transform**: 验证缩放、旋转以及复杂的 `WarpPerspective` 透视变换。
* **Animation**: 验证 GIF 序列的合成。
## 视觉回归测试
部分测试会生成临时的图片文件(如 `test.png`, `captcha.png`),测试脚本会自动清理这些文件。在开发新滤镜或绘图功能时,建议手动查看生成的图片以确保视觉效果符合预期。
## 性能基准测试
可以使用以下命令运行基准测试:
```bash
go test -bench .
```
以下是在 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz 环境下的基准测试结果:
| 测试项 | 耗时 (ns/op) |
| :--- | :--- |
| **WarpPerspective** | 8,928,754 |
| **PHash** | 1,041,925 |
| **ExtractPalette** | 453,400 |
## 🛡️ 鲁棒性防御 (Robustness)
- **可选参数提示**`New``Save` 等方法接受指针作为可选参数,结合最新的 `go/js` 引擎智能过滤空参数。
- **JS 错误调用栈**JS 桥接层改用具名导出并使用 `jsmod.MakeError` 包裹错误,确保 JS 抛出异常时携带准确的 Go 运行时堆栈。
---
所有测试均遵循 `@go` 基础设施标准,无外部系统依赖(除 FFmpeg 视频测试外,该部分会自动跳过或提示引导)。