OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace-rocks commits / 4363864

Add unit test for the fix in previous commit
this test was written by Claude. It looks OK to me, I guess it's correct. But there's no way we'll ever know, until the heat-death of the universe, amirite?
436386449815d91f29eec41a2c470b20dd0d0c5d
by Linas Vepstas <linasvepstas@gmail.com> · 2026-01-20T19:58:39.000Z

Changed files (1) +59 -0

tests/persist/rocks/AlphaEquivUTest.cxxtest +59 -0
……@@ -68,6 +68,7 @@ class AlphaEquivUTest : public CxxTest::TestSuite
6868
6969 void setup_data(void);
7070 void test_fetch(void);
71 void test_bulk_load(void);
7172 void test_remove(void);
7273 void test_recursive_remove(void);
7374};
……@@ -190,6 +191,64 @@ void AlphaEquivUTest::test_fetch(void)
190191
191192// ============================================================
192193
194// Test bulk loading of alpha-convertible atoms via load_atomspace().
195// This is a regression test for a bug where the h@hash prefix stored
196// with alpha-convertible atoms was not stripped during bulk load,
197// causing parse errors. Individual fetch_atom() worked correctly
198// because getAtom() handled the prefix, but loadAtoms() did not.
199void AlphaEquivUTest::test_bulk_load(void)
200{
201 logger().info("BEGIN TEST: %s", __FUNCTION__);
202
203 setup_data();
204
205 _as = createAtomSpace();
206 Handle hsn = _as->add_node(ROCKS_STORAGE_NODE, std::string(uri));
207 StorageNodePtr store = StorageNodeCast(hsn);
208 store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue());
209 TS_ASSERT(store->connected())
210
211 // Bulk load the entire AtomSpace (this was failing before the fix)
212 store->load_atomspace();
213 store->barrier();
214
215 // Find the alpha-equivalent lambda link that was loaded
216 Handle ly = al(LAMBDA_LINK, an(VARIABLE, "Y"), an(CONCEPT, "A"));
217
218 // Verify that the correct TV was loaded
219 ValuePtr tvp = ly->getValue(truth_key());
220 TSM_ASSERT("Expecting non-null TV after bulk load", tvp != nullptr);
221
222 if (tvp)
223 {
224 printf("Got TV: %s\n", tvp->to_string().c_str());
225 FloatValuePtr fv = FloatValueCast(tvp);
226 TSM_ASSERT("Expecting (stv 0.11 100)",
227 0.1 < fv->value()[0] and fv->value()[0] < 0.12 and
228 99 < fv->value()[1] and fv->value()[1] < 101);
229 }
230
231 // Verify that other values are there too
232 ValuePtr fu = ly->getValue(an(PREDICATE, "foo"));
233 TSM_ASSERT("Expecting non-null value after bulk load", fu != nullptr);
234
235 if (fu)
236 {
237 printf("Got Value: %s\n", fu->to_string().c_str());
238 TSM_ASSERT("Expecting a FloatValue",
239 nameserver().isA(fu->get_type(), FLOAT_VALUE));
240
241 FloatValuePtr fvp = FloatValueCast(fu);
242 TSM_ASSERT_EQUALS("Expecting three floats", fvp->size(), 3);
243 }
244
245 _as = nullptr;
246
247 logger().info("END TEST: %s", __FUNCTION__);
248}
249
250// ============================================================
251
193252// Test removal by an alpha-equivalent name
194253void AlphaEquivUTest::test_remove(void)
195254{