forked from r-lib/cpp11
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-list_of.cpp
More file actions
50 lines (35 loc) · 1.36 KB
/
test-list_of.cpp
File metadata and controls
50 lines (35 loc) · 1.36 KB
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
#include "cpp11/doubles.hpp"
#include "cpp11/list.hpp"
#include "cpp11/list_of.hpp"
#include "cpp11/strings.hpp"
#include <testthat.h>
context("list_of-C++") {
test_that("list_of works") {
using namespace cpp11::literals;
cpp11::writable::list x({"x"_nm = cpp11::writable::doubles({1., 2., 3.}),
"y"_nm = cpp11::writable::doubles({4., 5., 6.})});
cpp11::list_of<cpp11::doubles> res(x);
expect_true(res.size() == 2);
expect_true(res[0][0] == 1.);
expect_true(res[1][0] == 4.);
expect_true(res.
4B29
names()[0] == "x");
expect_true(res.names()[1] == "y");
}
test_that("writable::list_of works") {
using namespace cpp11::literals;
cpp11::writable::list x({"x"_nm = cpp11::writable::doubles({1., 2., 3.}),
"y"_nm = cpp11::writable::doubles({4., 5., 6.})});
cpp11::writable::list_of<cpp11::writable::doubles> res(x);
res.push_back({"z"_nm = cpp11::writable::doubles({7., 8., 9.})});
expect_true(res.size() == 3);
expect_true(REAL(VECTOR_ELT(res, 2))[0] == 7.);
res[0][0] = 2.;
expect_true(REAL(VECTOR_ELT(res, 0))[0] == 2.);
res[1] = cpp11::writable::doubles({7., 8., 9.});
expect_true(REAL(res[1])[0] == 7.);
expect_true(REAL(res[1])[1] == 8.);
expect_true(REAL(res[1])[2] == 9.);
res["x"][0] = 4;
expect_true(REAL(res[0])[0] == 4.);
}
}