Giter VIP home page Giter VIP logo

randall's Introduction

Randall

*Randomly generates instances of any class*

Dependencies

Beautiful treetop is needed for parsing regular expressions, so we can generate random character strings matching a regexp.

Slim bacon is used for executing specs. You need not install bacon to use Randall.

Install

gem install randall

Randall uses Fiber, so can be used on Ruby 1.9 or JRuby only.

Tested on:

  • ruby 1.9.1 p378

  • jruby 1.5.0 with option –1.9

Examples

Canonical approach

Numbers

String

Array and Hash

Objects

Syntax sugars

Some methods are provided to specify the type and restrictions.

r = Randall
r.integers.less_than(100)  # Same as r.generate(Integer, :less_than => 100)
r.floats.gt(100) # => r.generate(Float, :greater_than => 100)
r.floats.clost_to(0)
r.integers.in_range(1..2)

For generating strings.

number = Randall.strings.that.match(/[0-9]+/)

Above example has the same effect as number = Randall.new(String, :like => /[0-9]+/).

Generate Arrays whose elements are generated by number.

Randall.arrays.of(number).size(100)

Generate Hashes whose keys are

Randall.hashes.from(number).to(String).size(10)

Some monkey patching

  • +Array#pick+ randomly pick an element from the receiver.

  • +Regexp#rand+ generates a String that matches the receiver.

Monkey patching is disabled by default. You must patch explicitly, by calling RandallMonkey.patch.

Limitations on Generating Strings for Regular Expressions

  • Anchors, except +^+ and +$+, are ignored.

  • +p{*}+ and +P{*}+ are not supported.

  • Unicode characters are not supported.

  • +(?*)+ extension is not supported.

  • Back-reference is not supported.

License

The MIT license.

Copyright (2010), Diego Che ([email protected])

  • randexp generates random data from a

Regular Expression. The +Array#pick+ is from here.

report bugs to the github issue tracker.

randall's People

Contributors

dche avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

kwmalik

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.