-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathunique.cpp
More file actions
73 lines (63 loc) · 1.99 KB
/
unique.cpp
File metadata and controls
73 lines (63 loc) · 1.99 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
#include <algorithm>
#include <vector>
#include <random>
#include "ut.hpp"
#include "ut_proto.hpp"
#include "meta/typelist.hpp"
#include "meta/unique.hpp"
#include "sl/octet_info.hpp"
TEST(unique, typed)
{
//checking tag uniqueness
using tags = med::meta::typelist<
med::add_meta_info< med::add_tag<C<0x02>> >,
med::add_meta_info< med::add_tag<C<0x03>> >,
med::add_meta_info< med::add_tag<C<0x04>> >
>;
static_assert(std::is_void_v<med::meta::unique_t<med::tag_getter<med::sl::octet_info>, tags>>);
//fails to compile with duplicate tag in error message
// using dup_tags = med::meta::typelist<
// med::add_meta_info< med::add_tag<C<0x02>> >,
// med::add_meta_info< med::add_tag<C<0x03>> >,
// med::add_meta_info< med::add_tag<C<0x04>> >,
// med::add_meta_info< med::add_tag<C<0x05>> >,
// med::add_meta_info< med::add_tag<C<0x04>> >
// >;
// static_assert(not std::is_void_v<med::meta::unique_t<med::tag_getter<med::sl::octet_info>, dup_tags>>);
}
TEST(unique, static_odd)
{
using namespace med::meta;
static_assert(are_unique(nullptr, 1u, 2, 3, 4, 5));
static_assert(are_unique(1u, 2, 3, nullptr, 4, 5));
static_assert(are_unique(1u, 2, 3, 4, 5, nullptr));
static_assert(not are_unique(5, 2, 3, 4, 5));
static_assert(not are_unique(1, 5, 3, 4, 5));
static_assert(not are_unique(1, 2, 5, 4, 5));
static_assert(not are_unique(1, 2, 3, 5, 5));
}
TEST(unique, static_even)
{
using namespace med::meta;
static_assert(are_unique(1, 2, 3, 4));
static_assert(not are_unique(4, 2, 3, 4));
static_assert(not are_unique(1, 4, 3, 4));
static_assert(not are_unique(1, 2, 4, 4));
}
TEST(unique, dynamics)
{
std::random_device rdev;
std::mt19937 rgen{rdev()};
std::vector<int> v{1, 2, 3, 4, 5};
for (auto i = 0; i < 5; ++i)
{
std::shuffle(v.begin(), v.end(), rgen);
EXPECT_TRUE(med::meta::are_unique(v[0], v[1], v[2], v[3], v[4]));
}
v = {1, 2, 3, 4, 1};
for (auto i = 0; i < 5; ++i)
{
std::shuffle(v.begin(), v.end(), rgen);
EXPECT_FALSE(med::meta::are_unique(v[0], v[1], v[2], v[3], v[4]));
}
}