@@ -745,3 +745,34 @@ TEST(BlackboardTest, SetBlackboard_WithPortRemapping)
745745 // Tick till the end with no crashes
746746 ASSERT_NO_THROW (tree.tickWhileRunning (););
747747}
748+
749+ // Issue #974: blackboard->set(key, "42") stores a string.
750+ // When two string-valued blackboard entries are compared in a script,
751+ // numeric comparison should be used if both strings are parseable as numbers.
752+ // "9" < "10" is false lexicographically but true numerically.
753+ TEST (BlackboardTest, StringSetNumericScriptComparison_Issue974)
754+ {
755+ auto bb = Blackboard::create ();
756+ bb->set (" a" , std::string (" 9" ));
757+ bb->set (" b" , std::string (" 10" ));
758+
759+ BehaviorTreeFactory factory;
760+
761+ std::string xml_txt = R"(
762+ <root BTCPP_format="4" >
763+ <BehaviorTree ID="Main">
764+ <Sequence>
765+ <Script code=" result := false "/>
766+ <Script code=" result := (a < b) "/>
767+ <AlwaysSuccess _successIf="result"/>
768+ </Sequence>
769+ </BehaviorTree>
770+ </root>)" ;
771+
772+ auto tree = factory.createTreeFromText (xml_txt, bb);
773+ auto status = tree.tickWhileRunning ();
774+
775+ ASSERT_EQ (status, NodeStatus::SUCCESS);
776+ // 9 < 10 is true numerically, even though "9" > "10" lexicographically
777+ ASSERT_TRUE (bb->get <bool >(" result" ));
778+ }
0 commit comments