Learn R Programming

quickcheck

Overview

Property based testing in R, inspired by QuickCheck. This package builds on the property based testing framework provided by hedgehog and is designed to seamlessly integrate with testthat.

Installation

You can install the released version of quickcheck from CRAN with:

install.packages("quickcheck")

And the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("armcn/quickcheck")

Usage

The following example uses quickcheck to test the properties of the base R + function. Here is an introduction to the concept of property based testing, and an explanation of the mathematical properties of addition can be found here.

library(testthat)
library(quickcheck)

test_that("0 is the additive identity of +", {
  for_all(
    a = numeric_(len = 1),
    property = function(a) expect_equal(a, a + 0)
  )
})
#> Test passed 

Copy Link

Version

Install

install.packages('quickcheck')

Monthly Downloads

447

Version

0.1.3

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Andrew McNeil

Last Published

October 12th, 2023

Functions in quickcheck (0.1.3)

show_example

Show an example output of a generator
data_frame_of

Data frame generator with randomized columns
tibble_

Tibble generators
one_of

Randomly choose between generators
%>%

Pipe operator
posixct_

POSIXct generators
repeat_test

Repeatedly test properties of a function
character_

Character generators
numeric_

Numeric generators
as_hedgehog

Convert a quickcheck generator to a hedgehog generator
logical_

Logical generator
date_

Date generators
tibble_of

Random tibble generator
list_

List generator
flat_list_of

Variable length flat list generator
list_of

Variable length list generator
equal_length

Equal length vector generator
double_

Double generators
factor_

Factor generator
any_undefined

Any undefined value generator
any_tibble

Any tibble generator
any_vector

Any vector generator
any_data_frame

Any data frame generator
anything

Any R object generator
constant

Generate the same value every time
for_all

Test properties of a function
any_flat_homogeneous_list

Any flat homogeneous list generator
any_atomic

Any atomic vector generator
any_flat_list

Any flat list generator
any_data.table

Any data.table generator
data.table_

data.table generators
from_hedgehog

Convert a hedgehog generator to a quickcheck generator
any_list

Any list generator
data.table_of

data.table generator with randomized columns
data_frame_

Data frame generators
hms_

hms generators
integer_

Integer generators