<commit_before>= 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 <NAME> and <NAME> 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.

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

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

== Copyright

Copyright (c) 2006-2011 <NAME>. See LICENSE.txt for
further details.

Project webpage
http://rushcheck.rubyforge.org

Git repository
http://github.com/IKEGAMIDaisuke/rushcheck<commit_msg>write other examples in README.rdoc<commit_after>= 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 <NAME> and <NAME> 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

Copyright (c) 2006-2011 <NAME>. See LICENSE.txt (The MIT license) for
further details.

Project webpage
http://rushcheck.rubyforge.org

Git repository
http://github.com/IKEGAMIDaisuke/rushcheck
{'fraction_non_alphanumeric': 0.0693274409611932, 'fraction_numerical': 0.012291120011048198, 'mean_word_length': 3.5893536121673004, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5721880', 'n_tokens_mistral': 2194, 'n_tokens_neox': 2031, 'n_words': 1005}