diff options
author | Abseil Team <absl-team@google.com> | 2020-10-27 14:08:57 -0700 |
---|---|---|
committer | vslashg <gfalcon@google.com> | 2020-10-27 17:14:47 -0400 |
commit | 962b067540f511070b7afa4cda465233b42b560a (patch) | |
tree | d2ceea66018cb6d8dab291df01b61c0d22f0755e /absl/container/btree_test.cc | |
parent | 5bf048b8425cc0a342e4647932de19e25ffd6ad7 (diff) |
Export of internal Abseil changes
--
e5b45b15c19e85aaa33430ac2bd45fcc2e52dad5 by Greg Falcon <gfalcon@google.com>:
Add extra tests exercising ShiftLeft() at boundary conditions, to guard against logic errors in our memory bounds checking.
PiperOrigin-RevId: 339326030
--
cdfde78815ca016a57f90f53d08c3335bd355f30 by Evan Brown <ezb@google.com>:
Fix a bug in b-tree erase() and count() in which we weren't accounting for cases where the comparator is heterogeneous and has different equivalence classes for different lookup types.
Optimize equal_range to avoid comparisons when possible.
PiperOrigin-RevId: 339270230
--
b4aa337c156fa91f74f25c676c679ae146311968 by Derek Mauro <dmauro@google.com>:
Fix execution of the cmake build scripts when not on Kokoro
PiperOrigin-RevId: 339131253
--
fa3d1f602f711be72fde6b5f29d6341b9b5f8a2c by Derek Mauro <dmauro@google.com>:
Update Docker container used for Alpine Linux testing
PiperOrigin-RevId: 339074246
GitOrigin-RevId: e5b45b15c19e85aaa33430ac2bd45fcc2e52dad5
Change-Id: I2cc3adc4de3493203c8a944aedee40efa54af0c0
Diffstat (limited to 'absl/container/btree_test.cc')
-rw-r--r-- | absl/container/btree_test.cc | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/absl/container/btree_test.cc b/absl/container/btree_test.cc index 4a495067..9b1b6436 100644 --- a/absl/container/btree_test.cc +++ b/absl/container/btree_test.cc @@ -2680,6 +2680,12 @@ struct MultiKey { int i2; }; +bool operator==(const MultiKey a, const MultiKey b) { + return a.i1 == b.i1 && a.i2 == b.i2; +} + +// A heterogeneous comparator that has different equivalence classes for +// different lookup types. struct MultiKeyComp { using is_transparent = void; bool operator()(const MultiKey a, const MultiKey b) const { @@ -2690,8 +2696,6 @@ struct MultiKeyComp { bool operator()(const MultiKey a, const int b) const { return a.i1 < b; } }; -// Test that when there's a heterogeneous comparator that behaves differently -// for some heterogeneous operators, we get equal_range() right. TEST(Btree, MultiKeyEqualRange) { absl::btree_set<MultiKey, MultiKeyComp> set; @@ -2709,6 +2713,19 @@ TEST(Btree, MultiKeyEqualRange) { } } +TEST(Btree, MultiKeyErase) { + absl::btree_set<MultiKey, MultiKeyComp> set = { + {1, 1}, {2, 1}, {2, 2}, {3, 1}}; + EXPECT_EQ(set.erase(2), 2); + EXPECT_THAT(set, ElementsAre(MultiKey{1, 1}, MultiKey{3, 1})); +} + +TEST(Btree, MultiKeyCount) { + const absl::btree_set<MultiKey, MultiKeyComp> set = { + {1, 1}, {2, 1}, {2, 2}, {3, 1}}; + EXPECT_EQ(set.count(2), 2); +} + TEST(Btree, AllocConstructor) { using Alloc = CountingAllocator<int>; using Set = absl::btree_set<int, std::less<int>, Alloc>; |