]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/algorithm/test/is_palindrome_test.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / algorithm / test / is_palindrome_test.cpp
1 /*
2 Copyright (c) Alexander Zaitsev <zamazan4ik@gmail.com>, 2016
3
4 Distributed under the Boost Software License, Version 1.0. (See
5 accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7
8 See http://www.boost.org/ for latest version.
9 */
10
11 #include <boost/config.hpp>
12 #include <boost/algorithm/is_palindrome.hpp>
13
14 #define BOOST_TEST_MAIN
15 #include <boost/test/unit_test.hpp>
16
17 #include <algorithm>
18 #include <iostream>
19 #include <list>
20 #include <vector>
21
22
23 namespace ba = boost::algorithm;
24
25
26 template <typename T>
27 bool funcComparator(const T& v1, const T& v2)
28 {
29 return v1 == v2;
30 }
31
32 struct functorComparator
33 {
34 template <typename T>
35 bool operator()(const T& v1, const T& v2) const
36 {
37 return v1 == v2;
38 }
39 };
40
41 void test_is_palindrome()
42 {
43 const std::list<int> empty;
44 const std::vector<char> singleElement(1, 'z');
45 int oddNonPalindrome[] = {3,2,2};
46 const int oddPalindrome[] = {1,2,3,2,1};
47 const int evenPalindrome[] = {1,2,2,1};
48 int evenNonPalindrome[] = {1,4,8,8};
49 const char* stringNullPtr = NULL;
50
51 // Test a default operator==
52 BOOST_CHECK ( ba::is_palindrome(empty));
53 BOOST_CHECK ( ba::is_palindrome(singleElement));
54 BOOST_CHECK (!ba::is_palindrome(boost::begin(oddNonPalindrome), boost::end(oddNonPalindrome)));
55 BOOST_CHECK ( ba::is_palindrome(boost::begin(oddPalindrome), boost::end(oddPalindrome)));
56 BOOST_CHECK ( ba::is_palindrome(boost::begin(evenPalindrome), boost::end(evenPalindrome)));
57 BOOST_CHECK (!ba::is_palindrome(boost::begin(evenNonPalindrome), boost::end(evenNonPalindrome)));
58
59 //Test the custom comparators
60 BOOST_CHECK ( ba::is_palindrome(empty.begin(), empty.end(), functorComparator()));
61 BOOST_CHECK (!ba::is_palindrome(boost::begin(oddNonPalindrome), boost::end(oddNonPalindrome), funcComparator<int>));
62 BOOST_CHECK ( ba::is_palindrome(evenPalindrome, std::equal_to<int>()));
63
64 //Test C-strings like cases
65 BOOST_CHECK ( ba::is_palindrome(stringNullPtr));
66 BOOST_CHECK ( ba::is_palindrome(""));
67 BOOST_CHECK ( ba::is_palindrome("a"));
68 BOOST_CHECK ( ba::is_palindrome("abacaba", std::equal_to<char>()));
69 BOOST_CHECK ( ba::is_palindrome("abba"));
70 BOOST_CHECK (!ba::is_palindrome("acab"));
71 }
72
73 BOOST_AUTO_TEST_CASE( test_main )
74 {
75 test_is_palindrome ();
76 }