R Under development (unstable) (2024-01-24 r85824 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > #------------------------------------------------------------------------------# > # Author: Laurent R. Bergé > # Created: 2024-01-17 > # ~: Main tests > #------------------------------------------------------------------------------# > > > library(indexthis) > test = indexthis:::test > > # In these tests, we check the consistency of the results, quite extensively > # we cover all the branches in the cpp code > > n = 500 > > words = paste0(rep(letters, 5), rep(letters, each = 5), rep(rev(letters), 5)) > > years = 1800:2023 > months = 1:12 > day = 1:28 > date_sample = as.Date(paste0(sample(years, 200, TRUE), "-", + sample(months, 200, TRUE), "-", + sample(day, 200, TRUE))) > > > set.seed(1) > base = list( + int = as.integer(rnorm(n, sd = 8)), + fact = factor(sample(letters[-(1:5)], n, TRUE), letters), + bool = sample(c(TRUE, FALSE), n, TRUE), + dbl_int = round(rnorm(n, sd = 8)), + dbl = round(rnorm(n, sd = 8), 1), + char = sample(words, n, TRUE), + date = sample(date_sample, n, TRUE), + complex = complex(real = round(rnorm(n, sd = 4)), imaginary = round(rnorm(n, sd = 4))) + ) > > #### > #### single vector #### > #### > > for(i_type in seq_along(base)){ + cat(format(names(base))[i_type]) + x = base[[i_type]] + for(any_na in c(FALSE, TRUE)){ + cat(".") + if(any_na){ + x[c(1, 32, 65, 125)] = NA + } + + index = to_index(x) + + x_char = as.character(x) + if(any_na){ + x_char[is.na(x_char)] = "NA" + } + index_r = unclass(as.factor(x_char)) + + test(nrow(unique(data.frame(index, index_r))), max(index)) + } + cat("\n") + } int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. > > > > #### > #### double vector #### > #### > > for(i_type in seq_along(base)){ + cat(format(names(base))[i_type]) + x_raw = base[[i_type]] + for(j_type in seq_along(base)){ + cat("\n ", format(names(base))[j_type]) + y_raw = base[[j_type]] + for(any_na in c(FALSE, TRUE)){ + cat(".") + x = x_raw + y = y_raw + if(any_na){ + x[c(1, 32, 65, 125)] = NA + y[c(1, 32)] = y[1] + + y[c(2, 33, 65, 200, 225)] = NA + x[c(2, 33)] = x[2] + } + + index = to_index(x, y) + + x_char = paste0(x, "_", y) + index_r = unclass(as.factor(x_char)) + + test(nrow(unique(data.frame(index, index_r))), max(index)) + } + } + cat("\n") + } int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. fact int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. bool int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl_int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. char int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. date int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. complex int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. > > #### > #### triple vector #### > #### > > for(i_type in seq_along(base)){ + + cat(format(names(base))[i_type]) + x_raw = base[[i_type]] + + for(j_type in seq_along(base)){ + + cat("\n ", format(names(base))[j_type]) + y_raw = base[[j_type]] + + for(k_type in seq_along(base)){ + + cat("\n ", format(names(base))[k_type]) + z_raw = base[[k_type]] + + for(any_na in c(FALSE, TRUE)){ + cat(".") + + x = x_raw + y = y_raw + z = z_raw + + if(any_na){ + x[c(1, 32, 65, 125)] = NA + y[c(1, 32)] = y[1] + + y[c(2, 33, 65, 200, 225)] = NA + x[c(2, 33)] = x[2] + + z[c(8, 33, 50, 125)] = NA + } + + index = to_index(x, y, z) + + x_char = paste0(x, "_", y, "_", z) + index_r = unclass(as.factor(x_char)) + + test(nrow(unique(data.frame(index, index_r))), max(index)) + } + } + } + cat("\n") + } int int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. fact int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. bool int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl_int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. char int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. date int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. complex int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. fact int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. fact int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. bool int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl_int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. char int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. date int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. complex int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. bool int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. fact int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. bool int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl_int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. char int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. date int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. complex int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl_int int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. fact int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. bool int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl_int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. char int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. date int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. complex int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. fact int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. bool int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl_int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. char int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. date int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. complex int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. char int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. fact int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. bool int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl_int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. char int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. date int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. complex int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. date int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. fact int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. bool int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl_int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. char int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. date int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. complex int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. complex int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. fact int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. bool int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl_int int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. dbl int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. char int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. date int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. complex int .. fact .. bool .. dbl_int.. dbl .. char .. date .. complex.. > > > #### > #### quadruple vectors #### > #### > > int_types = 1:4 > for(i_type in int_types){ + + x_raw = base[[i_type]] + + for(j_type in int_types){ + + y_raw = base[[j_type]] + + for(k_type in int_types){ + + z_raw = base[[k_type]] + + for(l_type in int_types){ + + cat("\n", + format(names(base))[i_type], ", ", + format(names(base))[j_type], ", ", + format(names(base))[k_type], ", ", + format(names(base))[l_type], sep = "") + zz_raw = base[[l_type]] + + for(any_na in c(FALSE, TRUE)){ + cat(".") + + x = x_raw + y = y_raw + z = z_raw + zz = zz_raw + + if(any_na){ + x[c(1, 32, 65, 125)] = NA + y[c(1, 32)] = y[1] + + y[c(2, 33, 65, 200, 225)] = NA + x[c(2, 33)] = x[2] + + z[c(8, 33, 50, 200)] = NA + + zz[c(8, 33, 50, 200)] = NA + } + + index = to_index(x, y, z, zz) + + x_char = paste0(x, "_", y, "_", z, "_", zz) + index_r = unclass(as.factor(x_char)) + + test(nrow(unique(data.frame(index, index_r))), max(index)) + } + } + } + } + cat("\n--------------------------------------------\n") + } int , int , int , int .. int , int , int , fact .. int , int , int , bool .. int , int , int , dbl_int.. int , int , fact , int .. int , int , fact , fact .. int , int , fact , bool .. int , int , fact , dbl_int.. int , int , bool , int .. int , int , bool , fact .. int , int , bool , bool .. int , int , bool , dbl_int.. int , int , dbl_int, int .. int , int , dbl_int, fact .. int , int , dbl_int, bool .. int , int , dbl_int, dbl_int.. int , fact , int , int .. int , fact , int , fact .. int , fact , int , bool .. int , fact , int , dbl_int.. int , fact , fact , int .. int , fact , fact , fact .. int , fact , fact , bool .. int , fact , fact , dbl_int.. int , fact , bool , int .. int , fact , bool , fact .. int , fact , bool , bool .. int , fact , bool , dbl_int.. int , fact , dbl_int, int .. int , fact , dbl_int, fact .. int , fact , dbl_int, bool .. int , fact , dbl_int, dbl_int.. int , bool , int , int .. int , bool , int , fact .. int , bool , int , bool .. int , bool , int , dbl_int.. int , bool , fact , int .. int , bool , fact , fact .. int , bool , fact , bool .. int , bool , fact , dbl_int.. int , bool , bool , int .. int , bool , bool , fact .. int , bool , bool , bool .. int , bool , bool , dbl_int.. int , bool , dbl_int, int .. int , bool , dbl_int, fact .. int , bool , dbl_int, bool .. int , bool , dbl_int, dbl_int.. int , dbl_int, int , int .. int , dbl_int, int , fact .. int , dbl_int, int , bool .. int , dbl_int, int , dbl_int.. int , dbl_int, fact , int .. int , dbl_int, fact , fact .. int , dbl_int, fact , bool .. int , dbl_int, fact , dbl_int.. int , dbl_int, bool , int .. int , dbl_int, bool , fact .. int , dbl_int, bool , bool .. int , dbl_int, bool , dbl_int.. int , dbl_int, dbl_int, int .. int , dbl_int, dbl_int, fact .. int , dbl_int, dbl_int, bool .. int , dbl_int, dbl_int, dbl_int.. -------------------------------------------- fact , int , int , int .. fact , int , int , fact .. fact , int , int , bool .. fact , int , int , dbl_int.. fact , int , fact , int .. fact , int , fact , fact .. fact , int , fact , bool .. fact , int , fact , dbl_int.. fact , int , bool , int .. fact , int , bool , fact .. fact , int , bool , bool .. fact , int , bool , dbl_int.. fact , int , dbl_int, int .. fact , int , dbl_int, fact .. fact , int , dbl_int, bool .. fact , int , dbl_int, dbl_int.. fact , fact , int , int .. fact , fact , int , fact .. fact , fact , int , bool .. fact , fact , int , dbl_int.. fact , fact , fact , int .. fact , fact , fact , fact .. fact , fact , fact , bool .. fact , fact , fact , dbl_int.. fact , fact , bool , int .. fact , fact , bool , fact .. fact , fact , bool , bool .. fact , fact , bool , dbl_int.. fact , fact , dbl_int, int .. fact , fact , dbl_int, fact .. fact , fact , dbl_int, bool .. fact , fact , dbl_int, dbl_int.. fact , bool , int , int .. fact , bool , int , fact .. fact , bool , int , bool .. fact , bool , int , dbl_int.. fact , bool , fact , int .. fact , bool , fact , fact .. fact , bool , fact , bool .. fact , bool , fact , dbl_int.. fact , bool , bool , int .. fact , bool , bool , fact .. fact , bool , bool , bool .. fact , bool , bool , dbl_int.. fact , bool , dbl_int, int .. fact , bool , dbl_int, fact .. fact , bool , dbl_int, bool .. fact , bool , dbl_int, dbl_int.. fact , dbl_int, int , int .. fact , dbl_int, int , fact .. fact , dbl_int, int , bool .. fact , dbl_int, int , dbl_int.. fact , dbl_int, fact , int .. fact , dbl_int, fact , fact .. fact , dbl_int, fact , bool .. fact , dbl_int, fact , dbl_int.. fact , dbl_int, bool , int .. fact , dbl_int, bool , fact .. fact , dbl_int, bool , bool .. fact , dbl_int, bool , dbl_int.. fact , dbl_int, dbl_int, int .. fact , dbl_int, dbl_int, fact .. fact , dbl_int, dbl_int, bool .. fact , dbl_int, dbl_int, dbl_int.. -------------------------------------------- bool , int , int , int .. bool , int , int , fact .. bool , int , int , bool .. bool , int , int , dbl_int.. bool , int , fact , int .. bool , int , fact , fact .. bool , int , fact , bool .. bool , int , fact , dbl_int.. bool , int , bool , int .. bool , int , bool , fact .. bool , int , bool , bool .. bool , int , bool , dbl_int.. bool , int , dbl_int, int .. bool , int , dbl_int, fact .. bool , int , dbl_int, bool .. bool , int , dbl_int, dbl_int.. bool , fact , int , int .. bool , fact , int , fact .. bool , fact , int , bool .. bool , fact , int , dbl_int.. bool , fact , fact , int .. bool , fact , fact , fact .. bool , fact , fact , bool .. bool , fact , fact , dbl_int.. bool , fact , bool , int .. bool , fact , bool , fact .. bool , fact , bool , bool .. bool , fact , bool , dbl_int.. bool , fact , dbl_int, int .. bool , fact , dbl_int, fact .. bool , fact , dbl_int, bool .. bool , fact , dbl_int, dbl_int.. bool , bool , int , int .. bool , bool , int , fact .. bool , bool , int , bool .. bool , bool , int , dbl_int.. bool , bool , fact , int .. bool , bool , fact , fact .. bool , bool , fact , bool .. bool , bool , fact , dbl_int.. bool , bool , bool , int .. bool , bool , bool , fact .. bool , bool , bool , bool .. bool , bool , bool , dbl_int.. bool , bool , dbl_int, int .. bool , bool , dbl_int, fact .. bool , bool , dbl_int, bool .. bool , bool , dbl_int, dbl_int.. bool , dbl_int, int , int .. bool , dbl_int, int , fact .. bool , dbl_int, int , bool .. bool , dbl_int, int , dbl_int.. bool , dbl_int, fact , int .. bool , dbl_int, fact , fact .. bool , dbl_int, fact , bool .. bool , dbl_int, fact , dbl_int.. bool , dbl_int, bool , int .. bool , dbl_int, bool , fact .. bool , dbl_int, bool , bool .. bool , dbl_int, bool , dbl_int.. bool , dbl_int, dbl_int, int .. bool , dbl_int, dbl_int, fact .. bool , dbl_int, dbl_int, bool .. bool , dbl_int, dbl_int, dbl_int.. -------------------------------------------- dbl_int, int , int , int .. dbl_int, int , int , fact .. dbl_int, int , int , bool .. dbl_int, int , int , dbl_int.. dbl_int, int , fact , int .. dbl_int, int , fact , fact .. dbl_int, int , fact , bool .. dbl_int, int , fact , dbl_int.. dbl_int, int , bool , int .. dbl_int, int , bool , fact .. dbl_int, int , bool , bool .. dbl_int, int , bool , dbl_int.. dbl_int, int , dbl_int, int .. dbl_int, int , dbl_int, fact .. dbl_int, int , dbl_int, bool .. dbl_int, int , dbl_int, dbl_int.. dbl_int, fact , int , int .. dbl_int, fact , int , fact .. dbl_int, fact , int , bool .. dbl_int, fact , int , dbl_int.. dbl_int, fact , fact , int .. dbl_int, fact , fact , fact .. dbl_int, fact , fact , bool .. dbl_int, fact , fact , dbl_int.. dbl_int, fact , bool , int .. dbl_int, fact , bool , fact .. dbl_int, fact , bool , bool .. dbl_int, fact , bool , dbl_int.. dbl_int, fact , dbl_int, int .. dbl_int, fact , dbl_int, fact .. dbl_int, fact , dbl_int, bool .. dbl_int, fact , dbl_int, dbl_int.. dbl_int, bool , int , int .. dbl_int, bool , int , fact .. dbl_int, bool , int , bool .. dbl_int, bool , int , dbl_int.. dbl_int, bool , fact , int .. dbl_int, bool , fact , fact .. dbl_int, bool , fact , bool .. dbl_int, bool , fact , dbl_int.. dbl_int, bool , bool , int .. dbl_int, bool , bool , fact .. dbl_int, bool , bool , bool .. dbl_int, bool , bool , dbl_int.. dbl_int, bool , dbl_int, int .. dbl_int, bool , dbl_int, fact .. dbl_int, bool , dbl_int, bool .. dbl_int, bool , dbl_int, dbl_int.. dbl_int, dbl_int, int , int .. dbl_int, dbl_int, int , fact .. dbl_int, dbl_int, int , bool .. dbl_int, dbl_int, int , dbl_int.. dbl_int, dbl_int, fact , int .. dbl_int, dbl_int, fact , fact .. dbl_int, dbl_int, fact , bool .. dbl_int, dbl_int, fact , dbl_int.. dbl_int, dbl_int, bool , int .. dbl_int, dbl_int, bool , fact .. dbl_int, dbl_int, bool , bool .. dbl_int, dbl_int, bool , dbl_int.. dbl_int, dbl_int, dbl_int, int .. dbl_int, dbl_int, dbl_int, fact .. dbl_int, dbl_int, dbl_int, bool .. dbl_int, dbl_int, dbl_int, dbl_int.. -------------------------------------------- > > > #### > #### edge cases #### > #### > > base_na = list( + int = rep(NA_integer_, 50), + dbl = rep(NA_real_, 50), + char = rep(NA_character_, 50), + complex = rep(NA_complex_, 50) + ) > > for(i in seq_along(base_na)){ + index = to_index(base_na[[i]]) + test(all(index == index[1]), TRUE) + } > > for(i in seq_along(base_na)){ + for(j in seq_along(base_na)){ + index = to_index(base_na[[i]], base_na[[j]]) + test(all(index == index[1]), TRUE) + } + } > > > > > proc.time() user system elapsed 9.15 0.34 9.46