Skip to content

Commit 3568f65

Browse files
committed
Tests for r_vector.find
Fixes #18
1 parent cb1ba2e commit 3568f65

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

cpp11test/src/test-doubles.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,34 @@ context("doubles-C++") {
395395
expect_true(x.at(s0) == 1);
396396
}
397397

398+
test_that("operator[] and at with names") {
399+
using namespace cpp11::literals;
400+
cpp11::writable::doubles x({"a"_nm = 1., "b"_nm = 2.});
401+
cpp11::doubles y(x);
402+
403+
expect_true(x["a"] == 1);
404+
expect_true(x["b"] == 2);
405+
expect_error(x["c"] == 2);
406+
407+
expect_true(y["a"] == 1);
408+
expect_true(y["b"] == 2);
409+
expect_error(y["c"] == 2);
410+
}
411+
412+
test_that("doubles::find") {
413+
using namespace cpp11::literals;
414+
cpp11::writable::doubles x({"a"_nm = 1., "b"_nm = 2.});
415+
cpp11::doubles y(x);
416+
417+
expect_true(x.find("a") == x.begin());
418+
expect_true(x.find("b") == x.begin() + 1);
419+
expect_true(x.find("c") == x.end());
420+
421+
expect_true(y.find("a") == y.begin());
422+
expect_true(y.find("b") == y.begin() + 1);
423+
expect_true(y.find("c") == y.end());
424+
}
425+
398426
test_that("writable::doubles compound assignments") {
399427
cpp11::writable::doubles x(Rf_allocVector(REALSXP, 1));
400428
REAL(x)[0] = 1;

0 commit comments

Comments
 (0)