-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdaw_iterator_argument_iterator_test.cpp
More file actions
81 lines (68 loc) · 2.12 KB
/
daw_iterator_argument_iterator_test.cpp
File metadata and controls
81 lines (68 loc) · 2.12 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
// 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_argument_iterator.h"
#include "daw/daw_benchmark.h"
#include <cstddef>
#include <numeric>
#include <string_view>
void test_end_001( ) {
constexpr auto last = daw::arg_iterator_t( );
daw::expecting( !last );
}
void test_range_001( ) {
constexpr char const *argv_[] = { "test", "this", "out" };
auto const args = daw::arg_iterator_t( 3, argv_ );
daw::expecting( 3U, args.size( ) );
daw::expecting( 0U, args.position( ) );
}
void test_prefix_inc_001( ) {
constexpr char const *argv_[] = { "test", "this", "out" };
auto args = daw::arg_iterator_t( 3, argv_ );
++args;
daw::expecting( 3U, args.size( ) );
daw::expecting( 1U, args.position( ) );
daw::expecting( args != args.end( ) );
}
void test_postfix_inc_001( ) {
constexpr char const *argv_[] = { "test", "this", "out" };
auto args = daw::arg_iterator_t( 3, argv_ );
auto old_args = args++;
daw::expecting( 3U, args.size( ) );
daw::expecting( 1U, args.position( ) );
daw::expecting( 3U, old_args.size( ) );
daw::expecting( 0U, old_args.position( ) );
daw::expecting( args != old_args );
daw::expecting( args != args.end( ) );
daw::expecting( old_args != old_args.end( ) );
}
void test_accumulate_001( ) {
constexpr char const *argv_[] = { "test", "this", "out" };
auto const args = daw::arg_iterator_t( 3, argv_ );
auto result =
std::accumulate( args.begin( ), args.end( ), 0, []( int i, auto &&sv ) {
return i + sv[0];
} );
daw::expecting( result, 't' + 't' + 'o' );
}
void test_index_001( ) {
constexpr char const *argv_[] = { "test", "this", "out" };
auto args = daw::arg_iterator_t( 3, argv_ );
int sum = 0;
for( int n = 0; n < static_cast<int>( args.size( ) ); ++n ) {
sum += args[n][0];
}
daw::expecting( sum, 't' + 't' + 'o' );
}
int main( ) {
test_end_001( );
test_range_001( );
test_prefix_inc_001( );
test_postfix_inc_001( );
test_accumulate_001( );
test_index_001( );
}