Learn R Programming

unittest (version 1.0-0)

ok: The unittest package's workhorse function

Description

Report the test of an expression in TAP format.

Usage

ok( test, description )

Arguments

test
Expression to be tested. Evaluating to TRUE is treated as success, anything else as failure.
description
Character string describing the test. If a description is not given a character representation of the test expression will be used.

Value

  • ok() returns whatever was returned when test is evaluated. More importantly it has the side effect of printing the result of the test in TAP format.

Details

See unittest package documentation.

Examples

Run this code
ok( 1==1, "1 equals 1")
  # ok - 1 equals 1

  ok( 1==1 )
  # ok - 1 == 1

  ok( 1==2, "1 equals 2")
  # not ok - 1 equals 2
  # # Test returned non-TRUE value:
  # # [1] FALSE

  ok( all.equal(c(1,2),c(1,2)), "compare vectors" )
  # ok - compare vectors

  ok( stop("oops"), "something with a coding error")
  # not ok - something with a coding error
  # # Test resulted in error: oops
  # #  -> doTryCatch
  # #  -> return(expr)
  # #  -> name
  # #  -> parentenv
  # #  -> handler

  ok( c("Some diagnostic", "messages"), "A failure with diagnostic messages" )
  # not ok - A failure with diagnostic messages
  # # Test returned non-TRUE value:
  # # Some diagnostic
  # # messages

Run the code above in your browser using DataLab