python - 单元测试-如何测试计算是否适合循环的每次迭代?
问题描述
基本上,如何测试 for/while 循环。这甚至是一件事吗?我应该只测试计算的输出,看看是否正确?
此代码如下。它是一个在(更大的)图像上运行模板的函数。
def _scan_image(self, image, template, process):
"""main function: will iterate over the image one pixel at a time"""
for i in xrange(len(image)): # --------> I want to test inside this loop
for j in xrange(len(image[i])):
if (j <= self.x_axis_leng) and \
(i <= self.y_axis_hgt):
self.temp_matrix_holder.append(\
image[i][j:j+len(template[0])])
self.temp_matrix_holder.append(\
image[i + 1][j:j+len(template[0])])
new_score = self.calculate.run(\
self.temp_matrix_holder, self.temp, process)
if new_score <= self.score:
self.score = new_score
self.best_location = [j, i]
self._empty_list()
return self.score, self.best_location
解决方案
推荐阅读
- go - 无法通过 SSH 安装 go 模块(私有嵌套存储库)
- hybris - Hybris 生产支持活动
- reporting-services - 对 ssrs 中包含数字和字符串的 nvarchar 列进行排序
- ios - Vision Kit - 提取字典中的图像数据 - iOS
- apache-kafka - Kafka 内部主题:内部主题在哪里创建 - 源代理还是目标代理?
- html - 重新定位图像,然后在屏幕变小时缩小它,没有媒体查询
- laravel - Laravel url方法发布不指向项目文件夹?
- c# - 在 VSTO C# 中获取名字和姓氏
- cmake - 如何识别开源项目二进制文件中实现的代码位置?
- openapi - FastAPI 中不同的 OpenAPI 模式取决于环境