Add validation for R/UN_gcd.R
agarbiak opened this issue · comments
Add input validation for UN_gcd()
and UN_gcd_log()
similar to UN_x2.R:
Lines 14 to 44 in 839e0b1
# Ensure input symbols match tape_language | |
if ( | |
sum(!(input %in% tape_language)) > 0 | |
) { | |
unrecognised_symbols <- unique(input[!(input %in% tape_language)]) | |
stop( | |
paste0( | |
"Input contains symbols that are not specified in the instruction set.", | |
"The unrecognised symbols are: ", | |
paste(unrecognised_symbols, collapse = ", "), | |
"." | |
) | |
) | |
} | |
# Ensure input is correctly specified for UN_ function | |
if ( | |
sum(input %in% "1") != length(input) | |
) { | |
invalid_symbols <- unique( | |
input[!(input %in% "1")] | |
) | |
stop( | |
paste0( | |
"Input contains non-unary symbols. UN_ functions require unary inputs.", | |
"The invalid symbols are: ", | |
paste(invalid_symbols, collapse = ", "), | |
"." | |
) | |
) | |
} |
#5 adds validation.