forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_unique_everseen.cpp
More file actions
46 lines (36 loc) · 1.18 KB
/
Copy pathtest_unique_everseen.cpp
File metadata and controls
46 lines (36 loc) · 1.18 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
#include <unique_everseen.hpp>
#include "helpers.hpp"
#include <vector>
#include <string>
#include <iterator>
#include "catch.hpp"
using iter::unique_everseen;
using Vec = const std::vector<int>;
TEST_CASE("unique everseen: adjacent repeating values", "[unique_everseen]") {
Vec ns = {1,1,1,2,2,3,4,4,5,6,7,8,8,8,8,9,9};
auto ue = unique_everseen(ns);
Vec v(std::begin(ue), std::end(ue));
Vec vc = {1,2,3,4,5,6,7,8,9};
REQUIRE( v == vc );
}
TEST_CASE("unique everseen: nonadjacent repeating values",
"[unique_everseen]") {
Vec ns = {1,2,3,4,3,2,1,5,6};
auto ue = unique_everseen(ns);
Vec v(std::begin(ue), std::end(ue));
Vec vc = {1,2,3,4,5,6};
REQUIRE( v == vc );
}
TEST_CASE("unique everseen: moves rvalues, binds to lvalues",
"[unique_everseen]") {
itertest::BasicIterable<int> bi{1, 2};
unique_everseen(bi);
REQUIRE_FALSE( bi.was_moved_from() );
unique_everseen(std::move(bi));
REQUIRE( bi.was_moved_from() );
}
TEST_CASE("unique_everseen: iterator meets requirements", "[unique_everseen]") {
std::string s{};
auto c = unique_everseen(s);
REQUIRE( itertest::IsIterator<decltype(std::begin(c))>::value );
}