/** @file DPrimitive.test.cpp * * @author Roland Conybeare, Jan 2026 **/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace xo { using xo::scm::Primitives; using xo::scm::DSimpleRcx; using xo::scm::ARuntimeContext; using xo::scm::DFloat; using xo::scm::DInteger; using xo::scm::DArray; using xo::scm::DPrimitive_gco_2_gco_gco; using xo::mm::AAllocator; using xo::mm::AGCObject; using xo::mm::DArena; using xo::mm::ArenaConfig; using xo::print::APrintable; using xo::print::ppstate_standalone; using xo::print::ppconfig; using xo::facet::with_facet; using xo::facet::obj; using xo::scope; namespace ut { static InitEvidence s_init = InitSubsys::require(); TEST_CASE("DPrimitive-init", "[procedure2][DPrimitive]") { REQUIRE(s_init.evidence()); } // MOVE THESE TO xo-numeric/ // Should work using NumericPrimitives::s_mul_gco_gco #ifdef OBSOLETE TEST_CASE("DPrimitive-n_args", "[procedure2][DPrimitive]") { // s_mul_gco_gco_pm takes 2 AGCObject args REQUIRE(Primitives::s_mul_gco_gco_pm.n_args() == 2); } TEST_CASE("DPrimitive-is_nary", "[procedure2][DPrimitive]") { REQUIRE(Primitives::s_mul_gco_gco_pm.is_nary() == false); } TEST_CASE("DPrimitive-apply_nocheck-float-float", "[procedure2][DPrimitive]") { ArenaConfig cfg { .name_ = "testarena", .size_ = 4*1024 }; DArena arena = DArena::map(cfg); auto alloc = with_facet::mkobj(&arena); DSimpleRcx rcx_data(alloc); obj rcx = with_facet::mkobj(&rcx_data); // 3.0 * 7.0 = 21.0 obj x = DFloat::box(alloc, 3.0); obj y = DFloat::box(alloc, 7.0); DArray * args = DArray::array(alloc, x, y); obj result = Primitives::s_mul_gco_gco_pm.apply_nocheck(rcx, args); auto result_float = obj::from(result); REQUIRE(result_float); REQUIRE(result_float.data()->value() == 21.0); } TEST_CASE("DPrimitive-apply_nocheck-int-int", "[procedure2][DPrimitive]") { ArenaConfig cfg { .name_ = "testarena", .size_ = 4*1024 }; DArena arena = DArena::map(cfg); auto alloc = with_facet::mkobj(&arena); DSimpleRcx rcx_data(alloc); obj rcx = with_facet::mkobj(&rcx_data); // 3 * 7 = 21 obj x = DInteger::box(alloc, 3L); obj y = DInteger::box(alloc, 7L); DArray * args = DArray::array(alloc, x, y); obj result = Primitives::s_mul_gco_gco_pm.apply_nocheck(rcx, args); auto result_int = obj::from(result); REQUIRE(result_int); REQUIRE(result_int.data()->value() == 21L); } TEST_CASE("DPrimitive-apply_nocheck-int-float", "[procedure2][DPrimitive]") { ArenaConfig cfg { .name_ = "testarena", .size_ = 4*1024 }; DArena arena = DArena::map(cfg); auto alloc = with_facet::mkobj(&arena); DSimpleRcx rcx_data(alloc); obj rcx = with_facet::mkobj(&rcx_data); // 3 * 7.0 = 21.0 (mixed: result is float) obj x = DInteger::box(alloc, 3L); obj y = DFloat::box(alloc, 7.0); DArray * args = DArray::array(alloc, x, y); obj result = Primitives::s_mul_gco_gco_pm.apply_nocheck(rcx, args); auto result_float = obj::from(result); REQUIRE(result_float); REQUIRE(result_float.data()->value() == 21.0); } TEST_CASE("DPrimitive-pretty", "[procedure2][DPrimitive][pp]") { scope log(XO_DEBUG(false)); std::stringstream ss; ppconfig ppc; ppstate_standalone pps(&ss, 0, &ppc); obj prim_pr(&Primitives::s_mul_gco_gco_pm); pps.pretty(prim_pr); std::string output = ss.str(); log && log(output); CHECK(output.find("_mul") != std::string::npos); } #endif } /*namespace ut*/ } /*namespace xo*/ /* end DPrimitive.test.cpp */