3 ms·
I have to share this testing code I came across yesterday: https://github.com/dgryski/go-tinymap/blob/master/tinymap_test.go https://github.com/dgryski/go-tinym
by nemo1618 9y ago
I have to share this testing code I came across yesterday: https://github.com/dgryski/go-tinymap/blob/master/tinymap_test.go https://github.com/dgryski/go-tinymap/blob/master/tinymap_te...
It uses two neat strategies:
- testing/quick is used to generate random test cases that try to produce a failure, and;
- when a failure is found, another algorithm kicks in that minimizes the input that caused the failure, removing any superfluous operations.
The former uses a helper function that converts a `[]byte` (supplied by testing/quick) to a list of operations. This has a nice secondary benefit, which is that the same helper function can be used with fuzzing libraries.
The latter is really handy because testing/quick generates rather unusual test cases, and it can be hard to piece together which part of a large input caused the failure.
Very cool!
- Keats 9y agoIsn't that just quickcheck?
- burntsushi 9y agoNo. I mean, conceptually, sure, it's very similar. But QuickCheck is data type driven. The underlying library here is ddmin, and it seems to operate on []byte directly: https://github.com/dgryski/go-ddmin/blob/master/ddmin.go https://github.com/dgryski/go-ddmin/blob/master/ddmin.go --- The corresponding paper is here: https://www.st.cs.uni-saarland.de/papers/tse2002/tse2002.pdf https://www.st.cs.uni-saarland.de/papers/tse2002/tse2002.pdf (I am somewhat surprised that the paper doesn't mention QuickCheck at all. Although, I believe QuickCheck was published in 2000, so it had only been out for two years by then. So maybe I shouldn't be surprised actually.) See also: http://hypothesis.works/ http://hypothesis.works/