/* -*- Mode: C++; tab-width: 9; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
// Insert the values, and check each one is findable just after insertion. for (int i = 0; i < N; i++) {
tree.insert(new SplayInt(gValues[i]));
SplayInt* inserted = tree.find(SplayInt(gValues[i]));
MOZ_RELEASE_ASSERT(inserted);
MOZ_RELEASE_ASSERT(tree.findOrInsert(SplayInt(gValues[i])) == inserted);
tree.checkCoherency();
}
// Check they're all findable after all insertions. for (int i = 0; i < N; i++) {
MOZ_RELEASE_ASSERT(tree.find(SplayInt(gValues[i])));
MOZ_RELEASE_ASSERT(tree.findOrInsert(SplayInt(gValues[i])));
tree.checkCoherency();
}
// Check that non-inserted values cannot be found.
MOZ_RELEASE_ASSERT(!tree.find(SplayInt(-1)));
MOZ_RELEASE_ASSERT(!tree.find(SplayInt(N)));
MOZ_RELEASE_ASSERT(!tree.find(SplayInt(0x7fffffff)));
// Remove the values, and check each one is not findable just after removal. for (int i = 0; i < N; i++) {
SplayInt* removed = tree.remove(SplayInt(gValues[i]));
MOZ_RELEASE_ASSERT(removed->mValue == gValues[i]);
MOZ_RELEASE_ASSERT(!tree.find(*removed)); delete removed;
tree.checkCoherency();
}
MOZ_RELEASE_ASSERT(tree.empty());
// Insert the values, and check each one is findable just after insertion. for (int i = 0; i < N; i++) {
SplayInt* inserted = tree.findOrInsert(SplayInt(gValues[i]));
MOZ_RELEASE_ASSERT(tree.find(SplayInt(gValues[i])) == inserted);
MOZ_RELEASE_ASSERT(tree.findOrInsert(SplayInt(gValues[i])) == inserted);
tree.checkCoherency();
}
// Check they're all findable after all insertions. for (int i = 0; i < N; i++) {
MOZ_RELEASE_ASSERT(tree.find(SplayInt(gValues[i])));
MOZ_RELEASE_ASSERT(tree.findOrInsert(SplayInt(gValues[i])));
tree.checkCoherency();
}
// Check that non-inserted values cannot be found.
MOZ_RELEASE_ASSERT(!tree.find(SplayInt(-1)));
MOZ_RELEASE_ASSERT(!tree.find(SplayInt(N)));
MOZ_RELEASE_ASSERT(!tree.find(SplayInt(0x7fffffff)));
// Remove the values, and check each one is not findable just after removal. for (int i = 0; i < N; i++) {
SplayInt* removed = tree.remove(SplayInt(gValues[i]));
MOZ_RELEASE_ASSERT(removed->mValue == gValues[i]);
MOZ_RELEASE_ASSERT(!tree.find(*removed)); delete removed;
tree.checkCoherency();
}
MOZ_RELEASE_ASSERT(tree.empty());
// Reinsert the values, in reverse order to last time. for (int i = 0; i < N; i++) {
tree.insert(new SplayInt(gValues[N - i - 1]));
tree.checkCoherency();
}
// Remove the minimum value repeatedly. for (int i = 0; i < N; i++) {
SplayInt* removed = tree.removeMin();
MOZ_RELEASE_ASSERT(removed->mValue == i); delete removed;
tree.checkCoherency();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.