Project

queencheck

0.01
No commit activity in last 3 years
No release in over 3 years
QueenCheck is random test library. Inspired by QuickCheck library in Haskell.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0.0.6
>= 1.0.3
>= 0.6.0
>= 0.5.1
>= 1.0.2
>= 1.8.3
>= 0
>= 0.9.2.2
>= 0.9.0
>= 2.8.0
>= 0.9.0.rc9
>= 0.7.4
>= 0.3.0

Runtime

>= 0.5.8
 Project Readme

QueenCheck Build Status Gem Status

QueenCheck is random test library.

Inspired by QuickCheck library in Haskell.

Usage

$ gem install queencheck

or

$ git clone git://github.com/rosylilly/QueenCheck.git QueenCheck
$ cd QueenCheck
$ bundle install
$ bundle exec rake install

CI Report

See Travis-CI

Abstract

let's start DDT(Data Driven Testing)

require 'queencheck'

def plus(x, y)
  x + y
end

prop_Plus = QueenCheck::Testable.new(Integer, Integer) do | x, y |
  plus(x, y) == x + y
end
puts prop_Plus.check.pretty_report
# Tests: 100
#   ✓ Successes  : 100
#   ✗ Failures   :   0
#   ✷ Exceptions :   0

with exception, labeling and where

def div(x, y)
  x / y # => raise ZeroDividedError if y == 0
end

prop_Div = QueenCheck::Testable.new(Integer, Integer) do | x, y |
  div(x, y) == x / y
end
puts prop_Div.check.pretty_report
# Tests: 100
#   ✓ Successes  :  99
#   ✗ Failures   :   1
#   ✷ Exceptions :   1

puts prop_Div.check_with_label(
  "x > y" => proc{|x,y| x > y },
  "x < y" => proc{|x,y| x < y },
  "x = y" => proc{|x,y| x == y },
  "x is 0" => proc{|x,y| x.zero? },
  "y is 0" => proc{|x,y| y.zero? }
).pretty_report
# Tests: 100
#  ✓ Successes  :  99
#    x > y  :  43
#    x < y  :  56
#    x = y  :   0
#    x is 0 :   0
#    y is 0 :   0
#  ✗ Failures   :   1
#    x > y  :   0
#    x < y  :   0
#    x = y  :   1
#    x is 0 :   1
#    y is 0 :   1
#  ✷ Exceptions :   1
#    x > y  :   0
#    x < y  :   0
#    x = y  :   1
#    x is 0 :   1
#    y is 0 :   1

int_generater = Integer.arbitrary.gen # => QueenCheck::Gen
nonzero_integer = int_generater.where{|num| !num.zero? }
prop_DivSuccess = QueenCheck::Testable.new(nonzero_integer, nonzero_integer) do | x, y |
  div(x, y) == x / y
end
puts prop_DivSuccess.check_with_label(
  "x > y" => proc{|x,y| x > y },
  "x < y" => proc{|x,y| x < y },
  "x = y" => proc{|x,y| x == y },
  "x is 0" => proc{|x,y| x.zero? },
  "y is 0" => proc{|x,y| y.zero? }
).pretty_report
# Tests: 99
#   ✓ Successes  : 99
#     x > y  : 55
#     x < y  : 44
#     x = y  :  0
#     x is 0 :  0
#     y is 0 :  0
#   ✗ Failures   :  0
#     x > y  :  0
#     x < y  :  0
#     x = y  :  0
#     x is 0 :  0
#     y is 0 :  0
#   ✷ Exceptions :  0
#     x > y  :  0
#     x < y  :  0
#     x = y  :  0
#     x is 0 :  0
#     y is 0 :  0

Help me

please fork QueenCheck repository.

I'm waiting for the code review of you !