test-check

Saikyun 2020-09-28T12:31:12.009400Z

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

2020-09-28T12:51:21.010100Z

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

2020-09-28T12:51:43.010400Z

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

Saikyun 2020-09-28T17:13:08.011Z

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

Saikyun 2020-09-28T17:13:36.011800Z

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

2020-09-28T17:15:12.013600Z

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

Saikyun 2020-09-28T17:15:53.014900Z

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

2020-09-28T17:15:57.015300Z

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

Saikyun 2020-09-28T17:16:07.015500Z

right

Saikyun 2020-09-28T17:16:29.015800Z

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

👍 1
Saikyun 2020-09-28T17:17:33.016600Z

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

Saikyun 2020-09-28T17:17:55.017100Z

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

2020-09-28T17:18:47.017300Z

Nice

😋 1
2020-09-28T17:23:20.018700Z

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.

Saikyun 2020-09-28T17:25:14.019100Z

@andy.fingerhut was that aimed at me? 🙂

2020-09-28T17:26:01.019500Z

It was following up on your conversation, yes.

Saikyun 2020-09-28T17:29:57.020200Z

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

2020-09-28T17:47:26.021500Z

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.