-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathintersperse_test.cpp
More file actions
104 lines (84 loc) · 2.65 KB
/
intersperse_test.cpp
File metadata and controls
104 lines (84 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Boost string_algo library intersperse_test.cpp file ---------------------------//
// Copyright Denis Mikhailov 2022. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <boost/algorithm/string/intersperse.hpp>
// Include unit test framework
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <string>
#include <iostream>
#include <boost/test/test_tools.hpp>
using namespace std;
using namespace boost;
struct CharGenerator {
typedef char result_type;
char counter;
CharGenerator() { counter = '1'; }
char operator() () {
return counter++;
}
};
void intersperse_test()
{
string test = "";
intersperse(test, ',');
BOOST_CHECK(test == "");
test = "a";
intersperse(test, ',');
BOOST_CHECK(test == "a");
test = "ab";
intersperse(test, ',');
BOOST_CHECK(test == "a,b");
intersperse(test, ' ');
BOOST_CHECK(test == "a , b");
intersperse(test, ' ');
BOOST_CHECK(test == "a , b");
const string input1 = "abcde";
const string input2 = "";
const string input3 = "a";
const string input4 = "ab";
BOOST_CHECK(intersperse_copy(input1, ',') == "a,b,c,d,e");
BOOST_CHECK(intersperse_copy(input2, ',') == "");
BOOST_CHECK(intersperse_copy(input3, ',') == "a");
BOOST_CHECK(intersperse_copy(input4, ',') == "a,b");
}
void intersperse_fill_test()
{
string test = "";
intersperse_fill(test, ", ");
BOOST_CHECK(test == "");
test = "a";
intersperse_fill(test, ", ");
BOOST_CHECK(test == "a");
test = "ab";
intersperse_fill(test, ", ");
BOOST_CHECK(test == "a, b");
intersperse_fill(test, " ");
BOOST_CHECK(test == "a , b");
const string input1 = "abcde";
const string input2 = "";
const string input3 = "a";
const string input4 = "ab";
BOOST_CHECK(intersperse_fill_copy(input1, ", ") == "a, b, c, d, e");
BOOST_CHECK(intersperse_fill_copy(input2, ", ") == "");
BOOST_CHECK(intersperse_fill_copy(input3, ", ") == "a");
BOOST_CHECK(intersperse_fill_copy(input4, ", ") == "a, b");
}
void intersperse_generate_test()
{
const string input = "test";
CharGenerator g1, g2;
BOOST_CHECK(intersperse_generate_copy(input, g1) == "t1e2s3t");
string test = "test";
intersperse_generate(test, g2);
BOOST_CHECK(test == "t1e2s3t");
}
BOOST_AUTO_TEST_CASE( test_main )
{
intersperse_test();
intersperse_fill_test();
intersperse_generate_test();
}