找回密码
 注册
查看: 342|回复: 0

R语言 RUnit包 checkFuncs()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-9-28 23:41:28 | 显示全部楼层 |阅读模式
checkFuncs(RUnit)
checkFuncs()所属R语言包:RUnit

                                        RUnit check functions
                                         鲁尼特检查功能

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

A set of functions used to check the results of some test calculation. If these functions are called within the RUnit framework, the results of the checks are stored and reported in the test protocol.
一组功能用于检查一些测试的计算结果。如果这些功能被称为内鲁尼特框架,检查的结果被存储,并报告在测试协议。

checkEquals compares two R objects by invoking all.equal on the two objects. If the objects are not equal an error is generated and the failure is reported to the test logger such that it appears in the test protocol.
checkEquals比较两个的R对象由调用all.equal了两个对象。如果对象是不相等的,则会生成错误报告故障的测试记录器,使得它会出现在测试协议。

checkEqualsNumeric works just like checkEquals except that it invokes all.equal.numeric instead of all.equal
checkEqualsNumeric就像checkEquals惟,它调用all.equal.numeric,而不是all.equal的时间

checkIdentical is a convenience wrapper around identical using the error logging mechanism of RUnit.
checkIdentical是一个方便的包装相同的错误log记录机制鲁尼特。

checkTrue uses the function identical to check if the expression provided as first argument evaluates to TRUE. If not, an error is generated and the failure is reported to the test logger such that it appears in the test protocol.
checkTrue使用的功能identical来检查,如果表达式作为第一个参数的计算结果为TRUE的。如果没有,则会生成错误报告故障的测试记录器,使得它会出现在测试协议。

checkException evaluates the passed expression and uses the try mechanism to check if the evaluation generates an error. If it does the test is OK. Otherwise an error is generated and the failure is reported to the test logger such that it appears in the test protocol.
checkException评估通过表达和使用try机制,检查评估,如果产生一个错误。如果是这样的测试是OK的。否则就会产生错误和故障报告的测试记录器,它似乎在测试协议。

DEACTIVATED interrupts the test function and reports the test case as deactivated. In the test protocol deactivated test functions are listed separately. Test case deactivation can be useful in the case of major refactoring. Alternatively, test cases can be commented out completely but then it is easy to forget the test case altogether.
DEACTIVATED中断测试功能,并报告测试的情况下为停用。停用在测试协议测试功能单独列出。测试的情况下失活的情况下,重大的重构可能是有用的。另外,测试用例可以注释掉完全,但它完全测试的情况下,很容易忘记。


用法----------Usage----------


checkEquals(target, current, msg,
            tolerance = .Machine$double.eps^0.5,
            checkNames = TRUE, ...)
checkEqualsNumeric(target, current, msg,
                   tolerance = .Machine$double.eps^0.5, ...)
checkIdentical(target, current, msg)
checkTrue(expr, msg)
checkException(expr, msg, silent = getOption("RUnit")$silent)
DEACTIVATED(msg)



参数----------Arguments----------

参数:current, target
objects to be compared (checkEqualsNumeric cannot  handle S4 class objects).
要比较的对象(checkEqualsNumeric不能处理S4类对象)。


参数:msg
an optional message to document a check and to facilitate the identification of a possible failure. The message only appears as text in the test protocol, it is not further used in any of the check  functions.
一个可选的消息记录检查,并便于识别可能发生故障。该消息仅出现作为文本中的测试协议,它是未进一步在任何检查功能使用。


参数:tolerance
numeric >= 0.  A numeric check does not fail if differences are smaller than "tolerance".
数值> = 0。一个数字的支票不能失败如果差异小于“宽容”。


参数:checkNames
flag, if FALSE the names attributes are set to  NULL for both current and target before performing the check.
标志,如果FALSE的名称属性设置为NULL当前和目标,然后才进行检查。


参数:expr
syntactically valid R expression which can be evaluated and must return a logical scalar (TRUE|FALSE). A named  expression is also allowed but the name is disregarded.
语法上有效的R的表达进行评估,并必须返回一个逻辑标量(TRUE|FALSE)。也被允许的,但被忽略的名字命名的表达。


参数:silent
flag passed on to try, which determines if the error message generated by the checked function is displayed. Queried from  global options set for RUnit at package load.
标志传递到的try,确定通过检查函数生成的错误消息显示。从全局选项设置为鲁尼特包加载质疑。


参数:...
optional arguments passed to all.equal or  all.equal.numeric
可选参数传递给all.equal或all.equal.numeric


Details

详细信息----------Details----------

The check functions are direct equivalents of the various methods of the class junit.framework.Assert of Javas JUnit framework which served as basis for the RUnit package.
检查功能是直接对等的各种方法之类的junit.framework.Assert的Javas JUnit框架为基础的鲁尼特包。

For functions defined inside a package equipped with a namespace only exported functions can be accessed inside test cases directly. For functions not exported the only way to test them is to use the  ':::' operator combined with the package name as a prefix.
对于只导出函数的命名空间可以直接访问内部测试情况下,配备了一个包内定义的功能。功能不出口是唯一的方法来测试他们用:::运营商加上包名作为前缀。

Special care is required if test cases are written for S4 classes and methods. If a new class is defined inside a test case via a setClass call the class is added to the global class cache and thus available outside the test case. It will persist until explicitly removed via a removeClass call. Same applies for new method and generic definitions. Be sure to remove methods and classes in each test case they are defined after the checks have been performed. This is an advise gained from the cumbersome experience: not doing so leads to difficult to pin down error causes incurred from previously executed test cases. For a simple example see the provided test cases in /usr/lib/R/library/RUnit/examples/runitVirtualClassTest.r.
如果S4的类和方法编写的测试案例,要特别小心。如果一个新的类的内部定义一个测试案例,通过setClass调用的类被添加到全局类缓存中,从而将外部的测试案例。这将继续下去,直到显式删除通过removeClass呼叫。同样适用于新的方法和通用的定义。在已经进行的检查后,它们被定义在每个测试案例,一定要去除的方法和类。这是建议从繁琐的经验中获得:不这样做会导致难以牵制从以前执行的测试用例产生错误的原因。举一个简单的例子,请参阅提供的测试情况下,在/ usr / lib目录中/ R /图书馆/鲁尼特/例子/ runitVirtualClassTest.r的。


(作者)----------Author(s)----------



Thomas K枚nig, Klaus J眉nemann
& Matthias Burger



参见----------See Also----------

all.equal, all.equal.numeric and identical are the underlying comparison functions. try is used for error catching. .setUp for details on test case setup. See RUnit-options for global options controlling log out.
all.equal,all.equal.numeric和identical是底层的比较函数。 try用于错误捕捉。 .setUp测试案例设置的详细信息。请参阅鲁尼特选项全局选项控制的退出。


实例----------Examples----------



checkTrue(1 < 2, "check1")     ## passes fine[#经过精]
## checkTrue(1 > 2, "check2")  ## appears as failure in the test protocol[###checkTrue(1> 2,的“CHECK2”)显示为失败的测试协议]

v <- 1:3
w <- 1:3
checkEquals(v, w)               ## passes fine[#经过精]
names(v) <- c("A", "B", "C")
## checkEquals(v, w)            ## fails because v and w have different names[##:#checkEquals(v和w)失败,因为v和w具有不同的名称]
checkEqualsNumeric(v, w)        ## passes fine because names are ignored[#通过精细的,因为名字会被忽略]


x <- rep(1:12, 2)
y <- rep(0:1, 12)
res <- list(a=1:3, b=letters, LM=lm(y ~ x))
res2 <- list(a=seq(1,3,by=1), b=letters, LM=lm(y ~ x))
checkEquals( res, res2)        ## passes fine[#经过精]
checkIdentical( res, res)
checkIdentical( res2, res2)
## checkIdentical( res, res2)  ## fails because element 'a' differs in type[###checkIdentical(水库,RES2)失败,因为不同的类型元素A]


fun <- function(x) {
  if(x)
  {
   stop("stop conditions signaled")
  }
  return()
}

checkException(fun(TRUE))      ## passes fine[#经过精]
## checkException(fun(FALSE))  ## failure, because fun raises no error[#checkException(乐趣(FALSE))##失败,因为大家的快乐引发任何错误]
checkException(fun(TRUE), silent=TRUE)

##  special constants[#特殊常量]
##  same behaviour as for underlying base functions[#相同的行为为基础的基本功能]
checkEquals(NA, NA)
checkEquals(NaN, NaN)
checkEquals(Inf, Inf)

checkIdentical(NA, NA)
checkIdentical(NaN, NaN)
checkIdentical(-Inf, -Inf)

## DEACTIVATED("here one can document on the reason for deactivation")[涓#DEACTIVATED(“在这里,人们可以记录失活的原因”)]

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2024-11-28 06:45 , Processed in 0.024881 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表