1+ #include " cpp11/complexes.hpp"
12#include " cpp11/doubles.hpp"
23#include " cpp11/function.hpp"
34#include " cpp11/integers.hpp"
@@ -24,6 +25,7 @@ context("matrix-C++") {
2425 expect_true (x[1 ].size () == 2 );
2526 expect_true (x[1 ].stride () == 5 );
2627 }
28+
2729 test_that (" matrix dim attributes are correct for read only matrices" ) {
2830 auto getExportedValue = cpp11::package (" base" )[" getExportedValue" ];
2931
@@ -41,6 +43,7 @@ context("matrix-C++") {
4143 expect_true (x[1 ].size () == 61 );
4244 expect_true (x[1 ].stride () == 87 );
4345 }
46+
4447 test_that (" matrix<by_column> attributes are correct" ) {
4548 cpp11::doubles_matrix<cpp11::by_column> x (getExportedValue (" datasets" , " volcano" ));
4649
@@ -156,4 +159,40 @@ context("matrix-C++") {
156159 cpp11::writable::doubles_matrix<cpp11::by_row> x (5 , 2 );
157160 expect_error (cpp11::writable::integers_matrix<cpp11::by_column>(x));
158161 }
162+
163+ test_that (" complex objects can be created, filled, and copied" ) {
164+ // vector
165+
166+ cpp11::writable::complexes v (2 );
167+ v[0 ] = std::complex <double >(1 , 2 );
168+ v[1 ] = std::complex <double >(3 , 4 );
169+
170+ cpp11::complexes vc = v;
171+
172+ expect_true (v.size () == vc.size ());
173+
174+ for (int i = 0 ; i < 2 ; ++i) {
175+ expect_true (v[i] == vc[i]);
176+ }
177+
178+ // matrix
179+
180+ cpp11::writable::complexes_matrix<cpp11::by_row> m (5 , 2 );
181+
182+ for (int i = 0 ; i < 5 ; ++i) {
183+ for (int j = 0 ; j < 2 ; ++j) {
184+ m (i, j) = std::complex <double >(i, j);
185+ }
186+ }
187+
188+ cpp11::complexes_matrix<> mc = m;
189+ expect_true (m.nrow () == mc.nrow ());
190+ expect_true (m.ncol () == mc.ncol ());
191+
192+ for (int i = 0 ; i < 5 ; ++i) {
193+ for (int j = 0 ; j < 2 ; ++j) {
194+ expect_true (m (i, j) == mc (i, j));
195+ }
196+ }
197+ }
159198}
0 commit comments