| … | … | @@ -44,6 +44,7 @@ public: |
| 44 | 44 | void tearDown() {} |
| 45 | 45 | |
| 46 | 46 | void test_define_concept(); |
| 47 | void test_define_in_child_space(); |
| 47 | 48 | // void test_define_pattern(); |
| 48 | 49 | // void test_define_function(); |
| 49 | 50 | }; |
| … | … | @@ -86,3 +87,40 @@ void DefineLinkUTest::test_define_concept() |
| 86 | 87 | |
| 87 | 88 | logger().info("END TEST: %s", __FUNCTION__); |
| 88 | 89 | } |
| 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. |
| 94 | void 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 | } |