* attributes and nodes due to template use */
#include "expr/node.h"
#include "expr/type_node.h"
-#include "context/context.h"
#ifndef __CVC4__EXPR__ATTRIBUTE_H
#define __CVC4__EXPR__ATTRIBUTE_H
#undef CVC4_ATTRIBUTE_H__INCLUDING__ATTRIBUTE_INTERNALS_H
namespace CVC4 {
-
-class SmtEngine;
-
-namespace smt {
- extern CVC4_THREADLOCAL(SmtEngine*) s_smtEngine_current;
-}/* CVC4::smt namespace */
-
namespace expr {
namespace attr {
// ATTRIBUTE MANAGER ===========================================================
-struct SmtAttributes {
- SmtAttributes(context::Context*);
-
- // IF YOU ADD ANY TABLES, don't forget to add them also to the
- // implementation of deleteAllAttributes().
-
- /** Underlying hash table for context-dependent boolean-valued attributes */
- CDAttrHash<bool> d_cdbools;
- /** Underlying hash table for context-dependent integral-valued attributes */
- CDAttrHash<uint64_t> d_cdints;
- /** Underlying hash table for context-dependent node-valued attributes */
- CDAttrHash<TNode> d_cdtnodes;
- /** Underlying hash table for context-dependent node-valued attributes */
- CDAttrHash<Node> d_cdnodes;
- /** Underlying hash table for context-dependent string-valued attributes */
- CDAttrHash<std::string> d_cdstrings;
- /** Underlying hash table for context-dependent pointer-valued attributes */
- CDAttrHash<void*> d_cdptrs;
-
- /** Delete all attributes of given node */
- void deleteAllAttributes(TNode n);
-
- template <class T>
- void deleteFromTable(CDAttrHash<T>& table, NodeValue* nv);
-
-};/* struct SmtAttributes */
-
/**
* A container for the main attribute tables of the system. There's a
* one-to-one NodeManager : AttributeManager correspondence.
void clearDeleteAllAttributesBuffer();
- SmtAttributes& getSmtAttributes(SmtEngine*);
- const SmtAttributes& getSmtAttributes(SmtEngine*) const;
-
public:
/** Construct an attribute manager. */
struct getTable<bool, false> {
static const AttrTableId id = AttrTableBool;
typedef AttrHash<bool> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
+ static inline table_type& get(AttributeManager& am) {
return am.d_bools;
}
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
+ static inline const table_type& get(const AttributeManager& am) {
return am.d_bools;
}
};
struct getTable<uint64_t, false> {
static const AttrTableId id = AttrTableUInt64;
typedef AttrHash<uint64_t> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
+ static inline table_type& get(AttributeManager& am) {
return am.d_ints;
}
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
+ static inline const table_type& get(const AttributeManager& am) {
return am.d_ints;
}
};
struct getTable<TNode, false> {
static const AttrTableId id = AttrTableTNode;
typedef AttrHash<TNode> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
+ static inline table_type& get(AttributeManager& am) {
return am.d_tnodes;
}
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
+ static inline const table_type& get(const AttributeManager& am) {
return am.d_tnodes;
}
};
struct getTable<Node, false> {
static const AttrTableId id = AttrTableNode;
typedef AttrHash<Node> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
+ static inline table_type& get(AttributeManager& am) {
return am.d_nodes;
}
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
+ static inline const table_type& get(const AttributeManager& am) {
return am.d_nodes;
}
};
struct getTable<TypeNode, false> {
static const AttrTableId id = AttrTableTypeNode;
typedef AttrHash<TypeNode> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
+ static inline table_type& get(AttributeManager& am) {
return am.d_types;
}
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
+ static inline const table_type& get(const AttributeManager& am) {
return am.d_types;
}
};
struct getTable<std::string, false> {
static const AttrTableId id = AttrTableString;
typedef AttrHash<std::string> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
+ static inline table_type& get(AttributeManager& am) {
return am.d_strings;
}
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
+ static inline const table_type& get(const AttributeManager& am) {
return am.d_strings;
}
};
struct getTable<T*, false> {
static const AttrTableId id = AttrTablePointer;
typedef AttrHash<void*> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
+ static inline table_type& get(AttributeManager& am) {
return am.d_ptrs;
}
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
+ static inline const table_type& get(const AttributeManager& am) {
return am.d_ptrs;
}
};
struct getTable<const T*, false> {
static const AttrTableId id = AttrTablePointer;
typedef AttrHash<void*> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
+ static inline table_type& get(AttributeManager& am) {
return am.d_ptrs;
}
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
+ static inline const table_type& get(const AttributeManager& am) {
return am.d_ptrs;
}
};
-/** Access the "d_cdbools" member of AttributeManager. */
-template <>
-struct getTable<bool, true> {
- static const AttrTableId id = AttrTableCDBool;
- typedef CDAttrHash<bool> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
- return am.getSmtAttributes(smt).d_cdbools;
- }
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
- return am.getSmtAttributes(smt).d_cdbools;
- }
-};
-
-/** Access the "d_cdints" member of AttributeManager. */
-template <>
-struct getTable<uint64_t, true> {
- static const AttrTableId id = AttrTableCDUInt64;
- typedef CDAttrHash<uint64_t> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
- return am.getSmtAttributes(smt).d_cdints;
- }
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
- return am.getSmtAttributes(smt).d_cdints;
- }
-};
-
-/** Access the "d_tnodes" member of AttributeManager. */
-template <>
-struct getTable<TNode, true> {
- static const AttrTableId id = AttrTableCDTNode;
- typedef CDAttrHash<TNode> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
- return am.getSmtAttributes(smt).d_cdtnodes;
- }
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
- return am.getSmtAttributes(smt).d_cdtnodes;
- }
-};
-
-/** Access the "d_cdnodes" member of AttributeManager. */
-template <>
-struct getTable<Node, true> {
- static const AttrTableId id = AttrTableCDNode;
- typedef CDAttrHash<Node> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
- return am.getSmtAttributes(smt).d_cdnodes;
- }
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
- return am.getSmtAttributes(smt).d_cdnodes;
- }
-};
-
-/** Access the "d_cdstrings" member of AttributeManager. */
-template <>
-struct getTable<std::string, true> {
- static const AttrTableId id = AttrTableCDString;
- typedef CDAttrHash<std::string> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
- return am.getSmtAttributes(smt).d_cdstrings;
- }
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
- return am.getSmtAttributes(smt).d_cdstrings;
- }
-};
-
-/** Access the "d_cdptrs" member of AttributeManager. */
-template <class T>
-struct getTable<T*, true> {
- static const AttrTableId id = AttrTableCDPointer;
- typedef CDAttrHash<void*> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
- return am.getSmtAttributes(smt).d_cdptrs;
- }
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
- return am.getSmtAttributes(smt).d_cdptrs;
- }
-};
-
-/** Access the "d_cdptrs" member of AttributeManager. */
-template <class T>
-struct getTable<const T*, true> {
- static const AttrTableId id = AttrTableCDPointer;
- typedef CDAttrHash<void*> table_type;
- static inline table_type& get(AttributeManager& am, SmtEngine* smt) {
- return am.getSmtAttributes(smt).d_cdptrs;
- }
- static inline const table_type& get(const AttributeManager& am, SmtEngine* smt) {
- return am.getSmtAttributes(smt).d_cdptrs;
- }
-};
-
}/* CVC4::expr::attr namespace */
// ATTRIBUTE MANAGER IMPLEMENTATIONS ===========================================
table_type table_type;
const table_type& ah =
- getTable<value_type, AttrKind::context_dependent>::get(*this, smt::s_smtEngine_current);
+ getTable<value_type, AttrKind::context_dependent>::get(*this);
typename table_type::const_iterator i =
ah.find(std::make_pair(AttrKind::getId(), nv));
table_type;
const table_type& ah =
- getTable<value_type, AttrKind::context_dependent>::get(*am, smt::s_smtEngine_current);
+ getTable<value_type, AttrKind::context_dependent>::get(*am);
typename table_type::const_iterator i =
ah.find(std::make_pair(AttrKind::getId(), nv));
table_type table_type;
const table_type& ah =
- getTable<value_type, AttrKind::context_dependent>::get(*am, smt::s_smtEngine_current);
+ getTable<value_type, AttrKind::context_dependent>::get(*am);
typename table_type::const_iterator i =
ah.find(std::make_pair(AttrKind::getId(), nv));
table_type table_type;
const table_type& ah =
- getTable<value_type, AttrKind::context_dependent>::get(*am, smt::s_smtEngine_current);
+ getTable<value_type, AttrKind::context_dependent>::get(*am);
typename table_type::const_iterator i =
ah.find(std::make_pair(AttrKind::getId(), nv));
table_type table_type;
table_type& ah =
- getTable<value_type, AttrKind::context_dependent>::get(*this, smt::s_smtEngine_current);
+ getTable<value_type, AttrKind::context_dependent>::get(*this);
ah[std::make_pair(AttrKind::getId(), nv)] = mapping::convert(value);
}
}
}
-/**
- * Obliterate a NodeValue from a (context-dependent) attribute table.
- */
-template <class T>
-inline void SmtAttributes::deleteFromTable(CDAttrHash<T>& table,
- NodeValue* nv) {
- for(unsigned id = 0; id < attr::LastAttributeId<T, true>::getId(); ++id) {
- table.obliterate(std::make_pair(id, nv));
- }
-}
-
/**
* Remove all attributes from the table calling the cleanup function
* if one is defined.
#include <cxxtest/TestSuite.h>
+#include <map>
+
+#include "base/cvc4_assert.h"
+#include "context/context.h"
#include "context/cdhashmap.h"
#include "context/cdlist.h"
-using namespace std;
-using namespace CVC4;
-using namespace CVC4::context;
+using CVC4::AssertionException;
+using CVC4::context::Context;
+using CVC4::context::CDHashMap;
class CDMapBlack : public CxxTest::TestSuite {
-
Context* d_context;
-public:
-
+ public:
void setUp() {
d_context = new Context;
- //Debug.on("context");
- //Debug.on("gc");
- //Debug.on("pushpop");
+ // Debug.on("context");
+ // Debug.on("gc");
+ // Debug.on("pushpop");
}
- void tearDown() {
- delete d_context;
+ void tearDown() { delete d_context; }
+
+ // Returns the elements in a CDHashMap.
+ static std::map<int, int> GetElements(const CDHashMap<int, int>& map) {
+ return std::map<int, int>{map.begin(), map.end()};
+ }
+
+ // Returns true if the elements in map are the same as expected.
+ // NOTE: This is mostly to help the type checker for matching expected within
+ // a TS_ASSERT.
+ static bool ElementsAre(const CDHashMap<int, int>& map,
+ const std::map<int, int>& expected) {
+ return GetElements(map) == expected;
}
void testSimpleSequence() {
CDHashMap<int, int> map(d_context);
-
- TS_ASSERT(map.find(3) == map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
+ TS_ASSERT(ElementsAre(map, {}));
map.insert(3, 4);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
+ TS_ASSERT(ElementsAre(map, {{3, 4}}));
{
d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
+ TS_ASSERT(ElementsAre(map, {{3, 4}}));
map.insert(5, 6);
map.insert(9, 8);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
+ TS_ASSERT(ElementsAre(map, {{3, 4}, {5, 6}, {9, 8}}));
{
d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
+ TS_ASSERT(ElementsAre(map, {{3, 4}, {5, 6}, {9, 8}}));
map.insert(1, 2);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
+ TS_ASSERT(ElementsAre(map, {{1, 2}, {3, 4}, {5, 6}, {9, 8}}));
{
d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
+ TS_ASSERT(ElementsAre(map, {{1, 2}, {3, 4}, {5, 6}, {9, 8}}));
map.insertAtContextLevelZero(23, 317);
map.insert(1, 45);
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 45);
- TS_ASSERT(map[23] == 317);
-
+ TS_ASSERT(
+ ElementsAre(map, {{1, 45}, {3, 4}, {5, 6}, {9, 8}, {23, 317}}));
map.insert(23, 324);
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 45);
- TS_ASSERT(map[23] == 324);
-
+ TS_ASSERT(
+ ElementsAre(map, {{1, 45}, {3, 4}, {5, 6}, {9, 8}, {23, 324}}));
d_context->pop();
}
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 317);
-
+ TS_ASSERT(
+ ElementsAre(map, {{1, 2}, {3, 4}, {5, 6}, {9, 8}, {23, 317}}));
d_context->pop();
}
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[23] == 317);
-
+ TS_ASSERT(ElementsAre(map, {{3, 4}, {5, 6}, {9, 8}, {23, 317}}));
d_context->pop();
}
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[23] == 317);
+ TS_ASSERT(ElementsAre(map, {{3, 4}, {23, 317}}));
}
// no intervening find() in this one
// (under the theory that this could trigger a bug)
void testSimpleSequenceFewerFinds() {
CDHashMap<int, int> map(d_context);
-
map.insert(3, 4);
{
map.insert(1, 2);
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(7) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[5] == 6);
-
+ TS_ASSERT(ElementsAre(map, {{1, 2}, {3, 4}, {5, 6}, {9, 8}}));
{
d_context->push();
-
d_context->pop();
}
}
}
- void testObliterate() {
- CDHashMap<int, int> map(d_context);
-
- map.insert(3, 4);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
-
- {
- d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
-
- map.insert(5, 6);
- map.insert(9, 8);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
-
- {
- d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
-
- map.insertAtContextLevelZero(23, 317);
- map.insert(1, 2);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 317);
-
- map.obliterate(5);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 317);
-
- {
- d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 317);
-
- d_context->pop();
- }
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 317);
-
- map.obliterate(23);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
-
- d_context->pop();
- }
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[9] == 8);
-
- d_context->pop();
- }
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- }
-
- void testObliteratePrimordial() {
- CDHashMap<int, int> map(d_context);
-
- map.insert(3, 4);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map[3] == 4);
-
- {
- d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map[3] == 4);
-
- map.insert(5, 6);
- map.insert(9, 8);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
-
- {
- d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- map.insert(1, 2);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
-
- map.obliterate(3);
-
- TS_ASSERT(map.find(3) == map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
-
- {
- d_context->push();
-
- TS_ASSERT(map.find(3) == map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
-
- d_context->pop();
- }
-
- TS_ASSERT(map.find(3) == map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
-
- d_context->pop();
- }
-
- TS_ASSERT(map.find(3) == map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
-
- d_context->pop();
- }
-
- TS_ASSERT(map.find(3) == map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- }
-
- void testObliterateCurrent() {
- CDHashMap<int, int> map(d_context);
-
- map.insert(3, 4);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map[3] == 4);
-
- {
- d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map[3] == 4);
-
- map.insert(5, 6);
- map.insert(9, 8);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
-
- {
- d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
-
- map.insert(1, 2);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
-
- map.obliterate(1);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
-
- {
- d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
-
- d_context->pop();
- }
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
-
- d_context->pop();
- }
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
-
- d_context->pop();
- }
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map[3] == 4);
- }
-
void testInsertAtContextLevelZero() {
CDHashMap<int, int> map(d_context);
map.insert(3, 4);
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
-
+ TS_ASSERT(ElementsAre(map, {{3, 4}}));
{
d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
+ TS_ASSERT(ElementsAre(map, {{3, 4}}));
map.insert(5, 6);
map.insert(9, 8);
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
+ TS_ASSERT(ElementsAre(map, {{3, 4}, {5, 6}, {9, 8}}));
{
d_context->push();
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
+ TS_ASSERT(ElementsAre(map, {{3, 4}, {5, 6}, {9, 8}}));
map.insert(1, 2);
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
+ TS_ASSERT(ElementsAre(map, {{1, 2}, {3, 4}, {5, 6}, {9, 8}}));
map.insertAtContextLevelZero(23, 317);
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 317);
+ TS_ASSERT(
+ ElementsAre(map, {{1, 2}, {3, 4}, {5, 6}, {9, 8}, {23, 317}}));
TS_ASSERT_THROWS(map.insertAtContextLevelZero(23, 317),
AssertionException);
AssertionException);
map.insert(23, 472);
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 472);
-
+ TS_ASSERT(
+ ElementsAre(map, {{1, 2}, {3, 4}, {5, 6}, {9, 8}, {23, 472}}));
{
d_context->push();
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 472);
+ TS_ASSERT(
+ ElementsAre(map, {{1, 2}, {3, 4}, {5, 6}, {9, 8}, {23, 472}}));
TS_ASSERT_THROWS(map.insertAtContextLevelZero(23, 0),
AssertionException);
map.insert(23, 1024);
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 1024);
-
+ TS_ASSERT(
+ ElementsAre(map, {{1, 2}, {3, 4}, {5, 6}, {9, 8}, {23, 1024}}));
d_context->pop();
}
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 472);
-
+ TS_ASSERT(
+ ElementsAre(map, {{1, 2}, {3, 4}, {5, 6}, {9, 8}, {23, 472}}));
d_context->pop();
}
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[23] == 317);
-
- TS_ASSERT_THROWS(map.insertAtContextLevelZero(23, 0),
- AssertionException);
- map.insert(23, 477);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[23] == 477);
-
- d_context->pop();
- }
-
- TS_ASSERT_THROWS(map.insertAtContextLevelZero(23, 0),
- AssertionException);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[23] == 317);
- }
-
- void testObliterateInsertedAtContextLevelZero() {
- CDHashMap<int, int> map(d_context);
-
- map.insert(3, 4);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
-
- {
- d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
-
- map.insert(5, 6);
- map.insert(9, 8);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
-
- {
- d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
-
- map.insert(1, 2);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
-
- map.insertAtContextLevelZero(23, 317);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 317);
-
- TS_ASSERT_THROWS(map.insertAtContextLevelZero(23, 317),
- AssertionException);
- TS_ASSERT_THROWS(map.insertAtContextLevelZero(23, 472),
- AssertionException);
- map.insert(23, 472);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 472);
-
- {
- d_context->push();
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 472);
-
- TS_ASSERT_THROWS(map.insertAtContextLevelZero(23, 0),
- AssertionException);
- map.insert(23, 1024);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 1024);
-
- d_context->pop();
- }
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
- TS_ASSERT(map[23] == 472);
-
- map.obliterate(23);
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) != map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[1] == 2);
+ TS_ASSERT(
+ ElementsAre(map, {{3, 4}, {5, 6}, {9, 8}, {23, 317}}));
- d_context->pop();
- }
-
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
-
- // reinsert as a normal map entry
+ TS_ASSERT_THROWS(map.insertAtContextLevelZero(23, 0), AssertionException);
map.insert(23, 477);
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) != map.end());
- TS_ASSERT(map.find(9) != map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) != map.end());
- TS_ASSERT(map[3] == 4);
- TS_ASSERT(map[5] == 6);
- TS_ASSERT(map[9] == 8);
- TS_ASSERT(map[23] == 477);
-
+ TS_ASSERT(
+ ElementsAre(map, {{3, 4}, {5, 6}, {9, 8}, {23, 477}}));
d_context->pop();
}
- TS_ASSERT(map.find(3) != map.end());
- TS_ASSERT(map.find(5) == map.end());
- TS_ASSERT(map.find(9) == map.end());
- TS_ASSERT(map.find(1) == map.end());
- TS_ASSERT(map.find(23) == map.end());
- TS_ASSERT(map[3] == 4);
+ TS_ASSERT_THROWS(map.insertAtContextLevelZero(23, 0), AssertionException);
+
+ TS_ASSERT(
+ ElementsAre(map, {{3, 4}, {23, 317}}));
}
};