| … | … | @@ -68,6 +68,7 @@ class AlphaEquivUTest : public CxxTest::TestSuite |
| 68 | 68 | |
| 69 | 69 | void setup_data(void); |
| 70 | 70 | void test_fetch(void); |
| 71 | void test_bulk_load(void); |
| 71 | 72 | void test_remove(void); |
| 72 | 73 | void test_recursive_remove(void); |
| 73 | 74 | }; |
| … | … | @@ -190,6 +191,64 @@ void AlphaEquivUTest::test_fetch(void) |
| 190 | 191 | |
| 191 | 192 | // ============================================================ |
| 192 | 193 | |
| 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. |
| 199 | void 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 | |
| 193 | 252 | // Test removal by an alpha-equivalent name |
| 194 | 253 | void AlphaEquivUTest::test_remove(void) |
| 195 | 254 | { |