-
Notifications
You must be signed in to change notification settings - Fork 0
/
enumerate.tpp
112 lines (91 loc) · 3.44 KB
/
enumerate.tpp
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
#include <iostream>
#include <iomanip>
#include "brick-unit"
#include "brick-nat"
#include "brick-enumerate"
#include <set>
auto enum_prefix( auto expect, auto do_enum )
{
return [=]
{
decltype( expect ) enumerated;
using elem_t = std::decay_t< decltype( *expect.begin() ) >;
for ( int i = 0; i < expect.size(); ++i )
{
elem_t elem = do_enum( i );
ASSERT( !enumerated.contains( elem ), i, elem );
enumerated.insert( elem );
}
for ( auto i : enumerated )
if ( !expect.contains( i ) )
DEBUG( "extra: ", i );
for ( auto i : expect )
if ( !enumerated.contains( i ) )
DEBUG( "missing: ", i );
ASSERT_EQ( expect, enumerated );
};
}
int main()
{
using t2_t = std::array< brq::nat, 2 >;
using t3_t = std::array< brq::nat, 3 >;
using list_t = std::vector< brq::nat >;
std::set< t2_t > t2_b_33 =
{
{ 0, 0 },
{ 0, 1 }, { 1, 0 }, { 1, 1 },
{ 0, 2 }, { 1, 2 }, { 2, 0 }, { 2, 1 }, { 2, 2 }
};
std::set< t2_t > t2_b_26 =
{
{ 0, 0 }, { 0, 1 }, { 1, 0 }, { 1, 1 },
{ 0, 2 }, { 1, 2 }, { 0, 3 }, { 1, 3 },
{ 0, 4 }, { 1, 4 }, { 0, 5 }, { 1, 5 }
};
std::set< t2_t > t2_b_62 =
{
{ 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 },
{ 2, 0 }, { 2, 1 }, { 3, 0 }, { 3, 1 },
{ 4, 0 }, { 4, 1 }, { 5, 0 }, { 5, 1 }
};
std::set< t3_t > t3_b_223 =
{
{ 0, 0, 0 }, { 0, 0, 1 }, { 0, 1, 0 }, { 0, 1, 1 },
{ 1, 0, 0 }, { 1, 0, 1 }, { 1, 1, 0 }, { 1, 1, 1 },
{ 0, 0, 2 }, { 0, 1, 2 }, { 1, 0, 2 }, { 1, 1, 2 }
};
std::set< list_t > lists =
{
{}, { 0 }, { 1 }, { 0, 0 }, { 0, 1 }, { 1, 0 }, { 1, 1 },
{ 2 }, { 0, 2 }, { 1, 2 }, { 2, 0 }, { 2, 1 }, { 2, 2 },
{ 3 }, { 0, 3 }, { 1, 3 }, { 2, 3 }, { 3, 0 }, { 3, 1 }, { 3, 2 }, { 3, 3 },
{ 0, 0, 0 }, { 0, 0, 1 }, { 0, 1, 0 }, { 0, 1, 1 },
{ 1, 0, 0 }, { 1, 1, 0 }, { 1, 0, 1 }, { 1, 1, 1 },
{ 0, 0, 2 }, { 1, 0, 2 }, { 0, 1, 2 }, { 1, 1, 2 },
{ 0, 2, 0 }, { 1, 2, 0 }, { 0, 2, 1 }, { 1, 2, 1 },
{ 0, 2, 2 }, { 1, 2, 2 }, { 2, 0, 0 }, { 2, 1, 0 },
{ 2, 2, 0 }, { 2, 0, 1 }, { 2, 1, 1 }, { 2, 2, 1 },
{ 2, 0, 2 }, { 2, 1, 2 }, { 2, 2, 2 }
};
std::set< list_t > sets_3 =
{
{}, { 0 }, { 1 }, { 0, 1 }, { 2 }, { 0, 2 }, { 1, 2 }, { 0, 1, 2 }
};
using namespace brq::enumerate;
brq::test_case( "tuple 2" ) =
enum_prefix( t2_b_33, []( auto i ) { return tuple< 2 >( i ); } );
brq::test_case( "tuple 2 bounded (3, 3)" ) =
enum_prefix( t2_b_33, []( auto i ) { return tuple< 2 >( i ); } );
brq::test_case( "tuple 3 bounded (2, 2, 3)" ) =
enum_prefix( t3_b_223, []( auto i ) { return tuple< 3 >( i, std::array{ 2, 2, 3 } ); } );
brq::test_case( "tuple 2 bounded (2, 6)" ) =
enum_prefix( t2_b_26, []( auto i ) { return tuple< 2 >( i, std::array{ 2, 6 } ); } );
brq::test_case( "tuple 2 bounded (6, 2)" ) =
enum_prefix( t2_b_62, []( auto i ) { return tuple< 2 >( i, std::array{ 6, 2 } ); } );
brq::test_case( "list" ) =
enum_prefix( lists, []( auto i ) { return list( i ); } );
brq::test_case( "sets" ) =
enum_prefix( sets_3, []( auto i ) { return set( i ); } );
brq::test_case( "ints" ) =
enum_prefix( std::set{ 0, -1, 1, -2, 2 }, []( auto i ) { return integer( i ); } );
}