OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace commits / 2a3a080

Extend unit test to verify defines in stack work
2a3a080acf81a1f53dfdc33a2cf9e0d612f64f2d
by Linas Vepštas <linasvepstas@gmail.com> · 2026-01-22T03:29:26.000Z

Changed files (1) +38 -0

tests/atoms/grant/DefineLinkUTest.cxxtest +38 -0
……@@ -44,6 +44,7 @@ public:
4444 void tearDown() {}
4545
4646 void test_define_concept();
47 void test_define_in_child_space();
4748 // void test_define_pattern();
4849 // void test_define_function();
4950};
……@@ -86,3 +87,40 @@ void DefineLinkUTest::test_define_concept()
8687
8788 logger().info("END TEST: %s", __FUNCTION__);
8889}
90
91// Test that DefineLink lookup works when the alias is localized
92// (copied) to a child AtomSpace. This tests the AtomSpace::depth()
93// function which must correctly find atoms in parent spaces.
94void DefineLinkUTest::test_define_in_child_space()
95{
96 logger().info("BEGIN TEST: %s", __FUNCTION__);
97
98 // Create a parent AtomSpace with a definition
99 AtomSpacePtr parent = createAtomSpace();
100 Handle body = parent->add_node(CONCEPT_NODE, "the-body");
101 Handle alias = parent->add_node(DEFINED_SCHEMA_NODE, "the-alias");
102 parent->add_link(DEFINE_LINK, alias, body);
103
104 // Verify lookup works in parent
105 Handle got = DefineLink::get_definition(alias, parent.get());
106 TS_ASSERT_EQUALS(body, got);
107
108 // Create a child AtomSpace
109 AtomSpacePtr child = createAtomSpace(parent);
110
111 // Localize (copy) the alias to the child space
112 Handle local_alias = child->localize(alias);
113 TS_ASSERT(local_alias != nullptr);
114 TS_ASSERT(local_alias->getAtomSpace() == child.get());
115
116 // Verify depth calculation: alias in parent should be at depth 1
117 int depth = child->depth(alias);
118 TS_ASSERT_EQUALS(1, depth);
119
120 // The key test: lookup should still work from the child space,
121 // even though the DefineLink is in the parent (depth 1).
122 got = DefineLink::get_definition(local_alias, child.get());
123 TS_ASSERT_EQUALS(body, got);
124
125 logger().info("END TEST: %s", __FUNCTION__);
126}