测试例程后不可读的快速检查日志文件

时间:2015-05-25 15:58:12

标签: haskell character-encoding cabal quickcheck

我使用quickcheck为Haskell程序做了一个测试程序。我在我的cabal文件中声明了它:

Test-Suite routine_de_test
  Type:               exitcode-stdio-1.0
  Hs-Source-Dirs:     test
  Main-is:            Tests.hs

并以:

启动它
cabal configure --enable-tests
cabal buil
cabal test

测试处理正确,我希望在日志文件dist/test/中看到有关每个测试使用的随机值的详细信息,但是当我打开它时,文件看起来像这样:

enter image description here

我尝试使用多种编码(UTF8,ISO-8859-15,...)打开文件,但没有任何更改。

这是正常的吗?或者有什么不对吗?

从cabal执行quickcheck测试是否可以获得每个测试使用的随机值的完整列表?

1 个答案:

答案 0 :(得分:1)

看起来有趣的角色只是退格,而快速检查只是通过用(0 tests)然后(1 test)覆盖(2 tests)然后使用(3 tests)来报告它迄今为止执行的测试次数trace等等。

视觉上显示给终端时看起来很好。

更新

要报告用于测试的随机值,我知道的唯一方法是编写测试以显式显示(或保存到文件)所使用的值。

如果您的测试是纯函数,则可以使用Debug.Trace中的prop_commutes :: Int -> Int -> Bool prop_commutes a b = a + b == b + a 函数。例如,如果您有此属性:

prop_commutes

您可以通过以下方式修改import Debug.Trace prop_commutes :: Int -> Int -> Bool prop_commutes x y = a + b == b + a where (a,b) = trace ("(a,b) = " ++ show (x,y)) (x,y) 的每个调用:

quickCheck prop_commutes

然后(x,y) = (20,-73) (x,y) = (71,-36) (x,y) = (2,-11) ... 会发出如下行:

class Student {

  public final static List<Student> allCreatedStudents = new ArrayList<Student>();

  String name;
  int[] grades = new int[3];

  public Student(String name){
    this.name = name;
    allCreatedStudents.add(this); // Every time a student is created, he is recorded in the static list
  }

  public void setGrade(int grade, int index){
    this.grades[index] = grade;
  }

  public static int getHighestGrade(){
    int highestGrade = 0;
    for(Student s : allCreatedStudents){  // Loop through all students
      for(int i=0; i<s.grades.length; i++){  // Loop through all grades
        if(s.grades[i]>highestGrade)
          highestGrade = s.grades[i];
      }
    }
    return highestGrade;
  }

}

除了正常输出外。