|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Comprehensive test suite for Sparse Table implementation. More...
#include <cstdio>#include <iostream>#include <iomanip>#include <chrono>#include <cassert>#include <cmath>#include <string>#include <sstream>#include <random>#include <numeric>#include <climits>#include <cfloat>#include <functional>#include <algorithm>#include <vector>#include <tpl_sparse_table.H>#include <tpl_array.H>#include <tpl_dynList.H>Go to the source code of this file.
Classes | |
| class | Timer |
| struct | Gcd_Op |
| struct | And_Op |
| struct | Or_Op |
Macros | |
| #define | TEST(name) |
| #define | PASS() |
| #define | FAIL(msg) |
| #define | CHECK(cond, msg) |
| #define | CHECK_EQ(a, b, msg) |
| #define | CHECK_THROWS(ExType, expr, msg) |
Variables | |
| static int | tests_passed = 0 |
| static int | tests_failed = 0 |
| static int | total_tests = 0 |
| static mt19937 | rng |
Comprehensive test suite for Sparse Table implementation.
Tests Gen_Sparse_Table, Sparse_Table (min), and Max_Sparse_Table (max) against brute-force baselines with random and adversarial inputs.
COMPILE: g++ -std=c++20 -O2 -I.. -o sparse_table_test sparse_table_test.cc
RUN: ./sparse_table_test [seed]
If seed is omitted, a random seed based on time is used.
Definition in file sparse_table_test.cc.
| #define CHECK | ( | cond, | |
| msg | |||
| ) |
Definition at line 108 of file sparse_table_test.cc.
| #define CHECK_EQ | ( | a, | |
| b, | |||
| msg | |||
| ) |
| #define CHECK_THROWS | ( | ExType, | |
| expr, | |||
| msg | |||
| ) |
| #define FAIL | ( | msg | ) |
Definition at line 102 of file sparse_table_test.cc.
| #define PASS | ( | ) |
Definition at line 96 of file sparse_table_test.cc.
| #define TEST | ( | name | ) |
Definition at line 90 of file sparse_table_test.cc.
| int brute_and | ( | const vector< int > & | v, |
| size_t | l, | ||
| size_t | r | ||
| ) |
Definition at line 175 of file sparse_table_test.cc.
References l.
Referenced by test_bitwise_and_stress().
| int brute_gcd | ( | const vector< int > & | v, |
| size_t | l, | ||
| size_t | r | ||
| ) |
Definition at line 167 of file sparse_table_test.cc.
References l, and Aleph::maps().
Referenced by test_gcd_stress().
Definition at line 159 of file sparse_table_test.cc.
Referenced by test_double_stress(), test_stress_all_pairs_small(), and test_stress_max_small().
Definition at line 150 of file sparse_table_test.cc.
Referenced by test_adversarial_zigzag(), test_double_stress(), test_sliding_window(), test_stress_all_pairs_small(), test_stress_min_medium(), and test_stress_min_small().
| int brute_or | ( | const vector< int > & | v, |
| size_t | l, | ||
| size_t | r | ||
| ) |
Definition at line 183 of file sparse_table_test.cc.
References l.
Referenced by test_bitwise_or_stress().
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 1238 of file sparse_table_test.cc.
References Aleph::maps(), rng, test_adversarial_plateau_with_dip(), test_adversarial_single_outlier(), test_adversarial_zigzag(), test_all_constructors_agree(), test_all_equal(), test_bitwise_and_stress(), test_bitwise_or_stress(), test_boundary_queries_valid(), test_construct_from_array(), test_construct_from_dynlist(), test_construct_from_initlist(), test_construct_from_vector(), test_construct_uniform_value(), test_copy_assignment(), test_copy_constructor(), test_disjoint_split_min(), test_double_stress(), test_double_values(), test_empty_table(), test_gcd_known(), test_gcd_stress(), test_get_all_elements(), test_get_equals_point_query(), test_get_out_of_range(), test_idempotent_overlap_split(), test_int_extremes(), test_known_max_array(), test_known_min_array(), test_long_long_values(), test_move_assignment(), test_move_constructor(), test_negative_values(), test_non_power_of_two_sizes(), test_num_levels_correctness(), test_overlapping_ranges_idempotent(), test_performance_build(), test_performance_build_large(), test_performance_queries(), test_power_of_two_sizes(), test_query_l_greater_than_r(), test_query_r_out_of_range(), test_self_copy_assignment(), test_self_swap(), test_single_element(), test_single_element_max(), test_sliding_window(), test_sorted_ascending(), test_sorted_descending(), test_stress_all_pairs_small(), test_stress_all_point_queries(), test_stress_max_small(), test_stress_min_medium(), test_stress_min_small(), test_swap(), test_two_elements(), test_values_reconstruction(), tests_failed, tests_passed, and total_tests.
| void test_adversarial_plateau_with_dip | ( | ) |
Definition at line 1198 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::maps(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_adversarial_single_outlier | ( | ) |
Definition at line 1178 of file sparse_table_test.cc.
References CHECK_EQ, l, Aleph::maps(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_adversarial_zigzag | ( | ) |
Definition at line 1162 of file sparse_table_test.cc.
References brute_min(), CHECK_EQ, l, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_all_constructors_agree | ( | ) |
Definition at line 714 of file sparse_table_test.cc.
References Aleph::Array< T >::append(), Aleph::DynList< T >::append(), CHECK_EQ, Aleph::maps(), PASS, rng, Aleph::HTList::size(), Aleph::swap(), and TEST.
Referenced by main().
| void test_all_equal | ( | ) |
Definition at line 246 of file sparse_table_test.cc.
References CHECK_EQ, l, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_bitwise_and_stress | ( | ) |
Definition at line 598 of file sparse_table_test.cc.
References brute_and(), FAIL, Aleph::maps(), N, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, Aleph::swap(), and TEST.
Referenced by main().
| void test_bitwise_or_stress | ( | ) |
Definition at line 629 of file sparse_table_test.cc.
References brute_or(), FAIL, Aleph::maps(), N, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, Aleph::swap(), and TEST.
Referenced by main().
| void test_boundary_queries_valid | ( | ) |
Definition at line 845 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::Gen_Sparse_Table< T, Op >::get(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_construct_from_array | ( | ) |
Definition at line 664 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::Gen_Sparse_Table< T, Op >::get(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), Aleph::Gen_Sparse_Table< T, Op >::size(), and TEST.
Referenced by main().
| void test_construct_from_dynlist | ( | ) |
Definition at line 685 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::maps(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), Aleph::Gen_Sparse_Table< T, Op >::size(), and TEST.
Referenced by main().
| void test_construct_from_initlist | ( | ) |
Definition at line 695 of file sparse_table_test.cc.
References CHECK_EQ, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), Aleph::Gen_Sparse_Table< T, Op >::size(), and TEST.
Referenced by main().
| void test_construct_from_vector | ( | ) |
Definition at line 675 of file sparse_table_test.cc.
References CHECK_EQ, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), Aleph::Gen_Sparse_Table< T, Op >::size(), and TEST.
Referenced by main().
| void test_construct_uniform_value | ( | ) |
Definition at line 704 of file sparse_table_test.cc.
References CHECK_EQ, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), Aleph::Gen_Sparse_Table< T, Op >::size(), and TEST.
Referenced by main().
| void test_copy_assignment | ( | ) |
Definition at line 774 of file sparse_table_test.cc.
References CHECK_EQ, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), Aleph::Gen_Sparse_Table< T, Op >::size(), and TEST.
Referenced by main().
| void test_copy_constructor | ( | ) |
Definition at line 749 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::copy(), Aleph::maps(), PASS, Aleph::HTList::size(), and TEST.
Referenced by main().
| void test_disjoint_split_min | ( | ) |
Definition at line 1141 of file sparse_table_test.cc.
References CHECK_EQ, l, Aleph::maps(), min(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, and TEST.
Referenced by main().
| void test_double_stress | ( | ) |
Definition at line 899 of file sparse_table_test.cc.
References brute_max(), brute_min(), FAIL, Aleph::maps(), N, PASS, rng, Aleph::swap(), and TEST.
Referenced by main().
| void test_double_values | ( | ) |
Definition at line 887 of file sparse_table_test.cc.
References CHECK, Aleph::maps(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_empty_table | ( | ) |
Definition at line 195 of file sparse_table_test.cc.
References CHECK, CHECK_EQ, CHECK_THROWS, PASS, and TEST.
Referenced by main().
| void test_gcd_known | ( | ) |
Definition at line 554 of file sparse_table_test.cc.
References CHECK_EQ, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_gcd_stress | ( | ) |
Definition at line 566 of file sparse_table_test.cc.
References brute_gcd(), FAIL, Aleph::maps(), N, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, Aleph::swap(), and TEST.
Referenced by main().
| void test_get_all_elements | ( | ) |
Definition at line 354 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::Gen_Sparse_Table< T, Op >::get(), PASS, and TEST.
Referenced by main().
| void test_get_equals_point_query | ( | ) |
Definition at line 1107 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::Gen_Sparse_Table< T, Op >::get(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, and TEST.
Referenced by main().
| void test_get_out_of_range | ( | ) |
Definition at line 834 of file sparse_table_test.cc.
References CHECK_THROWS, Aleph::Gen_Sparse_Table< T, Op >::get(), PASS, and TEST.
Referenced by main().
| void test_idempotent_overlap_split | ( | ) |
Definition at line 1119 of file sparse_table_test.cc.
References CHECK_EQ, l, Aleph::maps(), min(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, and TEST.
Referenced by main().
| void test_int_extremes | ( | ) |
Definition at line 874 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::maps(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_known_max_array | ( | ) |
Definition at line 340 of file sparse_table_test.cc.
References CHECK_EQ, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_known_min_array | ( | ) |
Definition at line 321 of file sparse_table_test.cc.
References CHECK_EQ, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_long_long_values | ( | ) |
Definition at line 931 of file sparse_table_test.cc.
References CHECK_EQ, LL, Aleph::maps(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_move_assignment | ( | ) |
Definition at line 786 of file sparse_table_test.cc.
References CHECK_EQ, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), Aleph::Gen_Sparse_Table< T, Op >::size(), and TEST.
Referenced by main().
| void test_move_constructor | ( | ) |
Definition at line 762 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::maps(), PASS, Aleph::HTList::size(), and TEST.
Referenced by main().
| void test_negative_values | ( | ) |
Definition at line 863 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::maps(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_non_power_of_two_sizes | ( | ) |
Definition at line 301 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::maps(), Aleph::min_element(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, Aleph::Gen_Sparse_Table< T, Op >::size(), and TEST.
Referenced by main().
| void test_num_levels_correctness | ( | ) |
Definition at line 1054 of file sparse_table_test.cc.
References FAIL, Aleph::maps(), Aleph::Gen_Sparse_Table< T, Op >::num_levels(), PASS, and TEST.
Referenced by main().
| void test_overlapping_ranges_idempotent | ( | ) |
Definition at line 1026 of file sparse_table_test.cc.
References CHECK_EQ, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_performance_build | ( | ) |
Definition at line 950 of file sparse_table_test.cc.
References CHECK, CHECK_EQ, Aleph::maps(), N, PASS, rng, Aleph::Gen_Sparse_Table< T, Op >::size(), and TEST.
Referenced by main().
| void test_performance_build_large | ( | ) |
Definition at line 998 of file sparse_table_test.cc.
References CHECK, CHECK_EQ, Aleph::maps(), Aleph::min_element(), N, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, Aleph::Gen_Sparse_Table< T, Op >::size(), and TEST.
Referenced by main().
| void test_performance_queries | ( | ) |
Definition at line 968 of file sparse_table_test.cc.
References CHECK, Aleph::maps(), N, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, Aleph::swap(), and TEST.
Referenced by main().
| void test_power_of_two_sizes | ( | ) |
Definition at line 285 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::maps(), Aleph::min_element(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, Aleph::Gen_Sparse_Table< T, Op >::size(), and TEST.
Referenced by main().
| void test_query_l_greater_than_r | ( | ) |
Definition at line 825 of file sparse_table_test.cc.
References CHECK_THROWS, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_query_r_out_of_range | ( | ) |
Definition at line 814 of file sparse_table_test.cc.
References CHECK_THROWS, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_self_copy_assignment | ( | ) |
Definition at line 1078 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::Gen_Sparse_Table< T, Op >::get(), Aleph::maps(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), Aleph::Gen_Sparse_Table< T, Op >::size(), and TEST.
Referenced by main().
| void test_self_swap | ( | ) |
Definition at line 1095 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::maps(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), Aleph::Gen_Sparse_Table< T, Op >::size(), Aleph::Gen_Sparse_Table< T, Op >::swap(), and TEST.
Referenced by main().
| void test_single_element | ( | ) |
Definition at line 212 of file sparse_table_test.cc.
References CHECK, CHECK_EQ, Aleph::Gen_Sparse_Table< T, Op >::get(), Aleph::Gen_Sparse_Table< T, Op >::is_empty(), Aleph::Gen_Sparse_Table< T, Op >::num_levels(), PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), Aleph::Gen_Sparse_Table< T, Op >::size(), and TEST.
Referenced by main().
| void test_single_element_max | ( | ) |
Definition at line 224 of file sparse_table_test.cc.
References CHECK_EQ, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), and TEST.
Referenced by main().
| void test_sliding_window | ( | ) |
Definition at line 1219 of file sparse_table_test.cc.
References brute_min(), CHECK_EQ, l, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, TEST, and w.
Referenced by main().
| void test_sorted_ascending | ( | ) |
Definition at line 257 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::maps(), PASS, and TEST.
Referenced by main().
| void test_sorted_descending | ( | ) |
Definition at line 271 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::maps(), PASS, and TEST.
Referenced by main().
| void test_stress_all_pairs_small | ( | ) |
Definition at line 490 of file sparse_table_test.cc.
References brute_max(), brute_min(), FAIL, l, Aleph::maps(), N, PASS, rng, and TEST.
Referenced by main().
| void test_stress_all_point_queries | ( | ) |
Definition at line 473 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::Gen_Sparse_Table< T, Op >::get(), N, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, and TEST.
Referenced by main().
| void test_stress_max_small | ( | ) |
Definition at line 411 of file sparse_table_test.cc.
References brute_max(), FAIL, Aleph::maps(), N, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, Aleph::swap(), and TEST.
Referenced by main().
| void test_stress_min_medium | ( | ) |
Definition at line 442 of file sparse_table_test.cc.
References brute_min(), FAIL, Aleph::maps(), N, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, Aleph::swap(), and TEST.
Referenced by main().
| void test_stress_min_small | ( | ) |
Definition at line 380 of file sparse_table_test.cc.
References brute_min(), FAIL, Aleph::maps(), N, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), rng, Aleph::swap(), and TEST.
Referenced by main().
| void test_swap | ( | ) |
Definition at line 797 of file sparse_table_test.cc.
References CHECK_EQ, PASS, Aleph::Gen_Sparse_Table< T, Op >::query(), Aleph::Gen_Sparse_Table< T, Op >::size(), Aleph::Gen_Sparse_Table< T, Op >::swap(), and TEST.
Referenced by main().
| void test_two_elements | ( | ) |
Definition at line 232 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::maps(), PASS, and TEST.
Referenced by main().
| void test_values_reconstruction | ( | ) |
Definition at line 364 of file sparse_table_test.cc.
References CHECK_EQ, Aleph::maps(), PASS, Aleph::HTList::size(), TEST, and Aleph::Gen_Sparse_Table< T, Op >::values().
Referenced by main().
|
static |
Definition at line 143 of file sparse_table_test.cc.
Referenced by main(), test_all_constructors_agree(), test_bitwise_and_stress(), test_bitwise_or_stress(), test_disjoint_split_min(), test_double_stress(), test_gcd_stress(), test_get_equals_point_query(), test_idempotent_overlap_split(), test_non_power_of_two_sizes(), test_performance_build(), test_performance_build_large(), test_performance_queries(), test_power_of_two_sizes(), test_sliding_window(), test_stress_all_pairs_small(), test_stress_all_point_queries(), test_stress_max_small(), test_stress_min_medium(), and test_stress_min_small().
|
static |
Definition at line 87 of file sparse_table_test.cc.
Referenced by main().
|
static |
Definition at line 86 of file sparse_table_test.cc.
Referenced by main().
|
static |
Definition at line 88 of file sparse_table_test.cc.
Referenced by main().