Improve li_std_vector_vector runtime test for R

- Fix unittest_sequence to fail if elements don't match.
- li_std_vector_vector testcase fixes.

Replace list with c because vectors in R are not exactly lists,
therefore comparing vectors (returned by C++) with R lists
complicates things a lot. Added as.integer because by default
numbers are numeric and I guess we want to check the exact type
returned by C++ which is integer the first check fails because
make_vector_int returns a vector of strings (containing numbers),
not integers (in the previous version this test would pass
because R does an implicit 

Closes #2448
This commit is contained in:
AndLLA 2023-09-11 19:35:57 +02:00 committed by GitHub
parent 64c9720a7a
commit 04355afeb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 13 deletions

View File

@ -11,9 +11,9 @@ namespace std {
}; };
%inline %{ %inline %{
std::vector<std::string> make_vector_int() { std::vector<int> make_vector_int() {
std::string x[5] = {"1", "2", "3", "4", "5"}; int x[5] = {1, 2, 3, 4, 5};
std::vector<std::string> v; std::vector<int> v;
for (size_t i = 0; i < 5; ++i) for (size_t i = 0; i < 5; ++i)
v.push_back(x[i]); v.push_back(x[i]);
return v; return v;

View File

@ -6,23 +6,24 @@ source("li_std_vector_vector.R")
cacheMetaData(1) cacheMetaData(1)
v = make_vector_int() v = make_vector_int()
unittest_sequence(v, list(1, 2, 3, 4, 5)) unittest_sequence(v, as.integer(c(1, 2, 3, 4, 5)))
v = make_vector_vector_int() v = make_vector_vector_int()
unittest(length(v), 1) unittest(length(v), 1)
unittest_sequence(v[[1]], list(1, 2, 3, 4, 5)) unittest_sequence(v[[1]], as.integer(c(1, 2, 3, 4, 5)))
v = make_vector_bool() v = make_vector_bool()
unittest_sequence(v, list(TRUE, FALSE, FALSE, FALSE, TRUE)) unittest_sequence(v, c(TRUE, FALSE, FALSE, FALSE, TRUE))
print(v) print(v)
v = make_vector_vector_bool() v = make_vector_vector_bool()
unittest(length(v), 1) unittest(length(v), 1)
print(v) print(v)
unittest_sequence(v[[1]], list(FALSE, TRUE, TRUE, TRUE, FALSE)) # Does not actually fail if no match, arg, needs fixing unittest_sequence(v[[1]], c(FALSE, TRUE, TRUE, TRUE, FALSE))
v = make_vector_string() v = make_vector_string()
unittest_sequence(v, list("aa", "bb", "cc", "dd", "ee")) unittest_sequence(v, c("aa", "bb", "cc", "dd", "ee"))
v = make_vector_vector_string() v = make_vector_vector_string()
unittest(length(v), 1) unittest(length(v), 1)
unittest_sequence(v[[1]], list("1", "2", "3", "4", "5")) unittest_sequence(v[[1]], c("1", "2", "3", "4", "5"))
q(save="no") q(save="no")

View File

@ -18,10 +18,26 @@ unittesttol <- function(x,y,z) {
} }
unittest_sequence <- function (x,y) { unittest_sequence <- function (x,y) {
if (setequal(x, y)) { x = as.vector(x)
y = as.vector(y)
if (length(x) == 0 && length(y) == 0) {
print("PASS") print("PASS")
} else { return()
print("FAIL")
stop("Test failed")
} }
if (class(x[1]) != class(y[1])) {
print("FAILED")
stop(paste("Test failed: ", class(x[1]), " != ", class(y[1])))
}
try(expr = {
if (!any(x != y)) {
print("PASS")
return()
}
}, silent = T)
print("FAIL")
stop("Test failed")
} }