ProteoWizard
Functions | Variables
MemoryIndexTest.cpp File Reference
#include "MemoryIndex.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"

Go to the source code of this file.

Functions

void test ()
int main (int argc, char *argv[])

Variables

ostream * os_ = 0

Function Documentation

void test ( )

Definition at line 33 of file MemoryIndexTest.cpp.

References pwiz::data::MemoryIndex::create(), pwiz::data::MemoryIndex::find(), pwiz::data::Index::Entry::id, pwiz::data::Index::Entry::index, boost::lexical_cast(), pwiz::data::Index::Entry::offset, os_, pwiz::data::MemoryIndex::size(), and unit_assert.

{
if (os_) cout << "Testing MemoryIndex" << endl;
vector<Index::Entry> entries;
for (size_t i=0; i < 10; ++i)
{
Index::Entry entry;
entry.id = lexical_cast<string>(i);
entry.index = i;
entry.offset = i*100;
entries.push_back(entry);
}
MemoryIndex index;
unit_assert(index.size() == 0);
unit_assert(!index.find("42").get());
unit_assert(!index.find(42).get());
index.create(entries);
unit_assert(index.size() == 10);
for (size_t i=0; i < 10; ++i)
{
Index::EntryPtr entryPtr = index.find(i);
unit_assert(entryPtr.get());
unit_assert(entryPtr->id == lexical_cast<string>(i));
unit_assert(entryPtr->index == i);
unit_assert(entryPtr->offset == Index::stream_offset(i*100));
entryPtr = index.find(entryPtr->id);
unit_assert(entryPtr.get());
unit_assert(entryPtr->id == lexical_cast<string>(i));
unit_assert(entryPtr->index == i);
unit_assert(entryPtr->offset == Index::stream_offset(i*100));
}
unit_assert(!index.find("42").get());
unit_assert(!index.find(42).get());
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 74 of file MemoryIndexTest.cpp.

References e(), os_, test(), TEST_EPILOG, TEST_FAILED, and TEST_PROLOG.

{
TEST_PROLOG(argc, argv)
try
{
if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
test();
}
catch (exception& e)
{
TEST_FAILED(e.what())
}
catch (...)
{
TEST_FAILED("Caught unknown exception.")
}
}

Variable Documentation

ostream* os_ = 0

Definition at line 30 of file MemoryIndexTest.cpp.