testFun: Call a function and compare the result

testFunCallR Documentation

Call a function and compare the result

Description

This function and its methods uses the inputs from an observed call to a function to compare the behaviour of a new version of that function to determine if it produces the same result. This uses the arguments and any global variables to recreate the call and compares the new result to the one obtained in the original call.

Usage

testFunCall(x, fun, compare = identical, ...)

Arguments

x

the FunctionCallResults or CallResultInfo objects from collectCallResults.

fun

the definition of the function with which to compare the calls and results in x to the results from this function.

compare

a function used to compare the results from the original call to the result from each of these calls.

...

additional arguments passed to the compare function.

Value

Since this is a generic function, the resulting value will be different according to the inputs. For FunctionCallResults, this returns a list of values. For CallResultInfo, this returns the value from the compare function.

Author(s)

Duncan Temple Lang

See Also

collectCallResults

Examples

global1 = 10
global2 = 3.1415
f3 = function(x, y)
        x + y + global1 + global2
e3 = collectCallResults("f3")

f3(10, 11)
f3(999, 777)
k = e3()

testFunCall(k, f3)

rm(global1, global2)
testFunCall(k, f3)

testFunCall(k, function(x, y) x + y + global1 + global2)

duncantl/CallCounter documentation built on Nov. 23, 2023, 3:38 p.m.