Title: | Wizardry Code Offensive Programming |
---|---|
Description: | Allows to turn standard R code into offensive programming code. Provides code instrumentation to ease this change and tools to assist and accelerate code production and tuning while using offensive programming code technics. Should improve code robustness and quality. Function calls can be easily verified on-demand or in batch mode to assess parameter types and length conformities. Should improve coders productivity as offensive programming reduces the code size due to reduced number of controls all along the call chain. Should speed up processing as many checks will be reduced to one single check. |
Authors: | Fabien Gelineau <[email protected]> |
Maintainer: | Fabien Gelineau <[email protected]> |
License: | GPL-3 |
Version: | 1.1.24 |
Built: | 2024-11-01 11:52:35 UTC |
Source: | CRAN |
Get all predefined evaluation mode names
defineEvaluationModes()
defineEvaluationModes()
A vector
of strings, each representing a reusable evaluation mode name.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to EvaluationMode
.
##---- typical case ---- defineEvaluationModes()
##---- typical case ---- defineEvaluationModes()
Provides the parameter name to use to define function return type.
defineFunctionReturnTypesParameterName()
defineFunctionReturnTypesParameterName()
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to EvaluationMode
.
##---- typical case ---- defineFunctionReturnTypesParameterName()
##---- typical case ---- defineFunctionReturnTypesParameterName()
Define the paramater name to hold test case definitions
defineTestCaseDefinitionsParameterName()
defineTestCaseDefinitionsParameterName()
A single string
that is the parameter name to use.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to EvaluationMode
. See sibling
EvaluationMode
.
##---- typical case ---- defineTestCaseDefinitionsParameterName()
##---- typical case ---- defineTestCaseDefinitionsParameterName()
Class to define your evaluation mode
EvaluationMode(value_s_1 = defineEvaluationModes()[2])
EvaluationMode(value_s_1 = defineEvaluationModes()[2])
value_s_1 |
one |
An object
that is an R environment
.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to defineEvaluationModes
##---- typical case ---- EvaluationMode(defineEvaluationModes()[3])
##---- typical case ---- EvaluationMode(defineEvaluationModes()[3])
Human readable output synthetized from
verifyObjectNames
exploreObjectNamesVerification(object_o_1, what_s_1 = c("names", "return type", "test cases", "*")[1])
exploreObjectNamesVerification(object_o_1, what_s_1 = c("names", "return type", "test cases", "*")[1])
object_o_1 |
the |
what_s_1 |
a single |
The same value as verifyObjectNames
is returned
in invisible
mode.
It adds stdout
output to give very short synthesis about object names and content.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to verifyClassName
and
verifyFunctionName
.
##---- typical case ---- library('data.table') source(system.file('code-samples/frt-defs/good/full/AdditionFI.R', package = 'wyz.code.offensiveProgramming')) fi <- AdditionFI() exploreObjectNamesVerification(fi)
##---- typical case ---- library('data.table') source(system.file('code-samples/frt-defs/good/full/AdditionFI.R', package = 'wyz.code.offensiveProgramming')) fi <- AdditionFI() exploreObjectNamesVerification(fi)
Use function findFilesInPackage
to find files in package.
findFilesInPackage(filenames_s, packageName_s_1)
findFilesInPackage(filenames_s, packageName_s_1)
filenames_s |
An unconstrained vector of |
packageName_s_1 |
A length-1 vector of |
This function is vectorized. It returns a list
with one entry for each file searched for.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
# ------- example 1 ------- findFilesInPackage(c("AdditionTCFIG1.R", "Addition_TCFI_Partial_R6.R", "Addition_TCFI_Partial_S3.R"), "wyz.code.offensiveProgramming") # .../wyz.code.offensiveProgramming/code-samples/both-defs/good/full/AdditionTCFIG1.R # .../wyz.code.offensiveProgramming/code-samples/both-defs/good/partial/Addition_TCFI_Partial_R6.R # .../wyz.code.offensiveProgramming/code-samples/both-defs/good/partial/Addition_TCFI_Partial_S3.R # ------- example 2 ------- findFilesInPackage("datatable-intro.html", "data.table") # .../data.table/doc/datatable-intro.html
# ------- example 1 ------- findFilesInPackage(c("AdditionTCFIG1.R", "Addition_TCFI_Partial_R6.R", "Addition_TCFI_Partial_S3.R"), "wyz.code.offensiveProgramming") # .../wyz.code.offensiveProgramming/code-samples/both-defs/good/full/AdditionTCFIG1.R # .../wyz.code.offensiveProgramming/code-samples/both-defs/good/partial/Addition_TCFI_Partial_R6.R # .../wyz.code.offensiveProgramming/code-samples/both-defs/good/partial/Addition_TCFI_Partial_S3.R # ------- example 2 ------- findFilesInPackage("datatable-intro.html", "data.table") # .../data.table/doc/datatable-intro.html
Class to define and handle a function parameter
FunctionParameterName(name_s_1)
FunctionParameterName(name_s_1)
name_s_1 |
a |
The name of the parameter should be a semantic name. A semantic name is a compound string based on a special format allowing to distinguish by the name, the parameter type, and to express some length constraints.
An object
that is an R environment
. Use functions
isSemanticName
,
isPolymorphic
, isEllipsis
,
isValid
to check the provided name.
Functions get*
allows to retrieve parts of the name.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to defineEvaluationModes
.
##---- typical case ---- fpn <- FunctionParameterName('values_s_7m') fpn$isPolymorphic() fpn$isSemanticName() fpn$isValid() fpn$getTypeSuffix() # 's' fpn$getLengthSpecification() # '7m' fpn$getLengthSuffix() # 7 fpn$getLengthModifier() # 'm' fpn <- FunctionParameterName('object_') fpn$isPolymorphic() fpn$isSemanticName() fpn$isValid()
##---- typical case ---- fpn <- FunctionParameterName('values_s_7m') fpn$isPolymorphic() fpn$isSemanticName() fpn$isValid() fpn$getTypeSuffix() # 's' fpn$getLengthSpecification() # '7m' fpn$getLengthSuffix() # 7 fpn$getLengthModifier() # 'm' fpn <- FunctionParameterName('object_') fpn$isPolymorphic() fpn$isSemanticName() fpn$isValid()
This factory is a parameter type check factory. It provides type checking for each allowed type.
FunctionParameterTypeFactory()
FunctionParameterTypeFactory()
Many common types are already recorded and available through the factory. Use the function
getRecordedTypes
to get more insight.
If you desire to verify a type instrumentation, just use checkSuffix
function.
If you want to add an instrumentation for a new type, use addSuffix
function.
See examples below for more hands-on approach.
An object
that is an R environment
.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to defineEvaluationModes
##---- typical case ---- ff <- FunctionParameterTypeFactory() ff$checkSuffix('b') # TRUE # see verify_function recorded for 'boolean' entries ff$getRecordedTypes()[suffix == 'b']$verify_function[[1]] # record a new entry for suffix 'wo' ff$addSuffix('wo', "wo class", function(o_) is(o, "wo")) # TRUE ff$getRecordedTypes()[suffix == 'wo']
##---- typical case ---- ff <- FunctionParameterTypeFactory() ff$checkSuffix('b') # TRUE # see verify_function recorded for 'boolean' entries ff$getRecordedTypes()[suffix == 'b']$verify_function[[1]] # record a new entry for suffix 'wo' ff$addSuffix('wo', "wo class", function(o_) is(o, "wo")) # TRUE ff$getRecordedTypes()[suffix == 'wo']
Get ellipsis argument name value.
getEllipsisName()
getEllipsisName()
A string
with value "..."
, no more no less.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
# typical test getEllipsisName() #[1] "..."
# typical test getEllipsisName() #[1] "..."
Get the class kind of an R object as a string.
getObjectClassKind(object_o_1)
getObjectClassKind(object_o_1)
object_o_1 |
the |
A single character
value, taken in set "S3"
,
"S4"
,
"RC"
, "R6"
, "environment"
,
"unknown"
.
When provided object_
is not an R object, then value
NA_character_
is returned.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
##---- typical case ---- getObjectClassKind(new.env()) # [1] NA myrc <- setRefClass("RC", fields = list(x = "numeric"), methods = list( initialize = function(x = 1) .self$x <- x, getx = function() x, inc = function(n = 1) x <<- x + n ) ) getObjectClassKind(myrc$new()) # [1] RC myr6 <- R6::R6Class("R6", public = list( x = NULL, initialize = function(x = 1) self$x <- x, getx = function() self$x, inc = function(n = 1) self$x <- x + n ) ) getObjectClassKind(myr6$new()) # [1] R6
##---- typical case ---- getObjectClassKind(new.env()) # [1] NA myrc <- setRefClass("RC", fields = list(x = "numeric"), methods = list( initialize = function(x = 1) .self$x <- x, getx = function() x, inc = function(n = 1) x <<- x + n ) ) getObjectClassKind(myrc$new()) # [1] RC myr6 <- R6::R6Class("R6", public = list( x = NULL, initialize = function(x = 1) self$x <- x, getx = function() self$x, inc = function(n = 1) self$x <- x + n ) ) getObjectClassKind(myr6$new()) # [1] R6
Retrieve the class names of an object (
see is.object
).
)
getObjectClassNames(object_o_1) hasMainClass(object_o_1, classname_s_1)
getObjectClassNames(object_o_1) hasMainClass(object_o_1, classname_s_1)
object_o_1 |
the |
classname_s_1 |
a |
A list
with two character entries. First one is named
classname
,
provides the main classname (the one found in first position). Second one is named
classnames
, provides all the class names born by the
object
.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
# typical test getObjectClassNames(getObjectClassNames(factor(letters[1:3]))) #$classname #[1] "factor" #$classnames #[1] "factor" # another test getObjectClassNames(new.env()) #$classname #[1] NA #$classnames #[1] "environment"
# typical test getObjectClassNames(getObjectClassNames(factor(letters[1:3]))) #$classname #[1] "factor" #$classnames #[1] "factor" # another test getObjectClassNames(new.env()) #$classname #[1] NA #$classnames #[1] "environment"
Retrieve function argument names from an object.
getObjectFunctionArgumentNames(object_o_1, allNames_b_1 = TRUE)
getObjectFunctionArgumentNames(object_o_1, allNames_b_1 = TRUE)
object_o_1 |
the object to analyze. |
allNames_b_1 |
A boolean value. Passed to function
|
A list
. Entries are named with function names. Each entry is of type character,
and holds function argument names. Could be empty if function takes no argument.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
See is.object
.
# typical test MyEnv <- function() { self <- environment() class(self) <- append('MyEnv', class(self)) f <- function(x_3, y_3n) x_3 + y_3n self } getObjectFunctionArgumentNames(MyEnv()) #$f #[1] "x_3" "y_3n"
# typical test MyEnv <- function() { self <- environment() class(self) <- append('MyEnv', class(self)) f <- function(x_3, y_3n) x_3 + y_3n self } getObjectFunctionArgumentNames(MyEnv()) #$f #[1] "x_3" "y_3n"
Retrieve function names of an object (
see is.object
).
)
getObjectFunctionNames(object_o_1, allNames_b_1 = FALSE) getClassTypicalFunctionNames(object_o_1)
getObjectFunctionNames(object_o_1, allNames_b_1 = FALSE) getClassTypicalFunctionNames(object_o_1)
object_o_1 |
the |
allNames_b_1 |
A |
Function getClassTypicalFunctionNames
gives back
function names that are related to
R class style, and automatically added by R to your class object.
A vector
of function names (character
).
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
# typical test MyEnv <- function() { self <- environment() class(self) <- append('MyEnv', class(self)) f <- function(x_3, y_3n) x_3 + y_3n self } getObjectFunctionNames(MyEnv()) # [1] "f" # another test getObjectFunctionNames(new.env()) #[1] NA
# typical test MyEnv <- function() { self <- environment() class(self) <- append('MyEnv', class(self)) f <- function(x_3, y_3n) x_3 + y_3n self } getObjectFunctionNames(MyEnv()) # [1] "f" # another test getObjectFunctionNames(new.env()) #[1] NA
Provide short information about offensive programming instrumentation level
identifyOPInstrumentationLevel(object_o_1 = NULL, methodName_s_1 = NA_character_)
identifyOPInstrumentationLevel(object_o_1 = NULL, methodName_s_1 = NA_character_)
object_o_1 |
the |
methodName_s_1 |
the |
A list
with following names
offensive_programming |
a single |
full_instrumentation |
a single |
semantic_naming |
a single |
function_return_type |
a single |
test_case_definition |
a single |
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to verifyClassName
and
verifyFunctionName
.
##---- typical case ---- library('data.table') source(system.file('code-samples/frt-defs/good/full/AdditionFI.R', package = 'wyz.code.offensiveProgramming')) identifyOPInstrumentationLevel(AdditionFI()) #$offensive_programming #[1] TRUE #$full_instrumentation #[1] FALSE #$semantic_naming #[1] TRUE #$function_return_type #[1] TRUE #$test_case_definition #[1] FALSE
##---- typical case ---- library('data.table') source(system.file('code-samples/frt-defs/good/full/AdditionFI.R', package = 'wyz.code.offensiveProgramming')) identifyOPInstrumentationLevel(AdditionFI()) #$offensive_programming #[1] TRUE #$full_instrumentation #[1] FALSE #$semantic_naming #[1] TRUE #$function_return_type #[1] TRUE #$test_case_definition #[1] FALSE
Retrieve option telling if code is auditable
isAuditable()
isAuditable()
A boolean
value. To turn value to TRUE
, set option
op_audit
to TRUE
.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
# typical case isAuditable() # FALSE
# typical case isAuditable() # FALSE
Compare two functions signatures and tells if they are exactly the same.
matchFunctionSignature(aFunction_f_1, aFunctionTemplate_f_1 = function(){})
matchFunctionSignature(aFunction_f_1, aFunctionTemplate_f_1 = function(){})
aFunction_f_1 |
a |
aFunctionTemplate_f_1 |
a |
To get TRUE
as result, function and function model must share exactly the
sames attributes names and values, including default values if any used.
A boolean
value.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
matchFunctionSignature(sum, function(..., na.rm = FALSE) { NULL }) # [1] TRUE matchFunctionSignature(sum, function(..., na.rm) { NULL }) #[1] FALSE
matchFunctionSignature(sum, function(..., na.rm = FALSE) { NULL }) # [1] TRUE matchFunctionSignature(sum, function(..., na.rm) { NULL }) #[1] FALSE
A reminder of available functions from this package, and, most common usage
intent. A poor man CLI
cheat sheet.
opInformation()
opInformation()
A data.table
with following columns
name |
the object name |
category |
the category of the object describe by function name. Could be
|
nature |
either |
stratum |
the stratum the object belongs to. Values are |
phasing |
main usage phase of the object. Values are |
intent |
main global intent of the object. Values are |
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer also to package vignettes.
##---- typical case ---- opInformation()
##---- typical case ---- opInformation()
EvaluationMode
Prints the EvaluationMode
data
## S3 method for class 'EvaluationMode' print(x, ...)
## S3 method for class 'EvaluationMode' print(x, ...)
x |
the |
... |
any other argument, passed to print. |
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
b <- EvaluationMode(defineEvaluationModes()[2]) print(b)
b <- EvaluationMode(defineEvaluationModes()[2]) print(b)
FunctionParameterName
Prints the FunctionParameterName
data
## S3 method for class 'FunctionParameterName' print(x, ...)
## S3 method for class 'FunctionParameterName' print(x, ...)
x |
the |
... |
any other argument, passed to print. |
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
fn <- FunctionParameterName('x_s') print(fn)
fn <- FunctionParameterName('x_s') print(fn)
TestCaseDefinition
Prints the TestCaseDefinition
data
## S3 method for class 'TestCaseDefinition' print(x, ...)
## S3 method for class 'TestCaseDefinition' print(x, ...)
x |
the |
... |
any other argument, passed to print. |
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
b <- TestCaseDefinition(list(1L, 2L), 3L, 'sum of 2 integers') print(b)
b <- TestCaseDefinition(list(1L, 2L), 3L, 'sum of 2 integers') print(b)
As factory may be modified, this function allows you to make changes and to record them in your own specialized type factory, to match various needs and ease reuse.
retrieveFactory()
retrieveFactory()
Retrieves a FunctionParameterTypeFactory
from options variable named
op_type_factory
or provides a default type factory.
An R object
that is a FunctionParameterTypeFactory
.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
##---- typical case ---- ff <- retrieveFactory() ff$addSuffix('wo', "wo class", function(o_) is(o_, "wo")) ff$addSuffix('yo', "yo class", function(o_) is(o_, "yo")) ff$addSuffix('zo', "zo class", function(o_) is(o_, "zo")) options('op_type_factory' = ff) fg <- retrieveFactory() # retrieves the factory pointed by R variable ff fg$getRecordedTypes()[suffix %in% c('wo', 'yo', 'zo')] # right behavior ! # wrong behavior as retrieveFactory will provide the default factory and not yours! options('op_type_factory' = ff) fh <- retrieveFactory() # retrieves the default factory fh$getRecordedTypes()[suffix %in% c('wo', 'yo', 'zo')]
##---- typical case ---- ff <- retrieveFactory() ff$addSuffix('wo', "wo class", function(o_) is(o_, "wo")) ff$addSuffix('yo', "yo class", function(o_) is(o_, "yo")) ff$addSuffix('zo', "zo class", function(o_) is(o_, "zo")) options('op_type_factory' = ff) fg <- retrieveFactory() # retrieves the factory pointed by R variable ff fg$getRecordedTypes()[suffix %in% c('wo', 'yo', 'zo')] # right behavior ! # wrong behavior as retrieveFactory will provide the default factory and not yours! options('op_type_factory' = ff) fh <- retrieveFactory() # retrieves the default factory fh$getRecordedTypes()[suffix %in% c('wo', 'yo', 'zo')]
Retrieve function argument names from a function or a primitive.
retrieveFunctionArgumentNames(fun_f_1)
retrieveFunctionArgumentNames(fun_f_1)
fun_f_1 |
a function or primitive. Not a string! |
A vector
of strings
that are the function names.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
See retrieveFunctionArguments
.
See formalArgs
.
# typical test on a primitive retrieveFunctionArgumentNames(sin) #[1] "x" # typical test on a function retrieveFunctionArguments(ls) #[1] "name" "pos" "envir" "all.names" "pattern" "sorted"
# typical test on a primitive retrieveFunctionArgumentNames(sin) #[1] "x" # typical test on a function retrieveFunctionArguments(ls) #[1] "name" "pos" "envir" "all.names" "pattern" "sorted"
Retrieve function arguments to get arguments from a function or a primitive.
retrieveFunctionArguments(fun_f_1)
retrieveFunctionArguments(fun_f_1)
fun_f_1 |
a function or primitive. Not a string! |
A pairlist
.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
See retrieveFunctionArguments
.
See formalArgs
.
# typical test on a primitive retrieveFunctionArguments(sin) #$x # # typical test on a function retrieveFunctionArguments(ls) #$name #$pos #-1L #$envir #as.environment(pos) #$all.names #[1] FALSE #$pattern # #$sorted #[1] TRUE
# typical test on a primitive retrieveFunctionArguments(sin) #$x # # typical test on a function retrieveFunctionArguments(ls) #$name #$pos #-1L #$envir #as.environment(pos) #$all.names #[1] FALSE #$pattern # #$sorted #[1] TRUE
Retrieve the function return type definitions from an object
.
retrieveFunctionReturnTypes(object_o_1)
retrieveFunctionReturnTypes(object_o_1)
object_o_1 |
the |
A polymorphic return that is either
a list |
as returned by the |
another list |
as returned by the |
a data.table |
the function parameter types definition as declared in the source class |
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to defineEvaluationModes
.
##---- typical case ---- library('data.table') source(system.file('code-samples/no-defs/Addition.R', package = 'wyz.code.offensiveProgramming')) source(system.file('code-samples/frt-defs/good/full/AdditionFI.R', package = 'wyz.code.offensiveProgramming')) retrieveFunctionReturnTypes(AdditionFI()) # works, renders a data.table retrieveFunctionReturnTypes(Addition()) # fails, renders a list
##---- typical case ---- library('data.table') source(system.file('code-samples/no-defs/Addition.R', package = 'wyz.code.offensiveProgramming')) source(system.file('code-samples/frt-defs/good/full/AdditionFI.R', package = 'wyz.code.offensiveProgramming')) retrieveFunctionReturnTypes(AdditionFI()) # works, renders a data.table retrieveFunctionReturnTypes(Addition()) # fails, renders a list
Get the function names from a package name
retrievePackageFunctionNames(packageName_s_1, libraryPath_s_1 = .libPaths()[1])
retrievePackageFunctionNames(packageName_s_1, libraryPath_s_1 = .libPaths()[1])
packageName_s_1 |
a |
libraryPath_s_1 |
a |
A vector
of function names
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
# take to much time on Windows apparently to pass CRAN package acceptance tests if (.Platform$OS.type == "unix") retrievePackageFunctionNames('wyz.code.offensiveProgramming')
# take to much time on Windows apparently to pass CRAN package acceptance tests if (.Platform$OS.type == "unix") retrievePackageFunctionNames('wyz.code.offensiveProgramming')
From an instrumented class, retrieve the test case definitions or descriptions.
retrieveTestCaseDefinitions(object_o_1) retrieveTestCaseDescriptions(object_o_1)
retrieveTestCaseDefinitions(object_o_1) retrieveTestCaseDescriptions(object_o_1)
object_o_1 |
the |
For function
, retrieveTestCaseDefinitions
,
a polymorphic return that is either
a list |
as returned by the |
another list |
as returned by the
|
a data.table |
the test case definitions as declared in the source class |
For function
, retrieveTestCaseDescriptions
,
either a character vector
when no test case definitions exists or a
data.table
of the test case descriptions.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to defineEvaluationModes
.
##---- typical case ---- library('data.table') source(system.file('code-samples/tcd-defs/good/partial/AdditionTCPartial.R', package = 'wyz.code.offensiveProgramming')) source(system.file('code-samples/no-defs/Addition.R', package = 'wyz.code.offensiveProgramming')) retrieveTestCaseDefinitions(AdditionTCPartial()) # works, renders a data.table retrieveTestCaseDefinitions(Addition()) # fails, renders a list retrieveTestCaseDescriptions(Addition()) retrieveTestCaseDescriptions(AdditionTCPartial())
##---- typical case ---- library('data.table') source(system.file('code-samples/tcd-defs/good/partial/AdditionTCPartial.R', package = 'wyz.code.offensiveProgramming')) source(system.file('code-samples/no-defs/Addition.R', package = 'wyz.code.offensiveProgramming')) retrieveTestCaseDefinitions(AdditionTCPartial()) # works, renders a data.table retrieveTestCaseDefinitions(Addition()) # fails, renders a list retrieveTestCaseDescriptions(Addition()) retrieveTestCaseDescriptions(AdditionTCPartial())
function
Run a function from an object, according to the mentioned evaluation mode, and to the chosen type factory
runFunction(object_o_1, functionName_s_1, arguments_l, evaluationMode_o_1)
runFunction(object_o_1, functionName_s_1, arguments_l, evaluationMode_o_1)
object_o_1 |
the |
functionName_s_1 |
a single |
arguments_l |
a |
evaluationMode_o_1 |
an evaluation mode |
A list
with names
status |
a single |
value |
the result of the computation, might be a scalar or not, a warning, an error, ... |
mode |
the evaluation mode used to check the results |
function_return_type_check |
available if mode is different of |
parameter_type_checks |
available if mode is |
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to FunctionParameterTypeFactory
and
runFunction
.
##---- typical case ---- library('data.table') source(system.file('code-samples/frt-defs/good/full/AdditionFI.R', package = 'wyz.code.offensiveProgramming')) fi <- AdditionFI() runFunction(fi, 'addDouble', list(34, 44.6), EvaluationMode(defineEvaluationModes()[1])) runFunction(fi, 'addDouble', list(34, 44.6), EvaluationMode(defineEvaluationModes()[2])) runFunction(fi, 'addDouble', list(34, 44.6), EvaluationMode(defineEvaluationModes()[3]))
##---- typical case ---- library('data.table') source(system.file('code-samples/frt-defs/good/full/AdditionFI.R', package = 'wyz.code.offensiveProgramming')) fi <- AdditionFI() runFunction(fi, 'addDouble', list(34, 44.6), EvaluationMode(defineEvaluationModes()[1])) runFunction(fi, 'addDouble', list(34, 44.6), EvaluationMode(defineEvaluationModes()[2])) runFunction(fi, 'addDouble', list(34, 44.6), EvaluationMode(defineEvaluationModes()[3]))
Run specified test cases under the given evaluation mode
runTestCase(object_o_1, testCaseIndexes_i, evaluationMode_o_1 = EvaluationMode())
runTestCase(object_o_1, testCaseIndexes_i, evaluationMode_o_1 = EvaluationMode())
object_o_1 |
The R |
testCaseIndexes_i |
a |
evaluationMode_o_1 |
the evaluation mode to use. see |
A list
with two names
raw |
a |
synthesis |
a summary |
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to defineEvaluationModes
.
##---- typical case ---- library('data.table') source(system.file('code-samples/both-defs/good/full/AdditionTCFI_G1.R', package = 'wyz.code.offensiveProgramming')) em <- EvaluationMode('type_checking_enforcement') runTestCase(AdditionTCFI_G1(), c(3, 5, 7), em)
##---- typical case ---- library('data.table') source(system.file('code-samples/both-defs/good/full/AdditionTCFI_G1.R', package = 'wyz.code.offensiveProgramming')) em <- EvaluationMode('type_checking_enforcement') runTestCase(AdditionTCFI_G1(), c(3, 5, 7), em)
Run a function in a transient (non persistent) context.
runTransientFunction(function_f_1, arguments_l, evaluationMode_o_1, function_return_type_s_1)
runTransientFunction(function_f_1, arguments_l, evaluationMode_o_1, function_return_type_s_1)
function_f_1 |
a single R |
arguments_l |
a |
evaluationMode_o_1 |
an evaluation mode |
function_return_type_s_1 |
a |
A list
with names
status |
a single |
value |
the result of the computation, might be a scalar or not, a warning, an error, ... |
mode |
the evaluation mode used to check the results |
function_return_type_check |
available if mode is different of
|
parameter_type_checks |
available if mode is |
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to runFunction
.
##---- typical case ---- em <- EvaluationMode(defineEvaluationModes()[3]) h <- function(x_s) x_s runTransientFunction(h, list('neonira'), em, 'x_s') runTransientFunction(h, list(pi), em, 'x_s') runTransientFunction(h, list(pi), em, 'x_d')
##---- typical case ---- em <- EvaluationMode(defineEvaluationModes()[3]) h <- function(x_s) x_s runTransientFunction(h, list('neonira'), em, 'x_s') runTransientFunction(h, list(pi), em, 'x_s') runTransientFunction(h, list(pi), em, 'x_d')
Defines a test case
TestCaseDefinition(params_l, expectedResult_, description_s_1)
TestCaseDefinition(params_l, expectedResult_, description_s_1)
params_l |
a |
expectedResult_ |
test case expected result. This will be used to compare with function execution results |
description_s_1 |
a single entry character |
An object
that is an R environment
class.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to FunctionParameterTypeFactory
##---- typical case ---- tcd <- TestCaseDefinition(list(1:5), 15, 'sum of 5 first non nul integers') tcd <- TestCaseDefinition(list(1:7, 3:5, sample(1:100, 19, FALSE)), list(3:5), 'extract smallest length from input')
##---- typical case ---- tcd <- TestCaseDefinition(list(1:5), 15, 'sum of 5 first non nul integers') tcd <- TestCaseDefinition(list(1:7, 3:5, sample(1:100, 19, FALSE)), list(3:5), 'extract smallest length from input')
Verifies class name compliance with a policy.
verifyClassName(name_s = "MyClassName", strictSyntax_b_1 = TRUE)
verifyClassName(name_s = "MyClassName", strictSyntax_b_1 = TRUE)
name_s |
a |
strictSyntax_b_1 |
A When |
TRUE
when name complies with policy, FALSE
otherwise.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to defineEvaluationModes
.
##---- typical case ---- verifyClassName('matrix') verifyClassName('matrix', FALSE)
##---- typical case ---- verifyClassName('matrix') verifyClassName('matrix', FALSE)
Use this function to verify function arguments.
verifyFunctionArguments(arguments_l, abort_b_1 = TRUE, verbosity_b_1 = FALSE)
verifyFunctionArguments(arguments_l, abort_b_1 = TRUE, verbosity_b_1 = FALSE)
arguments_l |
An unconstrained |
abort_b_1 |
A single |
verbosity_b_1 |
A single |
This function allows to check all parameter types and values in a single line of code.
See examples below to know how to put this function in action.
Returned value depends on parameter abort_b_1
value.
When set to TRUE
, any error will abort processing by issuing a call to
stop
function.
When set to FALSE
, returned value is a boolean. It is TRUE
only
when no error have been detected. Otherwise FALSE
.
This function whenever used, should be the first statement of your function code.
Using this function outside function code is a non-sense.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
fun <- function(values_i_3m) { verifyFunctionArguments(mget(ls()), FALSE, FALSE) } fun(1) # [1] FALSE fun(1:7) # [1] TRUE nonOPFun <- function(x) { verifyFunctionArguments(mget(ls()), FALSE, TRUE) } nonOPFun(1:7) # $x # [1] 1 2 3 4 5 6 7 # # x FALSE unknown suffix, [NA] # # [1] FALSE # real use case with abortion myFunWithAbortion <- function(values_i_3m) { verifyFunctionArguments(mget(ls())) # ... } tryCatch(myFunWithAbortion(1), error = function(e) cat(e$message, '\n')) # argument mistmatch [values_i_3m] wrong length, was expecting [3m] , got [1] # real use case without abortion myFunWithoutAbortion <- function(values_i_3m) { if (!verifyFunctionArguments(mget(ls()), FALSE)) return(FALSE) cat('continuing processing ...\n') TRUE } myFunWithoutAbortion(1) # FALSE myFunWithoutAbortion(1:3) # continuing processing ... # TRUE
fun <- function(values_i_3m) { verifyFunctionArguments(mget(ls()), FALSE, FALSE) } fun(1) # [1] FALSE fun(1:7) # [1] TRUE nonOPFun <- function(x) { verifyFunctionArguments(mget(ls()), FALSE, TRUE) } nonOPFun(1:7) # $x # [1] 1 2 3 4 5 6 7 # # x FALSE unknown suffix, [NA] # # [1] FALSE # real use case with abortion myFunWithAbortion <- function(values_i_3m) { verifyFunctionArguments(mget(ls())) # ... } tryCatch(myFunWithAbortion(1), error = function(e) cat(e$message, '\n')) # argument mistmatch [values_i_3m] wrong length, was expecting [3m] , got [1] # real use case without abortion myFunWithoutAbortion <- function(values_i_3m) { if (!verifyFunctionArguments(mget(ls()), FALSE)) return(FALSE) cat('continuing processing ...\n') TRUE } myFunWithoutAbortion(1) # FALSE myFunWithoutAbortion(1:3) # continuing processing ... # TRUE
Function name must comply with a policy. This function allows to check compliance.
verifyFunctionName(name_s = "aSimpleFunctionName", strictSyntax_b_1 = TRUE)
verifyFunctionName(name_s = "aSimpleFunctionName", strictSyntax_b_1 = TRUE)
name_s |
The function name to be checked |
strictSyntax_b_1 |
A boolean value. When When |
A boolean
value, either TRUE
or FALSE
.
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to defineEvaluationModes
.
##---- typical case ---- verifyFunctionName('matrix') verifyFunctionName('matrix', FALSE)
##---- typical case ---- verifyFunctionName('matrix') verifyFunctionName('matrix', FALSE)
Verifies your declared return type definitions and detects anomalies.
verifyFunctionReturnTypesDefinition(object_o_1, requiresFullInstrumentation_b_1 = TRUE)
verifyFunctionReturnTypesDefinition(object_o_1, requiresFullInstrumentation_b_1 = TRUE)
object_o_1 |
The |
requiresFullInstrumentation_b_1 |
a |
When requiresFullInstrumentation_b_1
is TRUE
,
each function must have an entry in the test case parameter definition.
A list
with names
validity |
a single |
class |
the class name of the provided |
intent |
the stage of the failure, provides hint about the faced issue |
message |
some hints to resolve the issue(s). |
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to defineTestCaseDefinitionsParameterName
.
##---- typical case ---- library('data.table') source(system.file('code-samples/frt-defs/good/full/AdditionFI.R', package = 'wyz.code.offensiveProgramming')) fi <- AdditionFI() print(verifyFunctionReturnTypesDefinition(fi)) print(verifyFunctionReturnTypesDefinition(fi, FALSE))
##---- typical case ---- library('data.table') source(system.file('code-samples/frt-defs/good/full/AdditionFI.R', package = 'wyz.code.offensiveProgramming')) fi <- AdditionFI() print(verifyFunctionReturnTypesDefinition(fi)) print(verifyFunctionReturnTypesDefinition(fi, FALSE))
Verify object class name, object function names, and object function parameter names, and provides a synthesis of executed checks.
Proceeds also to some introspection on object
to identify instrumentation of function
return types and test case definitions. Provides information about completeness of instruction,
and about missing functions and test cases.
verifyObjectNames(object_o_1)
verifyObjectNames(object_o_1)
object_o_1 |
the object to be checked |
A list
with following names
class_name |
the class name of the provided |
supports_strict_compliance |
a single |
supports_lazy_compliance |
a single |
class_name_compliance |
a |
class_name_compliance |
a |
class_name_compliance |
a |
owns_function_return_type_information |
a single |
can_be_type_checked |
a single |
is_function_fully_instrumented |
a single |
missing_function |
a |
owns_test_case_definitions |
a single |
is_test_case_fully_instrumented |
a single |
missing_test_cases |
a single |
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to verifyClassName
and
verifyFunctionName
.
##---- typical case ---- library('data.table') source(system.file('code-samples/frt-defs/good/full/AdditionFI.R', package = 'wyz.code.offensiveProgramming')) fi <- AdditionFI() print(verifyObjectNames(fi))
##---- typical case ---- library('data.table') source(system.file('code-samples/frt-defs/good/full/AdditionFI.R', package = 'wyz.code.offensiveProgramming')) fi <- AdditionFI() print(verifyObjectNames(fi))
Checks for test cases definition compliance and dectects uncompliances.
verifyTestCaseDefinitions(object_o_1, requiresFullInstrumentation_b_1 = TRUE)
verifyTestCaseDefinitions(object_o_1, requiresFullInstrumentation_b_1 = TRUE)
object_o_1 |
The |
requiresFullInstrumentation_b_1 |
a |
When requiresFullInstrumentation_b_1
is TRUE
, each function
must have an entry in the test case parameter definition.
A list
with names
validity |
a single |
class |
the class name of the provided |
intent |
the stage of the failure, provides hint about the faced issue |
message |
some hints to resolve the issue(s). |
Fabien Gelineau <[email protected]>
Maintainer: Fabien Gelineau <[email protected]>
Refer to defineTestCaseDefinitionsParameterName
.
##---- typical case ---- library('data.table') source(system.file('code-samples/tcd-defs/good/full/AdditionTC.R', package = 'wyz.code.offensiveProgramming')) tc <- AdditionTC() print(verifyTestCaseDefinitions(tc))
##---- typical case ---- library('data.table') source(system.file('code-samples/tcd-defs/good/full/AdditionTC.R', package = 'wyz.code.offensiveProgramming')) tc <- AdditionTC() print(verifyTestCaseDefinitions(tc))