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.

34 {
35  if (os_) cout << "Testing MemoryIndex" << endl;
36 
37  vector<Index::Entry> entries;
38  for (size_t i=0; i < 10; ++i)
39  {
40  Index::Entry entry;
41  entry.id = lexical_cast<string>(i);
42  entry.index = i;
43  entry.offset = i*100;
44  entries.push_back(entry);
45  }
46 
47  MemoryIndex index;
48  unit_assert(index.size() == 0);
49  unit_assert(!index.find("42").get());
50  unit_assert(!index.find(42).get());
51 
52  index.create(entries);
53  unit_assert(index.size() == 10);
54 
55  for (size_t i=0; i < 10; ++i)
56  {
57  Index::EntryPtr entryPtr = index.find(i);
58  unit_assert(entryPtr.get());
59  unit_assert(entryPtr->id == lexical_cast<string>(i));
60  unit_assert(entryPtr->index == i);
61  unit_assert(entryPtr->offset == Index::stream_offset(i*100));
62 
63  entryPtr = index.find(entryPtr->id);
64  unit_assert(entryPtr.get());
65  unit_assert(entryPtr->id == lexical_cast<string>(i));
66  unit_assert(entryPtr->index == i);
67  unit_assert(entryPtr->offset == Index::stream_offset(i*100));
68  }
69 
70  unit_assert(!index.find("42").get());
71  unit_assert(!index.find(42).get());
72 }
int main ( int  argc,
char *  argv[] 
)

Definition at line 74 of file MemoryIndexTest.cpp.

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

75 {
76  TEST_PROLOG(argc, argv)
77 
78  try
79  {
80  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
81  test();
82  }
83  catch (exception& e)
84  {
85  TEST_FAILED(e.what())
86  }
87  catch (...)
88  {
89  TEST_FAILED("Caught unknown exception.")
90  }
91 
93 }

Variable Documentation

ostream* os_ = 0

Definition at line 30 of file MemoryIndexTest.cpp.