zlacker

[parent] [thread] 2 comments
1. MrJohz+(OP)[view] [source] 2024-06-06 05:57:36
I'm not sure about the property-based testing thing. In this example, yes, you can easily write a test case that compares against the string-based algorithm. But in general, this is one of the biggest weaknesses of PBT, which is that you need to find a good property to test.

In a lot of cases, the most useful property is "for all inputs, the result is the right answer", but we don't know the right answer until we've written the algorithm, and there's not usually much point writing two algorithms unless, like here, one of those algorithms is trivial correct but inappropriate for some reason.

More generally, I feel like the more trivial a property is to check, the simpler the code to implement it is, and the less useful the test is in general. In the extreme case, a getter/setter pair is very easy to test with PBT, but you rarely need to be testing your getters and setters.

replies(1): >>fanf2+fi
2. fanf2+fi[view] [source] 2024-06-06 08:55:13
>>MrJohz+(OP)
Counting digits is very closely adjacent to the general category of parsing and printing (or serialization/deserialization), which are both tricky to get right and have simple correctness tests. They are perfect candidates for property-based testing.
replies(1): >>MrJohz+142
◧◩
3. MrJohz+142[view] [source] [discussion] 2024-06-06 20:21:18
>>fanf2+fi
But how do you do PBT here without having a known-correct algorithm available? Because that scenario is seldom the case in practice.
[go to top]