首页 > 解决方案 > 单元测试-如何测试计算是否适合循环的每次迭代?

问题描述

基本上,如何测试 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

标签: pythonunit-testing

解决方案


推荐阅读