FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp11/cpp11test/src/test-function.cpp at main · josh28x/cpp11 · GitHub
josh28x
cpp11
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp11
/
cpp11test
/
src
/
test-function.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
43 lines (31 loc) · 1.18 KB
Breadcrumbs
cpp11
/
cpp11test
/
src
/
test-function.cpp
Copy path
File metadata and controls
43 lines (31 loc) · 1.18 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
cpp11/function.hpp
"
#
include
<
testthat.h
>
context
(
"
function-C++
"
) {
test_that
(
"
functions can be called
"
) {
auto
median =
cpp11::package
(
"
stats
"
)[
"
median
"
];
double
res =
median
(
cpp11::as_sexp
({
1
.,
2
.,
3
.,
NA_REAL
}),
true
);
expect_true
(res ==
2
.);
double
res2 =
median
(
cpp11::as_sexp
({
1
.,
2
.,
3
.,
NA_REAL
}),
false
);
expect_true
(
ISNAN
(res2));
}
test_that
(
"
functions can be called with named arguments
"
) {
using
namespace
cpp11
::literals
;
auto
median =
cpp11::package
(
"
stats
"
)[
"
median
"
];
double
res =
median
(
"
x
"
_nm = {
1
.,
2
.,
3
.,
NA_REAL
},
"
na.rm
"
_nm =
true
);
expect_true
(res ==
2
.);
double
res2 =
median
(
cpp11::as_sexp
({
1
.,
2
.,
3
.,
NA_REAL
}),
false
);
expect_true
(
ISNAN
(res2));
}
test_that
(
"
base functions can be called
"
) {
auto
file =
cpp11::package
(
"
base
"
)[
"
file
"
];
auto
isOpen =
cpp11::package
(
"
base
"
)[
"
isOpen
"
];
auto
close =
cpp11::package
(
"
base
"
)[
"
close
"
];
cpp11::sexp con =
file
(
"
foo
"
);
bool
res =
isOpen
(con);
expect_true
(res ==
false
);
close
(con);
}
test_that
(
"
unknown packages cause an error (#317)
"
) {
expect_error_as
(
cpp11::package
(
"
definitely_not_a_package
"
), cpp11::unwind_exception);
}
}
Back
|
FazBrowse Home
|
New Git URL