/* -*- Mode: C++; tab-width: 8; 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/. */
// Test with single bit set. for (size_t i = 0; i < size; i += 5) {
bitset[i] = true;
MOZ_RELEASE_ASSERT(bitset.FindFirst() == i);
MOZ_RELEASE_ASSERT(bitset.FindLast() == i);
MOZ_RELEASE_ASSERT(bitset.FindNext(i) == i);
MOZ_RELEASE_ASSERT(bitset.FindPrev(i) == i);
MOZ_RELEASE_ASSERT(bitset.FindNext(0) == i);
MOZ_RELEASE_ASSERT(bitset.FindPrev(size - 1) == i); if (i != 0) {
MOZ_RELEASE_ASSERT(bitset.FindNext(i - 1) == i);
MOZ_RELEASE_ASSERT(bitset.FindPrev(i - 1) == SIZE_MAX);
} if (i != size - 1) {
MOZ_RELEASE_ASSERT(bitset.FindNext(i + 1) == SIZE_MAX);
MOZ_RELEASE_ASSERT(bitset.FindPrev(i + 1) == i);
}
bitset[i] = false;
}
// Test with multiple bits set. // // This creates bits pattern with every |i|th bit set and checks the result // of calling FindNext/FindPrev at and around each set bit. for (size_t i = 3; i < size; i += 5) {
bitset.ResetAll(); for (size_t j = 0; j < size; j += i) {
bitset[j] = true;
} for (size_t j = 0; j < size; j += i) { // Test FindNext/FindPrev on the current bit.
MOZ_RELEASE_ASSERT(bitset[j]);
MOZ_RELEASE_ASSERT(bitset.FindNext(j) == j);
MOZ_RELEASE_ASSERT(bitset.FindPrev(j) == j); // Test FindNext/FindPrev on the previous bit. if (j != 0) {
MOZ_RELEASE_ASSERT(bitset[j - i]);
MOZ_RELEASE_ASSERT(bitset.FindNext(j - 1) == j);
MOZ_RELEASE_ASSERT(bitset.FindPrev(j - 1) == j - i);
} // Test FindNext/FindPrev on the next bit. if (j + i < size) {
MOZ_RELEASE_ASSERT(bitset[j + i]);
MOZ_RELEASE_ASSERT(bitset.FindNext(j + 1) == j + i);
MOZ_RELEASE_ASSERT(bitset.FindPrev(j + 1) == j);
}
}
}
}
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.