Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
throwing_compare_test.cc File Reference

The search trees let through what their comparison throws, and keep their keys. More...

#include "search_trees_test_common.H"
#include <gtest/gtest-spi.h>
#include <climits>
#include <stdexcept>
#include <string>
#include <utility>
#include <ahFunction.H>
#include <tpl_array.H>
#include <tpl_binNodeXt.H>
#include <tpl_binTreeOps.H>
#include <tpl_dynMapTree.H>
#include <tpl_dynSetTree.H>
Include dependency graph for throwing_compare_test.cc:

Go to the source code of this file.

Classes

struct  ThrowingCompareTree< Kind >
 
struct  ThrowingCompareSet< Kind >
 
struct  ThrowingCompareMap< Kind >
 

Macros

#define TREES_UNDER_TEST(X)
 
#define DECLARE_TREE_KIND(T, Restructures, Noexcept)
 
#define TREE_KIND_ENTRY(T, Restructures, Noexcept)   , T##_Kind
 

Functions

 TEST (ThrowingCompareHarness, AnExceptionThatTheOperationCatchesFailsTheTest)
 
 TYPED_TEST_SUITE (ThrowingCompareTree, Tree_Kinds, Kind_Names)
 
 TYPED_TEST (ThrowingCompareTree, IsNoexceptOnlyWithANothrowComparison)
 
 TYPED_TEST (ThrowingCompareTree, InsertionLetsTheExceptionThrough)
 
 TYPED_TEST (ThrowingCompareTree, SearchLetsTheExceptionThrough)
 
 TYPED_TEST (ThrowingCompareTree, RemovalLetsTheExceptionThrough)
 
 TYPED_TEST (ThrowingCompareTree, SplitLetsTheExceptionThrough)
 
 TYPED_TEST_SUITE (ThrowingCompareSet, Tree_Kinds, Kind_Names)
 
 TYPED_TEST (ThrowingCompareSet, LetsTheExceptionThrough)
 
 TYPED_TEST_SUITE (ThrowingCompareMap, Tree_Kinds, Kind_Names)
 
 TYPED_TEST (ThrowingCompareMap, LetsTheExceptionThrough)
 
 TEST (ThrowingCompareOperations, BinTreeOperationLeavesTheTreeAsItWas)
 
 TEST (ThrowingCompareOperations, BinTreeXtOperationLeavesTheTreeAsItWas)
 
 TEST (ThrowingCompareOperations, SplitsWithTheComparisonOfTheTree)
 
 TEST (ThrowingCompareOperations, SplayTreesKeepTheirNoexcept)
 
 TEST (ThrowingCompareOperations, TheConversionOfTheResultLetsTheExceptionThrough)
 
 TEST (ThrowingCompareOperations, TheConditionOnTheResultLetsTheExceptionThrough)
 
 TEST (ThrowingCompareOperations, AnOverloadForKeysNotConstantLetsTheExceptionThrough)
 
 TEST (ThrowingCompareOperations, TheSearchOfAMapComparesConstantKeys)
 
 TEST (ThrowingCompareOperations, TheCopyOfTheComparisonLetsTheExceptionThrough)
 
 TEST (ThrowingCompareOperations, RankedIteratorsLetTheExceptionThrough)
 
 TEST (ThrowingCompareOperations, AMapOnATreeThatGivesACopyOfItsComparison)
 
 TYPED_TEST (ThrowingCompareTree, TakesTheResultOfTheComparisonAsABool)
 

Detailed Description

The search trees let through what their comparison throws, and keep their keys.

The comparison of a tree is code of the user, and it may throw. The operations of the trees that compare are noexcept only if it cannot: a noexcept function that lets an exception out ends the program (std::terminate()), where the user expects the exception.

Here the comparison throws at its k-th call, for every k up to the number of calls that an operation makes. Every search tree of the library but the splay trees is tested alone, in a DynSetTree and in a DynMapTree: each insertion, search, removal and split must let the exception through and leave a tree that verifies, with the keys and the size that it had. The trees that do not recolor or rotate on their way down are left exactly as they were. The operations of BinTree_Operation and BinTreeXt_Operation are tested in the same way.

The splay trees keep their noexcept: a splay relinks the tree as it compares, so their comparison must not throw.

Definition in file throwing_compare_test.cc.

Macro Definition Documentation

◆ DECLARE_TREE_KIND

#define DECLARE_TREE_KIND (   T,
  Restructures,
  Noexcept 
)
Value:
struct T##_Kind \
{ \
using Nothrow_Tree = T<int>; \
template <class Cmp> using Tree_With = T<int, Cmp>; \
template <class Cmp> \
using Set_With = DynSetTree<int, T, Cmp>; \
template <class Cmp> \
using Map_With = DynMapTree<int, int, T, Cmp>; \
static constexpr bool restructures = Restructures; \
static constexpr bool noexcept_ops = Noexcept; \
static constexpr const char * name = #T; \
};
Generic key-value map implemented on top of a binary search tree.
Dynamic set backed by balanced binary search trees with automatic memory management.
QuadTree - Hierarchical spatial index for 2D points.
Definition quadtree.H:126
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:152

Definition at line 390 of file throwing_compare_test.cc.

◆ TREE_KIND_ENTRY

#define TREE_KIND_ENTRY (   T,
  Restructures,
  Noexcept 
)    , T##_Kind

Definition at line 415 of file throwing_compare_test.cc.

◆ TREES_UNDER_TEST

#define TREES_UNDER_TEST (   X)
Value:
X(BinTree, false, true) \
X(Avl_Tree, false, true) \
X(Avl_Tree_Rk, false, true) \
X(Rb_Tree, false, true) \
X(Rb_Tree_Rk, false, false) \
X(TdRbTree, true, true) \
X(TdRbTreeRk, true, true) \
X(HtdRbTree, true, true) \
X(HtdRbTreeRk, true, true) \
X(Treap, false, true) \
X(Treap_Rk, false, true) \
X(Rand_Tree, false, true)
#define X(p)
Definition btreepic.C:374
Hybrid top-down/bottom-up red-black tree with rank support.
Hybrid top-down/bottom-up red-black tree.
Definition tpl_hRbTree.H:86
Top-down red-black tree with rank (no virtual destructor).
Top-down red-black tree without virtual destructor.
Ranked AVL tree with nodes without a virtual destructor.
Definition tpl_avlRk.H:1592
AVL binary search tree with nodes without a virtual destructor.
Definition tpl_avl.H:831
Binary search tree with nodes without virtual destructors,.
Randomized binary search tree.
Red-Black binary search tree with nodes without virtual destructor and with subtree counters for sele...
Definition tpl_rbRk.H:1653
Red-black tree with nodes without virtual destructor.
Extended treap (a special type of randomized binary search tree) which manages selection and splittin...
Treap (a special type of randomized binary search tree) using nodes without virtual destructor.
Definition tpl_treap.H:797

Definition at line 374 of file throwing_compare_test.cc.

Function Documentation

◆ TEST() [1/12]

TEST ( ThrowingCompareHarness  ,
AnExceptionThatTheOperationCatchesFailsTheTest   
)

Definition at line 442 of file throwing_compare_test.cc.

◆ TEST() [2/12]

TEST ( ThrowingCompareOperations  ,
AMapOnATreeThatGivesACopyOfItsComparison   
)

◆ TEST() [3/12]

TEST ( ThrowingCompareOperations  ,
AnOverloadForKeysNotConstantLetsTheExceptionThrough   
)

Definition at line 1688 of file throwing_compare_test.cc.

References Aleph::Less.

◆ TEST() [4/12]

TEST ( ThrowingCompareOperations  ,
BinTreeOperationLeavesTheTreeAsItWas   
)

Definition at line 1018 of file throwing_compare_test.cc.

References Aleph::check_bst(), k, KEY, RLINK, and Aleph::split().

◆ TEST() [5/12]

TEST ( ThrowingCompareOperations  ,
BinTreeXtOperationLeavesTheTreeAsItWas   
)

Definition at line 1186 of file throwing_compare_test.cc.

References Aleph::check_rank_tree(), l, r, and Aleph::split().

◆ TEST() [6/12]

TEST ( ThrowingCompareOperations  ,
RankedIteratorsLetTheExceptionThrough   
)

Definition at line 1746 of file throwing_compare_test.cc.

References Aleph::has_curr().

◆ TEST() [7/12]

TEST ( ThrowingCompareOperations  ,
SplayTreesKeepTheirNoexcept   
)

Definition at line 1317 of file throwing_compare_test.cc.

◆ TEST() [8/12]

TEST ( ThrowingCompareOperations  ,
SplitsWithTheComparisonOfTheTree   
)

Definition at line 1307 of file throwing_compare_test.cc.

◆ TEST() [9/12]

TEST ( ThrowingCompareOperations  ,
TheConditionOnTheResultLetsTheExceptionThrough   
)

◆ TEST() [10/12]

◆ TEST() [11/12]

TEST ( ThrowingCompareOperations  ,
TheCopyOfTheComparisonLetsTheExceptionThrough   
)

Definition at line 1728 of file throwing_compare_test.cc.

References Aleph::search().

◆ TEST() [12/12]

TEST ( ThrowingCompareOperations  ,
TheSearchOfAMapComparesConstantKeys   
)

◆ TYPED_TEST() [1/8]

TYPED_TEST ( ThrowingCompareMap  ,
LetsTheExceptionThrough   
)

Definition at line 866 of file throwing_compare_test.cc.

References Aleph::search().

◆ TYPED_TEST() [2/8]

TYPED_TEST ( ThrowingCompareSet  ,
LetsTheExceptionThrough   
)

Definition at line 754 of file throwing_compare_test.cc.

References k, and Aleph::size().

◆ TYPED_TEST() [3/8]

TYPED_TEST ( ThrowingCompareTree  ,
InsertionLetsTheExceptionThrough   
)

Definition at line 491 of file throwing_compare_test.cc.

References KEY.

◆ TYPED_TEST() [4/8]

TYPED_TEST ( ThrowingCompareTree  ,
IsNoexceptOnlyWithANothrowComparison   
)

Definition at line 470 of file throwing_compare_test.cc.

References Aleph::remove(), and Aleph::search().

◆ TYPED_TEST() [5/8]

TYPED_TEST ( ThrowingCompareTree  ,
RemovalLetsTheExceptionThrough   
)

Definition at line 605 of file throwing_compare_test.cc.

References KEY.

◆ TYPED_TEST() [6/8]

TYPED_TEST ( ThrowingCompareTree  ,
SearchLetsTheExceptionThrough   
)

Definition at line 551 of file throwing_compare_test.cc.

References k, and KEY.

◆ TYPED_TEST() [7/8]

TYPED_TEST ( ThrowingCompareTree  ,
SplitLetsTheExceptionThrough   
)

Definition at line 716 of file throwing_compare_test.cc.

References Aleph::split().

◆ TYPED_TEST() [8/8]

TYPED_TEST ( ThrowingCompareTree  ,
TakesTheResultOfTheComparisonAsABool   
)

Definition at line 1871 of file throwing_compare_test.cc.

◆ TYPED_TEST_SUITE() [1/3]

TYPED_TEST_SUITE ( ThrowingCompareMap  ,
Tree_Kinds  ,
Kind_Names   
)

◆ TYPED_TEST_SUITE() [2/3]

TYPED_TEST_SUITE ( ThrowingCompareSet  ,
Tree_Kinds  ,
Kind_Names   
)

◆ TYPED_TEST_SUITE() [3/3]

TYPED_TEST_SUITE ( ThrowingCompareTree  ,
Tree_Kinds  ,
Kind_Names   
)