@@ -57,6 +57,39 @@ template <typename index_at> struct aligned_wrapper_gt {
57
57
}
58
58
};
59
59
60
+ /* *
61
+ * Tests the functionality of the custom uint40_t type ensuring consistent
62
+ * behavior across various constructors from uint32_t, uint64_t, and size_t types.
63
+ */
64
+ void test_uint40 () {
65
+ // Constants for tests
66
+ std::uint64_t max_uint40_k = (1ULL << 40 ) - 1 ;
67
+
68
+ for (std::uint64_t original_value : {
69
+ 42ull , // Typical small number
70
+ 4242ull , // Larger number still within uint40 range
71
+ 1ull << 40 , // Exactly at the boundary of uint40
72
+ (1ull << 40 ) + 1 , // Just beyond the boundary of uint40
73
+ 1ull << 63 // Well beyond the uint40 boundary, tests masking
74
+ }) {
75
+ std::uint32_t v_32 = static_cast <std::uint32_t >(original_value);
76
+ std::uint64_t v_64 = original_value;
77
+ std::size_t v_size = static_cast <std::size_t >(original_value);
78
+
79
+ // Create uint40_t instances from different types
80
+ uint40_t n_40_from_32 (v_32);
81
+ uint40_t n_40_from_64 (v_64);
82
+ uint40_t n_40_from_size (v_size);
83
+
84
+ // Expected value after masking
85
+ std::uint64_t expected_value = original_value & max_uint40_k;
86
+
87
+ // Check if all conversions are equal to the masked value
88
+ expect (n_40_from_32 == expected_value);
89
+ expect (n_40_from_64 == expected_value);
90
+ expect (n_40_from_size == expected_value);
91
+ }
92
+ }
60
93
/* *
61
94
* Tests the behavior of various move-constructors and move-assignment operators for the index.
62
95
*
@@ -700,6 +733,7 @@ template <typename key_at, typename slot_at> void test_replacing_update() {
700
733
}
701
734
702
735
int main (int , char **) {
736
+ test_uint40 ();
703
737
704
738
// Weird corner cases
705
739
test_replacing_update<std::int64_t , std::uint32_t >();
0 commit comments