forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixed_flat_set_unittest.cc
37 lines (30 loc) · 1.35 KB
/
fixed_flat_set_unittest.cc
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
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/containers/fixed_flat_set.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_piece.h"
#include "base/test/gtest_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
TEST(FixedFlatSetTest, MakeFixedFlatSet_SortedInput) {
constexpr auto kSet = MakeFixedFlatSet<int>({1, 2, 3, 4});
static_assert(ranges::is_sorted(kSet), "Error: Set is not sorted.");
static_assert(ranges::adjacent_find(kSet) == kSet.end(),
"Error: Set contains repeated elements.");
EXPECT_THAT(kSet, ::testing::ElementsAre(1, 2, 3, 4));
}
TEST(FixedFlatSetTest, MakeFixedFlatSet_UnsortedInput) {
constexpr auto kSet = MakeFixedFlatSet<StringPiece>({"foo", "bar", "baz"});
static_assert(ranges::is_sorted(kSet), "Error: Set is not sorted.");
static_assert(ranges::adjacent_find(kSet) == kSet.end(),
"Error: Set contains repeated elements.");
EXPECT_THAT(kSet, ::testing::ElementsAre("bar", "baz", "foo"));
}
// Verifies that passing repeated keys to MakeFixedFlatSet results in a CHECK
// failure.
TEST(FixedFlatSetTest, RepeatedKeys) {
EXPECT_CHECK_DEATH(MakeFixedFlatSet<int>({1, 2, 3, 1}));
}
} // namespace base