@@ -355,11 +355,6 @@ context("complexes-C++") {
355355 test_that (" comparison operator works" ) {
356356 using namespace cpp4r ;
357357
358- // SEXP base = PROTECT(Rf_allocVector(CPLXSXP, 2));
359- // SEXP same_values = PROTECT(Rf_allocVector(CPLXSXP, 2));
360- // SEXP diff_length = PROTECT(Rf_allocVector(CPLXSXP, 1));
361- // SEXP diff_values = PROTECT(Rf_allocVector(CPLXSXP, 2));
362-
363358 cpp4r::complexes base (Rf_allocVector (CPLXSXP, 2 ));
364359 cpp4r::complexes same_values (Rf_allocVector (CPLXSXP, 2 ));
365360 cpp4r::complexes diff_length (Rf_allocVector (CPLXSXP, 1 ));
@@ -385,8 +380,6 @@ context("complexes-C++") {
385380 expect_true (!(base != same_values));
386381 expect_true (base != diff_length);
387382 expect_true (base != diff_values);
388-
389- UNPROTECT (4 );
390383 }
391384
392385 test_that (" proxy comparison works symmetrically" ) {
@@ -482,16 +475,20 @@ context("complexes-C++") {
482475 auto x0 = x[0 ];
483476 expect_true (x0 == one);
484477
485- // Arithmetic is not defined on Rcomplex or r_complex,
486- // so using it on a proxy also fails and is not defined
487- // expect_error(x0 += two);
488- // expect_error(x0 -= two);
489- // expect_error(x0 *= two);
490- // expect_error(x0 /= two);
491- // expect_error(x0--);
492- // expect_error(x0++);
493- // expect_error(++x0);
494- // expect_error(--x0);
478+ // Test compound assignment operators (now implemented in proxy class)
479+ x0 += two; // (1,1) + (2,2) = (3,3)
480+ expect_true (x0 == cpp4r::r_complex (3 , 3 ));
481+
482+ x0 -= two; // (3,3) - (2,2) = (1,1)
483+ expect_true (x0 == one);
484+
485+ x0 *= two; // (1,1) * (2,2) = (1*2-1*2, 1*2+1*2) = (0,4)
486+ expect_true (x0 == cpp4r::r_complex (0 , 4 ));
487+
488+ x[0 ] = one; // Reset to (1,1)
489+ x0 = x[0 ];
490+ x0 /= two; // (1,1) / (2,2) = ((1*2+1*2) + (1*2-1*2)i)/(2²+2²) = (4,0)/8 = (0.5,0)
491+ expect_true (x0 == cpp4r::r_complex (0.5 , 0 ));
495492 }
496493
497494 test_that (" writable::complexes convert to complexes with correct size" ) {
0 commit comments