#!/usr/bin/r -t
#
# Copyright (C) 2010 - 2014 Dirk Eddelbuettel and Romain Francois
#
# This file is part of Rcpp.
#
# Rcpp is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# Rcpp is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Rcpp. If not, see .
.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"
if (.runThisTest) {
.setUp <- Rcpp:::unitTestSetup("wrap.cpp")
test.wrap.map.string.int <- function(){
checkEquals(map_string_int(),
c( a = 200L, b = 100L, c = 300L),
msg = "wrap( map) " )
}
test.wrap.map.string.double <- function(){
checkEquals(map_string_double(),
c( a = 200, b = 100, c = 300),
msg = "wrap( map) " )
}
test.wrap.map.string.bool <- function(){
checkEquals(map_string_bool(),
c( a = FALSE, b = TRUE, c = TRUE ),
msg = "wrap( map) " )
}
test.wrap.map.string.Rbyte <- function(){
checkEquals(map_string_Rbyte(),
c( a = as.raw(1), b = as.raw(0), c = as.raw(2) ),
msg = "wrap( map) " )
}
test.wrap.map.string.string <- function(){
checkEquals(map_string_string(),
c( a = "bar", b = "foo", c = "bling" ),
msg = "wrap( map) " )
}
test.wrap.map.string.generic <- function(){
checkEquals(map_string_generic(),
list( a = c(1L, 2L, 2L), b = c(1L, 2L), c = c(1L,2L,2L,2L) ) ,
msg = "wrap( map>) " )
}
test.wrap.multimap.string.int <- function(){
checkEquals(multimap_string_int(),
c( a = 200L, b = 100L, c = 300L),
msg = "wrap( multimap) ")
}
test.wrap.multimap.string.double <- function(){
checkEquals(multimap_string_double(),
c( a = 200, b = 100, c = 300),
msg = "wrap( multimap) " )
}
test.wrap.multimap.string.bool <- function(){
checkEquals(multimap_string_bool(),
c( a = FALSE, b = TRUE, c = TRUE ),
msg = "wrap( multimap)")
}
test.wrap.multimap.string.Rbyte <- function(){
checkEquals(multimap_string_Rbyte(),
c( a = as.raw(1), b = as.raw(0), c = as.raw(2) ),
msg = "wrap( multimap) " )
}
test.wrap.multimap.string.string <- function(){
checkEquals(multimap_string_string(),
c( a = "bar", b = "foo", c = "bling" ),
msg = "wrap( multimap) " )
}
test.wrap.multimap.string.generic <- function(){
checkEquals(multimap_string_generic(),
list( a = c(1L, 2L, 2L), b = c(1L, 2L), c = c(1L,2L,2L,2L) ) ,
msg = "wrap( multimap>) " )
}
test.nonnull.const.char <- function() {
checkEquals(nonnull_const_char(),
"foo",
msg = "null const char*")
}
test.wrap.unordered.map.string.int <- function(){
res <- unordered_map_string_int()
checkEquals( res[["a"]], 200L, msg = "wrap( tr1::unordered_map) " )
checkEquals( res[["b"]], 100L, msg = "wrap( tr1::unordered_map) " )
checkEquals( res[["c"]], 300L, msg = "wrap( tr1::unordered_map) " )
}
test.wrap.unordered.map.string.double <- function(){
res <- unordered_map_string_double()
checkEquals( res[["a"]], 200, msg = "wrap( tr1::unordered_map) " )
checkEquals( res[["b"]], 100, msg = "wrap( tr1::unordered_map) " )
checkEquals( res[["c"]], 300, msg = "wrap( tr1::unordered_map) " )
}
test.wrap.unordered.map.string.bool <- function(){
res <- unordered_map_string_bool()
checkEquals( res[["a"]], FALSE, msg = "wrap( tr1::unordered_map) " )
checkEquals( res[["b"]], TRUE , msg = "wrap( tr1::unordered_map) " )
checkEquals( res[["c"]], TRUE , msg = "wrap( tr1::unordered_map) " )
}
test.wrap.unordered.map.string.Rbyte <- function(){
res <- unordered_map_string_Rbyte()
checkEquals( res[["a"]], as.raw(1), msg = "wrap( tr1::unordered_map) " )
checkEquals( res[["b"]], as.raw(0), msg = "wrap( tr1::unordered_map) " )
checkEquals( res[["c"]], as.raw(2), msg = "wrap( tr1::unordered_map) " )
}
test.wrap.unordered.map.string.string <- function(){
res <- unordered_map_string_string()
checkEquals( res[["a"]], "bar" , msg = "wrap( tr1::unordered_map) " )
checkEquals( res[["b"]], "foo" , msg = "wrap( tr1::unordered_map) " )
checkEquals( res[["c"]], "bling" , msg = "wrap( tr1::unordered_map) " )
}
test.wrap.unordered.map.string.generic <- function(){
res <- unordered_map_string_generic()
checkEquals( res[["a"]], c(1L,2L,2L) , msg = "wrap( tr1::unordered_map>) " )
checkEquals( res[["b"]], c(1L,2L) , msg = "wrap( tr1::unordered_map>) " )
checkEquals( res[["c"]], c(1L,2L,2L,2L) , msg = "wrap( tr1::unordered_map>) " )
}
test.wrap.map.int.double <- function(){
checkEquals(
map_int_double(),
c("-1" = 3, "0" = 2 ),
msg = "std::map"
)
}
test.wrap.map.double.double <- function(){
checkEquals(
map_double_double(),
c("0" = 2, "1.2" = 3 ),
msg = "std::map"
)
}
test.wrap.map.int.vector_double <- function(){
checkEquals(
map_int_vector_double(),
list("0" = c(1,2), "1" = c(2,3) ),
msg = "std::map >"
)
}
test.wrap.map.int.Foo <- function(){
checkEquals(
sapply( map_int_Foo(), function(.) .$get() ),
c("0" = 2, "1" = 3 ),
msg = "std::map"
)
}
test.wrap.vector.Foo <- function(){
checkEquals(
sapply( vector_Foo(), function(.) .$get() ),
c(2, 3),
msg = "std::vector< MODULE EXPOSED CLASS >"
)
}
}