]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/algorithm/test/is_palindrome_test.cpp
add subtree-ish sources for 12.0.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 #define Begin(arr) (arr)
42 #define End(arr) (arr+(sizeof(arr)/(sizeof(arr[0]))))
43
44 void test_is_palindrome()
45 {
46 const std::list<int> empty;
47 const std::vector<char> singleElement(1, 'z');
48 int oddNonPalindrome[] = {3,2,2};
49 const int oddPalindrome[] = {1,2,3,2,1};
50 const int evenPalindrome[] = {1,2,2,1};
51 int evenNonPalindrome[] = {1,4,8,8};
52 const char* stringNullPtr = NULL;
53
54 // Test a default operator==
55 BOOST_CHECK ( ba::is_palindrome(empty));
56 BOOST_CHECK ( ba::is_palindrome(singleElement));
57 BOOST_CHECK (!ba::is_palindrome(Begin(oddNonPalindrome), End(oddNonPalindrome)));
58 BOOST_CHECK ( ba::is_palindrome(Begin(oddPalindrome), End(oddPalindrome)));
59 BOOST_CHECK ( ba::is_palindrome(Begin(evenPalindrome), End(evenPalindrome)));
60 BOOST_CHECK (!ba::is_palindrome(Begin(evenNonPalindrome), End(evenNonPalindrome)));
61
62 //Test the custom comparators
63 BOOST_CHECK ( ba::is_palindrome(empty.begin(), empty.end(), functorComparator()));
64 BOOST_CHECK (!ba::is_palindrome(Begin(oddNonPalindrome), End(oddNonPalindrome), funcComparator<int>));
65 BOOST_CHECK ( ba::is_palindrome(evenPalindrome, std::equal_to<int>()));
66
67 //Test C-strings like cases
68 BOOST_CHECK ( ba::is_palindrome(stringNullPtr));
69 BOOST_CHECK ( ba::is_palindrome(""));
70 BOOST_CHECK ( ba::is_palindrome("a"));
71 BOOST_CHECK ( ba::is_palindrome("abacaba", std::equal_to<char>()));
72 BOOST_CHECK ( ba::is_palindrome("abba"));
73 BOOST_CHECK (!ba::is_palindrome("acab"));
74 }
75
76 BOOST_AUTO_TEST_CASE( test_main )
77 {
78 test_is_palindrome ();
79 }