Code Monkey home page Code Monkey logo

rushcheck's Introduction

RushCheck library - a random test library for ruby

RushCheck library is a random testing library/tools for ruby which are imported from QuickCheck library in Haskell.

QuickCheck has been developed by Koen Claessen and John Hughes in 2000.

http://www.cs.chalmers.se/~rjmh/QuickCheck/
http://hackage.haskell.org/package/QuickCheck

Check out directories both data/rushcheck/doc and rdoc for details.

Current status is alpha

Less documents/examples, no gem. There is a gem version 0.8, but, it is not recommended to install because we will change the API.

An example

Let’s see data/examples/sample.rb The first example is here:

require 'rushcheck'

# assert_sort_one should be true
def assert_sort_one
  RushCheck::Assertion.new(Integer) { |x|
    [x].sort == [x]
  }.check
end

We will check that for all integer x, the array [x] does not changed after it is sorted. Here is a session with irb: (not installed, but downloaded the source code from the repository)

% irb -I lib -I data/examples -r sample
irb(main):001:0> assert_sort_one
OK, passed 100 tests.
==> true
irb(main):002:0>

The above test passed as expected. Another example when we will meet a bug in the code. The property that sorting does not change arrays is explicitly false.

# however, assert_sort_two is not true generally,
# and RushCheck finds a counter example.
def assert_sort_two
  RushCheck::Assertion.new(Integer, Integer) { |x, y|
    ary = [x, y]
    ary.sort == ary
  }.check
end

Continue the irb session:

irb(main):002:0> assert_sort_two
Falsifiable, after 2 tests:
[2, 0]
=> false
irb(main):003:0>

When x <= y in the test, the sorted array [x, y].sort equals the original array [x, y]. However, if x > y then the sorted array differs the original. We see the counter example [2, 0] thanks to random testing.

What we have studied from the above two examples: The method RushCheck::Assertion.new takes classes as variables, and has a block with the binded variables respectively; The block should return true or false; Finally the method check executes the random testing and shows the result.

More further

Specification of the program should be provided as properties. In each property, we write what has to be satisfied. RushCheck helps to test the properties with 100 (as the default) tests by random generated test cases. We can change the number of tests easily as follows;

# 1000 tests instead
c = RushCheck::Config.new(1000)
RushCheck::Assertion(Integer) { |x|
... # the property of the test
}.check(c)

The block of the property should be return either true or false. Therefore the assertion method in Test/Unit should not be written in the block because this returns nil object.

# NG case
RushCheck::Assertion(Integer) { |x|
  assertion_equal x*x, x**2 # NG because this returns nil
}.check

On the other hand, the check method in RushCheck returns either true or false if the test does not throw any exception. Then we can combine RushCheck and Test/Unit like this;

# OK
assertion_equal true,
  RushCheck::Assertion(Integer) { |x|
    x*x == x**2
  }.check

Contributing to rushcheck

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2006-2011 Daisuke IKEGAMI. See LICENSE.txt (The MIT license) for further details.

Project webpage rushcheck.rubyforge.org

Git repository github.com/IKEGAMIDaisuke/rushcheck

rushcheck's People

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.