1
  7   ÷ˆl–Ü4ý(Ð?J€ÆÝ¸ÔÅ£�þ[jGVlmÇ[)K@þø„]ÿ÷Âô ?÷     ÷##  RUnit : A unit test framework for the R programming language
##  Copyright (C) 2003-2009  Thomas Koenig, Matthias Burger, Klaus Juenemann
##
##  This program is free software; you can redistribute it and/or modify
##  it under the terms of the GNU General Public License as published by
##  the Free Software Foundation; version 2 of the License.
##
##  This program is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##  GNU General Public License for more details.
##
##  You should have received a copy of the GNU General Public License
##  along with this program; if not, write to the Free Software
##  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
##
##  $Id$


cat("\n\nRUnit test cases for 'RUnit:check' functions\n\n")


testRUnit.checkEquals <- function()
{
  ##@bdescr
  ## test case for function checkEquals of class: none
  ##@edescr

  ##  integer
  x <- 1:10
  checkEquals(x, x)
  ##  return value
  checkTrue( checkEquals(x, x))
  namedInt <- 1:10
  names(namedInt) <- letters[namedInt]
  checkEquals(namedInt, namedInt)
  checkEquals(namedInt, x, checkNames=FALSE)
  
  ##  numeric
   checkEquals(pi, pi)
  y <- 1/0
  checkEquals(Inf, y)
  checkEquals(y, Inf)
  y <- log(-1)
  checkEquals(NaN, y)
  checkEquals(rep(NaN, 23), rep(y, 23))
  checkEquals(9, 9.0)
  checkEquals(NA, NA)
  checkEquals(rep(NA, 14), rep(NA, 14))
  checkEquals( numeric(1), numeric(1))
  checkEquals( 0.01, 0.02, tolerance=0.01)
  tmp <- c(0.01, NA, 0.02, Inf, -Inf, NaN, 1.0)
  checkEquals( tmp, tmp, tolerance=0.01)
  
  ##  complex
  checkEquals(complex(0), complex(0))
  checkEquals(complex(2), complex(2))
  checkEquals(complex(2, imaginary=1), complex(2, imaginary=1))

  ##  character
  checkEquals( character(1), character(1))
  checkEquals( letters, letters)
  
  ##  matrix
  checkEquals( matrix(1, 3,5), matrix(1, 3,5))
  checkEquals( matrix(1, 50000,5), matrix(1, 50000,5),
              "large matrix not identified as equal")

  ##  language
  checkEquals( expression(2), expression(2))
  checkEquals( call("mean", "median"), call("mean", "median"))

  ##  formula
  simpleForm <- x ~ 1
  checkEquals( simpleForm, simpleForm,
              "simple formula not identified as equal")
  compForm <- y ~ x + y + x*y + offset(x)
  checkEquals( compForm, compForm,
              "formula not identified as equal")
  
  ##  factor
  alphaFac <- factor(letters)
  checkEquals( alphaFac, alphaFac,
              "factor not identified as equal")
  
  ##  list
  checkEquals( list(100), list(100))
  checkEquals( list(100), list(100), tolerance=1)
  alphaList <- seq_along(letters)
  names(alphaList) <- letters
  checkEquals( alphaList, alphaList)
  checkEquals( alphaList, alphaList, checkNames=FALSE)

  ##  nested list with NA, NaN, Inf
  nl <- list(a=list(1), b=list(1:4),
             c=list(ab=1, bc=list(list(2), list(NA), list(NaN)) ),
             d=list(m1=matrix(NA, 2,3), m2=matrix(1+1i, 4,5)),
             e=list(e1=NaN, e2=list(Inf), e3=list(a=Inf, b=-Inf, c=NaN, d=-0/0)))
  checkEquals(nl, nl)
  
  ##  example from ?glm
  counts <- c(18,17,15,20,10,20,25,13,12)
  outcome <- gl(3,1,9)
  treatment <- gl(3,3)
  lmFit <- glm(counts ~ outcome + treatment, family=poisson())
  checkEquals( lmFit, lmFit, checkNames=FALSE)
  checkEquals( lmFit, lmFit)
  lmFitUnnamed <- lmFit
  names(lmFitUnnamed) <- NULL
  checkEquals( lmFit, lmFitUnnamed, checkNames=FALSE)
  
  ##  POSIXct
  sysTime <- as.POSIXct(Sys.time())
  checkEquals( sysTime, sysTime)

  ##  raw
  checkEquals( raw(14), raw(14))
  namedRaw <-  as.raw(1:14)
  names(namedRaw) <- letters[1:14]
  checkEquals( namedRaw, namedRaw)

  ##  formula
  a <- 1:10
  f <- gl(2,5)
  checkEquals( a~f, a~f)
  
  ##  S4 objects
  if (identical(TRUE, require(methods))) {
    setClass("track1",
             representation(x="numeric", y="numeric"),
             where=.GlobalEnv)
    on.exit(removeCl