Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:03:56

0001 /*----------------------------------------------------------------------
0002 
0003 Test program for edm::vector_transform class.
0004 
0005  ----------------------------------------------------------------------*/
0006 
0007 #include <cassert>
0008 #include <iostream>
0009 #include <string>
0010 #include <boost/algorithm/string.hpp>
0011 #include <cppunit/extensions/HelperMacros.h>
0012 
0013 #include "FWCore/Utilities/interface/transform.h"
0014 
0015 class testTransform : public CppUnit::TestFixture {
0016   CPPUNIT_TEST_SUITE(testTransform);
0017 
0018   CPPUNIT_TEST(valueTest);
0019 
0020   CPPUNIT_TEST_SUITE_END();
0021 
0022 public:
0023   void setUp() {}
0024   void tearDown() {}
0025 
0026   void valueTest();
0027 };
0028 
0029 // register the test so that the runner can find it
0030 CPPUNIT_TEST_SUITE_REGISTRATION(testTransform);
0031 
0032 std::string byvalue_toupper(std::string const& value) { return boost::to_upper_copy(value); }
0033 
0034 const std::string byconstvalue_toupper(std::string const& value) { return boost::to_upper_copy(value); }
0035 
0036 std::string& byref_toupper(std::string const& value) { return *new std::string(boost::to_upper_copy(value)); }
0037 
0038 std::string& byconstref_toupper(std::string const& value) { return *new std::string(boost::to_upper_copy(value)); }
0039 
0040 void testTransform::valueTest() {
0041   const std::vector<std::string> input{"Hello", "World"};
0042   const std::vector<std::string> upper{"HELLO", "WORLD"};
0043   const std::vector<std::string::size_type> size{5, 5};
0044 
0045   auto test_lambda = edm::vector_transform(input, [](std::string const& value) { return value.size(); });
0046   CPPUNIT_ASSERT(size == test_lambda);
0047 
0048   CPPUNIT_ASSERT(upper == edm::vector_transform(input, byvalue_toupper));
0049   CPPUNIT_ASSERT(upper == edm::vector_transform(input, byconstvalue_toupper));
0050   CPPUNIT_ASSERT(upper == edm::vector_transform(input, byref_toupper));
0051   CPPUNIT_ASSERT(upper == edm::vector_transform(input, byconstref_toupper));
0052 }