/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/NPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): */ #ifndef TREETEST_H #define TREETEST_H #include "Tree.h" const bool printProgress = true; // Set to print the progress of each test Uint32 random(Uint16 range); // --- PRIVATE ---------------------------------------------------------------- class TreeHarness { // We could have used Uint32 directly instead of struct TestKey, but // this way we can check that the Tree templates do not expect any methods // other than operator< to apply to keys. struct TestKey { Uint32 n; // Number of the node that contains this key explicit TestKey(Uint32 n): n(n) {} bool operator<(const TestKey &key2) const {return n < key2.n;} }; struct TestNode: TreeNode { TestKey key; TestNode(): key(0) {} const TestKey &getKey() const {return key;} }; public: static const nNodes = 32; private: SortedTree tree; Uint32 rep; // Bitmap of what should be in the tree TestNode nodes[nNodes]; public: TreeHarness(); static inline Uint32 randomNode() {return random(nNodes);} inline bool present(Uint32 n) const {return rep>>n & 1;} inline void add(Uint32 n) {rep |= 1<