Fork me on GitHub
#test-check
<
2020-09-28
>
Saikyun12:09:12

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

gfredericks12:09:21

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

gfredericks12:09:43

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

Saikyun17:09:08

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

Saikyun17:09:36

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

gfredericks17:09:12

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

Saikyun17:09:53

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

gfredericks17:09:57

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

Saikyun17:09:29

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

👍 3
Saikyun17:09:33

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

Saikyun17:09:55

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

andy.fingerhut17:09:20

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.

Saikyun17:09:14

@andy.fingerhut was that aimed at me? 🙂

andy.fingerhut17:09:01

It was following up on your conversation, yes.

Saikyun17:09:57

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 ^^

andy.fingerhut17:09:26

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.