testing

Testing tools, testing philosophy & methodology...
dharrigan 2019-05-07T20:08:53.048300Z

Is there a standard approach for testing a function that takes a single parameter (and evals to true/false), but have a test that you feed it a list (or vector) of values to test? I have something like this:

dharrigan 2019-05-07T20:09:30.049300Z

(t/deftest test-palindromes
  (for [x palindromes]
     (t/is (= true (p/palindrome? x)))))

dharrigan 2019-05-07T20:10:38.050400Z

Feels a bit clunky. Ideally, i would like an indvidual test for each element in the vector (in this case, palindromes), but there could be a lot!

seancorfield 2019-05-07T20:24:10.050900Z

It feels like a job for generative testing...

dharrigan 2019-05-07T20:34:26.051400Z

can generative testing generate palindromes?

dharrigan 2019-05-07T20:34:59.051800Z

(I have about 20 words and a few sentences that are palindromes)

seancorfield 2019-05-07T20:40:32.053400Z

Generate random strings and append them, reversed, to themselves, and you have randomly generated palindromes. That will test cases involving empty strings and weird characters. You can also append them, reversed with the first character removed, to get odd-length palindromes.

seancorfield 2019-05-07T20:41:14.054200Z

The key property to test there is if you give your function random strings that are known to be palindromic, it will return true for all of them.

dharrigan 2019-05-07T20:41:49.054700Z

Good point!

dharrigan 2019-05-07T20:41:52.055Z

Thanks for the insight 🙂

dharrigan 2019-05-07T20:42:43.056100Z

I'll have to go away now and look at how to do generative testing (which I saw briefly on my skim so far)

seancorfield 2019-05-07T20:43:07.056500Z

You could test for the false case by generating random strings and then filtering out those that start and end with the same character (strings need to be at least length 2).

dharrigan 2019-05-07T20:43:28.056900Z

great! thank you kindly! 🙂