Skip to content
Snippets Groups Projects
Commit bbfa882a authored by Reinhold Kainhofer's avatar Reinhold Kainhofer Committed by Reinhold Kainhofer
Browse files

Check valid values of tariff type

Closes #59
parent c2cee036
No related branches found
No related tags found
No related merge requests found
...@@ -42,6 +42,15 @@ TariffTypeEnum = objectProperties::setSingleEnum( ...@@ -42,6 +42,15 @@ TariffTypeEnum = objectProperties::setSingleEnum(
"dread-disease", "dread-disease",
"endowment + dread-disease" "endowment + dread-disease"
)) ))
setValidity("TariffTypeSingleEnum", function(object) {
if (length(object) != 1L) {
"Only one tariff type can be given"
} else if (!object %in% levels(object)) {
paste("Tarif type '", object, "' does not exist. Valid tariff types are:",
paste0("\n('", paste0(levels(object), collapse = "', '"),
"')"), sep = "")
}
});
############# Class InsuranceTarif ########################################### ############# Class InsuranceTarif ###########################################
...@@ -160,7 +169,7 @@ InsuranceTarif = R6Class( ...@@ -160,7 +169,7 @@ InsuranceTarif = R6Class(
#' temporary dread-disease insurance. Benefits occur either on death, #' temporary dread-disease insurance. Benefits occur either on death,
#' severe illness or survival, whichever comes first.} #' severe illness or survival, whichever comes first.}
#' } #' }
tariffType = ("wholelife"), tariffType = TariffTypeEnum("wholelife"),
#' @field Parameters A data structure (nested list) containing all relevant #' @field Parameters A data structure (nested list) containing all relevant
#' parameters describing a contract, its underlying tariff, the profit #' parameters describing a contract, its underlying tariff, the profit
...@@ -206,7 +215,9 @@ InsuranceTarif = R6Class( ...@@ -206,7 +215,9 @@ InsuranceTarif = R6Class(
#' i = 0.01, mortalityTable = AVOe2005R.male) #' i = 0.01, mortalityTable = AVOe2005R.male)
initialize = function(name = NULL, type = "wholelife", tarif = "Generic Tarif", desc = "Description of tarif", ...) { initialize = function(name = NULL, type = "wholelife", tarif = "Generic Tarif", desc = "Description of tarif", ...) {
if (!missing(name)) self$name = name; if (!missing(name)) self$name = name;
if (!missing(type)) self$tariffType = type; if (!missing(type)) {
self$tariffType = TariffTypeEnum(type)
}
if (!missing(tarif)) self$tarif = tarif; if (!missing(tarif)) self$tarif = tarif;
if (!missing(desc)) self$desc = desc; if (!missing(desc)) self$desc = desc;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment