Skip to content

Commit

Permalink
Add an example in README.rdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Daisuke IKEGAMI committed Mar 30, 2011
1 parent c3668a5 commit 5140cb5
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion README.rdoc
Expand Up @@ -9,6 +9,11 @@ QuickCheck has been developed by Koen Claessen and John Hughes in 2000.

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.

== 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
Expand All @@ -19,6 +24,54 @@ Check out directories both data/rushcheck/doc and rdoc for details.
* 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.

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

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.

== Copyright

Copyright (c) 2006-2011 Daisuke IKEGAMI. See LICENSE.txt for
Expand All @@ -29,4 +82,3 @@ http://rushcheck.rubyforge.org/

Git repository
http://github.com/IKEGAMIDaisuke/rushcheck

0 comments on commit 5140cb5

Please sign in to comment.