-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdaw_iterator_circular_iterator_test.cpp
More file actions
150 lines (130 loc) · 3.94 KB
/
daw_iterator_circular_iterator_test.cpp
File metadata and controls
150 lines (130 loc) · 3.94 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright (c) Darrell Wright
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/beached/header_libraries
//
#include "daw/iterator/daw_circular_iterator.h"
#include "daw/daw_benchmark.h"
#include <algorithm>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <type_traits>
#include <vector>
void daw_circular_iterator_001( ) {
std::vector<int> numbers = { 1, 2, 3, 4, 5, 6, 7 };
auto first = daw::make_circular_iterator( numbers );
for( size_t n = 0; n < 14; ++n ) {
std::cout << *first++ << ' ';
}
std::cout << '\n';
}
void daw_circular_iterator_002( ) {
std::vector<int> numbers = { 1, 2, 3, 4, 5, 6, 7 };
auto first = daw::make_circular_iterator( numbers );
for( size_t n = 0; n < 14; ++n ) {
std::cout << *first-- << ' ';
}
std::cout << '\n';
}
void daw_circular_iterator_003( ) {
std::vector<int> numbers = { 1, 2, 3, 4, 5, 6, 7 };
auto first = daw::make_circular_iterator( numbers );
for( int n = 0; n < 14; ++n ) {
first += n * n;
std::cout << *first << ' ';
}
std::cout << '\n';
}
void daw_circular_iterator_004( ) {
auto a = std::vector<int>{};
auto it = daw::make_circular_iterator( a );
constexpr bool is_move_assignable =
std::is_move_assignable<decltype( it )>::value;
daw::expecting( is_move_assignable );
}
void daw_circular_iterator_005( ) {
auto a = std::vector<int>{};
auto it = daw::make_circular_iterator( a );
constexpr bool is_move_constructible =
std::is_move_constructible<decltype( it )>::value;
daw::expecting( is_move_constructible );
}
void daw_circular_iterator_006( ) {
auto a = std::vector<int>{};
auto it = daw::make_circular_iterator( a );
static_assert( std::is_nothrow_move_assignable_v<decltype( it )> );
}
void daw_circular_iterator_007( ) {
auto a = std::vector<int>{};
auto it = daw::make_circular_iterator( a );
static_assert( std::is_nothrow_move_constructible_v<decltype( it )> );
}
void daw_circular_iterator_008( ) {
int a[] = { 1, 2, 3, 4 };
auto it = daw::make_circular_iterator( a );
auto it2 = it + 4;
constexpr bool tst1 = ::std::is_same_v<decltype( *it ), decltype( a[0] )>;
constexpr bool tst2 = ::std::is_same_v<decltype( it ), decltype( it2 )>;
daw::expecting( tst1 );
daw::expecting( tst2 );
}
void daw_circular_iterator_009( ) {
int a[] = { 1, 2, 3, 4 };
auto it = daw::make_circular_iterator( a );
auto it2 = it + 4;
constexpr bool tst1 = ::std::is_same_v<decltype( *it ), decltype( a[0] )>;
constexpr bool tst2 = ::std::is_same_v<decltype( it ), decltype( it2 )>;
daw::expecting( tst1 );
daw::expecting( tst2 );
}
void daw_circular_iterator_010( ) {
int a[] = { 1, 2, 3, 4 };
auto it = daw::make_circular_iterator( a );
using std::swap;
swap( *it, *( it + 1 ) );
daw::expecting( a[0], 2 );
daw::expecting( a[1], 1 );
}
void daw_circular_iterator_011( ) {
int a[] = { 1, 2, 3, 4 };
auto it = daw::make_circular_iterator( a );
auto it2 = it + 3;
daw::expecting( std::distance( it, it2 ), 3 );
}
void daw_circular_iterator_012( ) {
int a[] = { 1, 2, 3, 4 };
auto it = daw::make_circular_iterator( a );
auto it2 = it + 3;
std::iter_swap( it, it2 );
daw::expecting( a[0], 4 );
daw::expecting( a[3], 1 );
}
void daw_circular_iterator_013( ) {
int a[] = { 1, 2, 3, 4 };
auto it = daw::make_circular_iterator( a );
auto const last = it.end( );
std::reverse( it, last );
daw::expecting( a[0], 4 );
daw::expecting( a[1], 3 );
daw::expecting( a[2], 2 );
daw::expecting( a[3], 1 );
}
int main( ) {
daw_circular_iterator_001( );
daw_circular_iterator_002( );
daw_circular_iterator_003( );
daw_circular_iterator_004( );
daw_circular_iterator_005( );
daw_circular_iterator_006( );
daw_circular_iterator_007( );
daw_circular_iterator_008( );
daw_circular_iterator_009( );
daw_circular_iterator_010( );
daw_circular_iterator_011( );
daw_circular_iterator_012( );
daw_circular_iterator_013( );
}