@@ -2363,4 +2363,103 @@ TEST(Group_ArrayCompression_Correctness)
2363
2363
#endif
2364
2364
}
2365
2365
2366
+ TEST (Group_ArrayCompression_Correctness_Negative)
2367
+ {
2368
+ GROUP_TEST_PATH (path);
2369
+
2370
+ // Create group with one list<int> which maps to array_integer
2371
+ Group to_disk;
2372
+ TableRef table = to_disk.add_table (" test" );
2373
+ auto col_key = table->add_column_list (type_Int, " lint" );
2374
+ auto obj = table->create_object ();
2375
+ auto array = obj.get_list <int64_t >(col_key);
2376
+
2377
+ array.add (-1 );
2378
+ array.add (-1 );
2379
+ array.add (-1 );
2380
+ array.add (-1 );
2381
+ array.add (std::numeric_limits<int64_t >::max ());
2382
+ array.add (std::numeric_limits<int64_t >::max ());
2383
+
2384
+ CHECK_EQUAL (array.size (), 6 );
2385
+ CHECK_EQUAL (array.get_any (0 ).get_int (), -1 );
2386
+ CHECK_EQUAL (array.get_any (1 ).get_int (), -1 );
2387
+ CHECK_EQUAL (array.get_any (2 ).get_int (), -1 );
2388
+ CHECK_EQUAL (array.get_any (3 ).get_int (), -1 );
2389
+ CHECK_EQUAL (array.get_any (4 ).get_int (), std::numeric_limits<int64_t >::max ());
2390
+ CHECK_EQUAL (array.get_any (5 ).get_int (), std::numeric_limits<int64_t >::max ());
2391
+
2392
+ // Serialize to disk (compression should happen when the proper leaf array is serialized to disk)
2393
+ to_disk.write (path, crypt_key ());
2394
+
2395
+ #ifdef REALM_DEBUG
2396
+ to_disk.verify ();
2397
+ #endif
2398
+
2399
+ // Load the tables
2400
+ Group from_disk (path, crypt_key ());
2401
+ TableRef read_table = from_disk.get_table (" test" );
2402
+ auto col_key1 = read_table->get_column_key (" lint" );
2403
+ auto obj1 = read_table->get_object (0 );
2404
+ auto l1 = obj1.get_list <int64_t >(col_key1);
2405
+ CHECK (l1.size () == array.size ());
2406
+ CHECK (*read_table == *table);
2407
+ for (size_t i = 0 ; i < l1.size (); ++i) {
2408
+ CHECK_EQUAL (l1.get_any (i), array.get_any (i));
2409
+ }
2410
+
2411
+ #ifdef REALM_DEBUG
2412
+ from_disk.verify ();
2413
+ #endif
2414
+ }
2415
+
2416
+ TEST (Group_ArrayCompression_Correctness_Random_Input)
2417
+ {
2418
+ GROUP_TEST_PATH (path);
2419
+
2420
+ // Create group with one list<int> which maps to array_integer
2421
+ Group to_disk;
2422
+ TableRef table = to_disk.add_table (" test" );
2423
+ auto col_key = table->add_column_list (type_Int, " lint" );
2424
+ auto obj = table->create_object ();
2425
+ auto array = obj.get_list <int64_t >(col_key);
2426
+
2427
+ std::random_device dev;
2428
+ std::mt19937 rng (dev ());
2429
+ constexpr auto min = std::numeric_limits<int64_t >::min ();
2430
+ constexpr auto max = std::numeric_limits<int64_t >::max ();
2431
+ std::uniform_int_distribution<std::mt19937::result_type> dist6 (static_cast <unsigned int >(min),
2432
+ static_cast <unsigned int >(max));
2433
+ for (size_t i = 0 ; i < 1000 ; ++i) {
2434
+ const auto v = dist6 (rng);
2435
+ array.add (v);
2436
+ const auto stored_v = array.get_any (i).get_int ();
2437
+ CHECK_EQUAL (stored_v, v);
2438
+ }
2439
+
2440
+ // Serialize to disk (compression should happen when the proper leaf array is serialized to disk)
2441
+ to_disk.write (path, crypt_key ());
2442
+
2443
+ #ifdef REALM_DEBUG
2444
+ to_disk.verify ();
2445
+ #endif
2446
+
2447
+ // Load the tables
2448
+ Group from_disk (path, crypt_key ());
2449
+ TableRef read_table = from_disk.get_table (" test" );
2450
+ auto col_key1 = read_table->get_column_key (" lint" );
2451
+ auto obj1 = read_table->get_object (0 );
2452
+ auto l1 = obj1.get_list <int64_t >(col_key1);
2453
+ CHECK (l1.size () == array.size ());
2454
+ CHECK (*read_table == *table);
2455
+ for (size_t i = 0 ; i < l1.size (); ++i) {
2456
+ CHECK_EQUAL (l1.get_any (i), array.get_any (i));
2457
+ }
2458
+
2459
+ #ifdef REALM_DEBUG
2460
+ from_disk.verify ();
2461
+ #endif
2462
+ }
2463
+
2464
+
2366
2465
#endif // TEST_GROUP
0 commit comments