File: runit.ListOf.R

package info (click to toggle)
rcpp 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 12,344 kB
  • sloc: ansic: 43,817; cpp: 39,947; sh: 51; makefile: 2
file content (101 lines) | stat: -rw-r--r-- 2,981 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Copyright (C) 2014  Dirk Eddelbuettel, Romain Francois and Kevin Ushey
#
# 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 <http://www.gnu.org/licenses/>.

.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"

if (.runThisTest) {

    .setUp <- Rcpp:::unitTestSetup("ListOf.cpp")

    x <- list( c(1, 5), c(2, 6), c(3, 7) )

    test.ListOf.identity <- function() {
        checkIdentical(
            test_identity(setNames(x, c('a', 'b', 'c'))),
            setNames(x, c('a', 'b', 'c'))
        )
    }

    test.ListOf.lapply.sum <- function() {
        x <- list( c(1, 5), c(2, 6), c(3, 7) )
        checkIdentical( test_lapply_sum(x), lapply(x, sum) )
    }

    test.ListOf.sapply.sum <- function() {
        x <- list( c(1, 5), c(2, 6), c(3, 7) )
        checkIdentical( test_sapply_sum(x), sapply(x, sum) )
    }

    test.ListOf.assign <- function() {
        x <- list( c(1, 5), c(2, 6), c(3, 7) )
        test_assign(x, 100, "apple")
        checkIdentical( x[[2]], 100 )
    }

    test.ListOf.assign.names <- function() {
        x <- setNames(list(1, 2, 3), c('a', 'b', 'c'))
        test_assign_names(x)
        checkIdentical( x[["a"]], x[["b"]] )
    }

    test.ListOf.arith <- function() {
        checkIdentical(test_add(list(1, 2, 3)), 6)
        checkIdentical(test_add_subtract(list(1, 2, 3)), 0)
        checkIdentical(test_mult( list(1, 2, 3) ), 6)
        checkIdentical(test_char( list("banana") ), list("apple"))
    }

    test.ListOf.assign.names <- function() {
        checkException(test_assign_names(list(alpha=1, beta=2, gamma=3)))
    }

    test.ListOf.sub.calls <- function() {
        checkEquals(test_sub_calls( list(1, 2, 3) ), 3)
    }

    test.ListOf.nested <- function() {
        checkEquals(
            test_nested_listof( list(list(1)) ),
            1
        )
    }

    test.ListOf.convert.implicit <- function() {
        checkEquals(
            test_return_IVList(list(1, 2, 3)),
            list(1L, 2L, 3L)
        )
    }

    test.ListOf.convert.fail <- function() {
        checkException(
            test_return_IVList(list("a", "b", "c"))
        )
    }

    test.ListOf.names <- function() {
        l <- list(a = 1L, b = 2L, c = 3L)
        checkEquals(listof_names(l), c("a", "b", "c"))
    }

    test.ListOf.attr.foo <- function() {
        l <- list(a = 1L)
        attr(l, "foo") <- "bar"
        checkEquals(listof_attr_foo(l), "bar")
    }

}