leebyron / testcheck-js

Generative testing for JavaScript

Home Page:http://leebyron.com/testcheck-js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a generator for non-integer number?

Wizek opened this issue · comments

+1, it's weird that there isn't any

is there any way to write your own generator?

There is not because of how the shrinking behavior works. A typically reasonable stand in is two divide two generated posInt.

You can write your own generator! See map and bind in https://github.com/leebyron/testcheck-js/blob/master/type-definitions/testcheck.d.ts - the only rule for writing new generators is that they must be based on one of the original generators.

In fact, all the generators are based on Int already (even string!)

Thank you, is there any way to write generator which will generate random functions?

Yes:

gen.map(gen.int, () => Math.random())

However shrinking behavior will be broken, since it relies on a stable production of values. That's nearly all of the value of using a generative test framework (and the overhead) so if you need to generate random values for a test, you might be better off with a simple for loop in your unit tests.

@leebyron thats a good example of replacing existing generator, but its not exactly what i need. Lets say i need to create two set of random functions, one from Number -> Number, another one String -> String

So i need to create a new generator, which will be like num2num or str2str

If im missing any piece of documentation, then pls point me

gen.map and gen.bind are the two functions for building new generators.

But again, randomness does not work well with shrinking generative tests. Determinism is critical

Just updated to depend on the latest cljs test.check library which provides a generator for floating-point numbers! It even will generate Infinity, NaN, and shrink in an ergonomic way, it's pretty great.

yay, thats cool

thank you