Fork me on GitHub

is it possible to write a meaningful "not"-generator? in my case I have a bunch of specs and I use clojure.spec.gen.alpha/generate for automatic testing. it just struck me that it might sense for some falsifying tests, i.e. checking that my code actually throws exceptions on invalid data


if you have a spec you could do something like (gen/such-that (complement passes-the-spec?) gen/any)


kind of sloppy/stupid but also it's one line


haha, interesting. could be nice to just throw at the program to see what happens 🙂


I just started thinking that it might be too naive to only test for "valid" data (it's an input form)


Yeah that's a tough use case I think. There's a variety of options with different tradeoffs, and no holistic silver bullet thing


makes sense. I guess I could try generating random strings and just filter away the ones that are actually valid


Two things are Just use examples Generate valid things and then tweak them in specific ways


thanks for the input, will think a bit about it 🙂

👍 3

I'm very happy because today I managed to create automatic gui / end-to-end testing by using cljs + spec generators 🙂


it looks very cool to have everything filled out for me. will be a nice demo to show when talking about clojure with my colleagues


As a maybe-already-obvious example, generating strings of 10 characters where each character is uniformly chosen from the set of all Unicode code points, and then filtering only the ones that contain only ASCII characters, is extremely unlikely to get past the ASCII filter.


@andy.fingerhut was that aimed at me? 🙂


It was following up on your conversation, yes.


ah, okay. yeah, then I get what you mean 🙂 I was thinking if there might be something "cleverer", or an obvious answer that I didn't know about. thanks ^^


Obviously for that simple example, if you want to guarantee all-ASCII strings, it is straightforward to generate them that way in the first place, and then no filter is needed. But when the condition you want to satisfy has more interdependence between the parts, it can get very tricky.