Giter Site home page Giter Site logo

sunesimonsen / chance-generators Goto Github PK

View Code? Open in Web Editor NEW
9.0 4.0 1.0 407 KB

Random generators based on changejs

Home Page: https://sunesimonsen.github.io/chance-generators/

License: MIT License

JavaScript 100.00%
property-based-testing generators unexpected testing

chance-generators's People

Contributors

dependabot[bot] avatar papandreou avatar rhendric avatar sunesimonsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

papandreou

chance-generators's Issues

Make generator mappers more discoverable

After I've learned about the map method of generators I'm slowly realizing that the mapper functions themselves are very powerful, reusable and composable. I feel we should encourage sharing of such functions, and maybe add some of the most useful ones to core.

We might also want to consider changing the API slightly. it always occurred to me as odd that it was OK to use a Generators instance declared in an outer scope inside the mapper function body (probably because it looks like a side effect and mapper should be "pure"), for example:

var g = new Generators(424);
var equallyLongStrings = g.integer({min:0, max: 10}).map(function (n) {
  return g.array(g.string({length: n}));
});

Would it be possible to eg. pass the Generators instance to the mapper function as the second parameter? I think that would make it easier to put generator mappers into libraries.

Consider introducing an `any` generator.

Something like:

var number = g.pick([
    g.integer({min: -100, max: 100}), g.integer,
    g.floating({min: -100, max: 100}), g.floating
])
var stringNumber = number.map(function (v) { return String(v) })
var anyPrimitive = g.pick([number, g.string, g.pick([
    -0, +0, 0, undefined, null, false, true,
    NaN, Infinity, -Infinity, '', [], stringNumber,
    Number.MAX_SAFE_INTEGER,
    Number.MIN_SAFE_INTEGER,
    Number.MAX_VALUE,
    Number.MIN_VALUE
])])
var any = g.weighted([anyPrimitive, g.array(anyPrimitive)], [10, 1])

It should also be capable of generating random objects and nested arrays.

Add shrinking to the producer

Investigate if it is possible to shrink the producers by starting with an infinite cycle count. When the producer hits the max cycle count, it starts over.

When you need to shrink you take the current cycle and return a new producer with that as the max cycle count. That way we would shrink towards the beginning of the producer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.