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

§ test()

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.

Referenced by main().

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 }
virtual EntryPtr find(const std::string &id) const
returns the entry for the specified string id, or null if the id is not in the index ...
stream_offset offset
Definition: Index.hpp:50
index implementation in memory; find(string id) is O(logN); find(ordinal index) is O(1); memory footp...
Definition: MemoryIndex.hpp:37
std::string id
Definition: Index.hpp:48
boost::shared_ptr< Entry > EntryPtr
Definition: Index.hpp:53
virtual void create(std::vector< Entry > &entries)
create the index from specified list of entries; the list is non-const because the index implementati...
float lexical_cast(const std::string &str)
boost::iostreams::stream_offset stream_offset
Definition: Index.hpp:43
virtual size_t size() const
returns the number of entries in the index
generic type identifying an indexed item by string id, ordinal index, and stream offset ...
Definition: Index.hpp:46
boost::uint64_t index
Definition: Index.hpp:49
#define unit_assert(x)
Definition: unit.hpp:85
ostream * os_

§ main()

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 }
#define TEST_EPILOG
Definition: unit.hpp:182
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
void test()
ostream * os_

Variable Documentation

§ os_

ostream* os_ = 0

Definition at line 30 of file MemoryIndexTest.cpp.

Referenced by main(), and test().