@@ -29,15 +29,61 @@ namespace ba = boost::algorithm;
29
29
30
30
static void
31
31
test_ordered (void )
32
+ {
33
+ const int strictlyIncreasingValues[] = { 1 , 2 , 3 , 4 , 5 };
34
+ const int randomValues[] = { 3 , 6 , 1 , 2 , 7 };
35
+ const int constantValues[] = { 1 , 2 , 2 , 2 , 5 };
36
+ int nonConstantArray[] = { 1 , 2 , 2 , 2 , 5 };
37
+ const int inOrderUntilTheEnd [] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 6 };
38
+
39
+ // Begin/end checks
40
+ BOOST_CHECK ( ba::is_sorted (b_e (strictlyIncreasingValues)));
41
+ BOOST_CHECK ( !ba::is_sorted (b_e (randomValues)));
42
+ BOOST_CHECK ( ba::is_sorted (b_e (strictlyIncreasingValues), std::less<int >()));
43
+ BOOST_CHECK ( !ba::is_sorted (b_e (strictlyIncreasingValues), std::greater<int >()));
44
+
45
+ // Range checks
46
+ BOOST_CHECK ( ba::is_sorted (a_range (strictlyIncreasingValues)));
47
+ BOOST_CHECK ( !ba::is_sorted (a_range (randomValues)));
48
+ BOOST_CHECK ( ba::is_sorted (a_range (strictlyIncreasingValues), std::less<int >()));
49
+ BOOST_CHECK ( !ba::is_sorted (a_range (strictlyIncreasingValues), std::greater<int >()));
50
+
51
+ BOOST_CHECK ( ba::is_sorted_until ( b_e (strictlyIncreasingValues)) == a_end (strictlyIncreasingValues));
52
+ BOOST_CHECK ( ba::is_sorted_until ( b_e (strictlyIncreasingValues), std::less<int >()) == a_end (strictlyIncreasingValues));
53
+ BOOST_CHECK ( ba::is_sorted_until ( a_range (strictlyIncreasingValues)) == boost::end (strictlyIncreasingValues));
54
+ BOOST_CHECK ( ba::is_sorted_until ( a_range (strictlyIncreasingValues), std::less<int >()) == boost::end (strictlyIncreasingValues));
55
+
56
+ // Check for const and non-const arrays
57
+ BOOST_CHECK ( ba::is_sorted_until ( b_e (constantValues), std::less<int >()) != a_end (constantValues));
58
+ BOOST_CHECK ( ba::is_sorted_until ( a_range (constantValues), std::less<int >()) != boost::end (constantValues));
59
+ BOOST_CHECK ( ba::is_sorted_until ( b_e (nonConstantArray), std::less<int >()) != a_end (nonConstantArray));
60
+ BOOST_CHECK ( ba::is_sorted_until ( a_range (nonConstantArray), std::less<int >()) != boost::end (nonConstantArray));
61
+
62
+ BOOST_CHECK ( ba::is_sorted_until ( b_e (randomValues), std::less<int >()) == &randomValues[2 ] );
63
+ BOOST_CHECK ( ba::is_sorted_until ( b_e (randomValues)) == &randomValues[2 ] );
64
+ BOOST_CHECK ( ba::is_sorted_until ( a_range (randomValues), std::less<int >()) == &randomValues[2 ] );
65
+ BOOST_CHECK ( ba::is_sorted_until ( a_range (randomValues)) == &randomValues[2 ] );
66
+
67
+ BOOST_CHECK ( ba::is_sorted_until ( a_range (inOrderUntilTheEnd), std::less<int >()) == &inOrderUntilTheEnd[8 ] );
68
+ BOOST_CHECK ( ba::is_sorted_until ( a_range (inOrderUntilTheEnd)) == &inOrderUntilTheEnd[8 ] );
69
+
70
+ // For zero and one element collections, the comparison predicate should never be called
71
+ BOOST_CHECK ( ba::is_sorted_until ( a_begin (randomValues), a_begin (randomValues), std::equal_to<int >()) == a_begin (randomValues));
72
+ BOOST_CHECK ( ba::is_sorted_until ( a_begin (randomValues), a_begin (randomValues)) == a_begin (randomValues));
73
+ BOOST_CHECK ( ba::is_sorted_until ( a_begin (randomValues), a_begin (randomValues) + 1 , std::equal_to<int >()) == a_begin (randomValues) + 1 );
74
+ BOOST_CHECK ( ba::is_sorted_until ( a_begin (randomValues), a_begin (randomValues) + 1 ) == a_begin (randomValues) + 1 );
75
+ }
76
+
77
+
78
+ static void
79
+ test_increasing_decreasing (void )
32
80
{
33
81
const int strictlyIncreasingValues[] = { 1 , 2 , 3 , 4 , 5 };
34
82
const int strictlyDecreasingValues[] = { 9 , 8 , 7 , 6 , 5 };
35
83
const int increasingValues[] = { 1 , 2 , 2 , 2 , 5 };
36
84
const int decreasingValues[] = { 9 , 7 , 7 , 7 , 5 };
37
85
const int randomValues[] = { 3 , 6 , 1 , 2 , 7 };
38
86
const int constantValues[] = { 7 , 7 , 7 , 7 , 7 };
39
- int nonConstantArray[] = { 7 , 7 , 7 , 7 , 7 };
40
- const int inOrderUntilTheEnd [] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 6 };
41
87
42
88
// Test a strictly increasing sequence
43
89
BOOST_CHECK ( ba::is_strictly_increasing (b_e (strictlyIncreasingValues)));
@@ -98,30 +144,11 @@ test_ordered(void)
98
144
BOOST_CHECK ( !ba::is_strictly_decreasing (strictlyIncreasingValues, strictlyIncreasingValues+2 ));
99
145
BOOST_CHECK ( !ba::is_decreasing (strictlyIncreasingValues, strictlyIncreasingValues+2 ));
100
146
101
- // Test underlying routines
102
- BOOST_CHECK ( ba::is_sorted_until ( b_e (strictlyIncreasingValues), std::less<int >()) == a_end (strictlyIncreasingValues));
103
- BOOST_CHECK ( ba::is_sorted_until ( a_range (strictlyIncreasingValues), std::less<int >()) == boost::end (strictlyIncreasingValues));
104
-
105
- BOOST_CHECK ( ba::is_sorted_until ( b_e (nonConstantArray), std::less<int >()) != a_end (nonConstantArray));
106
- BOOST_CHECK ( ba::is_sorted_until ( a_range (nonConstantArray), std::less<int >()) != boost::end (nonConstantArray));
107
-
108
- BOOST_CHECK ( ba::is_sorted_until ( b_e (randomValues), std::less<int >()) == &randomValues[2 ] );
109
- BOOST_CHECK ( ba::is_sorted_until ( a_range (randomValues), std::less<int >()) == &randomValues[2 ] );
110
-
111
- BOOST_CHECK ( ba::is_sorted_until ( b_e (randomValues), std::less<int >()) == &randomValues[2 ] );
112
- BOOST_CHECK ( ba::is_sorted_until ( a_range (randomValues), std::less<int >()) == &randomValues[2 ] );
113
-
114
- BOOST_CHECK ( ba::is_sorted_until ( a_range (inOrderUntilTheEnd), std::less<int >()) == &inOrderUntilTheEnd[8 ] );
115
-
116
- // For zero and one element collections, the comparison predicate should never be called
117
- BOOST_CHECK ( ba::is_sorted_until ( a_begin (randomValues), a_begin (randomValues), std::equal_to<int >()) == a_begin (randomValues));
118
- BOOST_CHECK ( ba::is_sorted_until ( a_begin (randomValues), a_begin (randomValues) + 1 , std::equal_to<int >()) == a_begin (randomValues) + 1 );
119
-
120
147
}
121
148
122
149
int test_main ( int , char * [] )
123
150
{
124
151
test_ordered ();
125
-
152
+ test_increasing_decreasing ();
126
153
return 0 ;
127
154
}
0 commit comments