Classes | Macros | Functions
SortByPointers_test.cc File Reference

Unit test for SortByPointers.h utilities. More...

#include <boost/test/unit_test.hpp>
#include "larcorealg/CoreUtils/SortByPointers.h"
#include <vector>
#include <algorithm>
#include <type_traits>
#include <cstdlib>

Go to the source code of this file.

Classes

struct  AbsSorter< Data >
 

Macros

#define BOOST_TEST_MODULE   ( SortByPointers_test )
 

Functions

void test_SortByPointers ()
 
void test_makePointerVector ()
 
void test_MoveFromPointers ()
 
 BOOST_AUTO_TEST_CASE (SortByPointers_testcase)
 
 BOOST_AUTO_TEST_CASE (makePointerVector_testcase)
 
 BOOST_AUTO_TEST_CASE (MoveFromPointers_testcase)
 

Detailed Description

Unit test for SortByPointers.h utilities.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
September 28th, 2017
See also
SortByPointers.h

Definition in file SortByPointers_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( SortByPointers_test )

Definition at line 10 of file SortByPointers_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( SortByPointers_testcase  )

Definition at line 95 of file SortByPointers_test.cc.

95  {
96 
98 
99 } // BOOST_AUTO_TEST_CASE(SortByPointers_testcase)
void test_SortByPointers()
BOOST_AUTO_TEST_CASE ( makePointerVector_testcase  )

Definition at line 102 of file SortByPointers_test.cc.

102  {
103 
105 
106 } // BOOST_AUTO_TEST_CASE(makePointerVector_testcase)
void test_makePointerVector()
BOOST_AUTO_TEST_CASE ( MoveFromPointers_testcase  )

Definition at line 109 of file SortByPointers_test.cc.

109  {
110 
112 
113 } // BOOST_AUTO_TEST_CASE(MoveFromPointers_testcase)
void test_MoveFromPointers()
void test_makePointerVector ( )

Definition at line 54 of file SortByPointers_test.cc.

54  {
55 
56  std::vector<int> data = { 8, -7, 5 };
57 
58  std::vector<int*> expectedDataPtr = { &(data[0]), &(data[1]), &(data[2]) };
59 
60  auto dataPtr = util::makePointerVector(data);
61 
62  static_assert(
63  std::is_same<std::decay_t<decltype(dataPtr)>, std::vector<int*>>(),
64  "Unexpected data type from makePointerVector()");
65 
66  BOOST_CHECK_EQUAL_COLLECTIONS(
67  dataPtr.cbegin(), dataPtr.cend(),
68  expectedDataPtr.cbegin(), expectedDataPtr.cend()
69  );
70 
71 } // test_makePointerVector()
auto makePointerVector(Coll &coll)
Creates a STL vector with pointers to data from another collection.
void test_MoveFromPointers ( )

Definition at line 75 of file SortByPointers_test.cc.

75  {
76 
77  std::vector<int> data = { 1, 2, 3, 4 };
78 
79  std::vector<int*> const dataPtr
80  = { &(data[2]), &(data[3]), &(data[0]), &(data[1]) };
81  std::vector<int> expectedMovedData = { 3, 4, 1, 2 };
82 
83  std::vector<int> movedData;
84  util::MoveFromPointers(movedData, dataPtr);
85 
86  BOOST_CHECK_EQUAL_COLLECTIONS(
87  movedData.cbegin(), movedData.cend(),
88  expectedMovedData.cbegin(), expectedMovedData.cend()
89  );
90 
91 } // test_MoveFromPointers()
void MoveFromPointers(Coll &dest, PtrColl &src)
Moves the content from a collection of pointers to one of data.
void test_SortByPointers ( )

Definition at line 34 of file SortByPointers_test.cc.

34  {
35 
36  std::vector<int> data = { 8, -7, 5, 9, -2 };
37 
38  AbsSorter<int> absSorter;
39 
40  auto sortedData = data;
41  std::sort(sortedData.begin(), sortedData.end(), absSorter);
42 
44  [absSorter](auto& coll){ std::sort(coll.begin(), coll.end(), absSorter); }
45  );
46 
47  BOOST_CHECK_EQUAL_COLLECTIONS
48  (data.cbegin(), data.cend(), sortedData.cbegin(), sortedData.cend());
49 
50 } // test_SortByPointers()
void SortByPointers(Coll &coll, Sorter sorter)
Applies sorting indirectly, minimizing data copy.