CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
101 lines
2.6 KiB
C++
101 lines
2.6 KiB
C++
//===- RepeatedTest.cpp - Repeated unit tests -----------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ADT/Repeated.h"
|
|
#include "gmock/gmock.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
using ::testing::Each;
|
|
using ::testing::ElementsAre;
|
|
using ::testing::IsEmpty;
|
|
using ::testing::SizeIs;
|
|
|
|
namespace llvm {
|
|
namespace {
|
|
|
|
TEST(RepeatedTest, Construction) {
|
|
{
|
|
Repeated<int> Rep(5, 42);
|
|
EXPECT_EQ(Rep.value(), 42);
|
|
EXPECT_THAT(Rep, SizeIs(5));
|
|
EXPECT_EQ(Rep[0], 42);
|
|
EXPECT_EQ(Rep[4], 42);
|
|
EXPECT_THAT(Rep, ElementsAre(42, 42, 42, 42, 42));
|
|
}
|
|
|
|
{
|
|
Repeated<std::string> Rep(3, "hello");
|
|
EXPECT_EQ(Rep.value(), "hello");
|
|
EXPECT_THAT(Rep, SizeIs(3));
|
|
}
|
|
|
|
{
|
|
// Move-only type.
|
|
Repeated<std::unique_ptr<int>> Rep(1, std::make_unique<int>(42));
|
|
EXPECT_EQ(*Rep.value(), 42);
|
|
EXPECT_THAT(Rep, SizeIs(1));
|
|
}
|
|
|
|
{
|
|
// Empty Rep.
|
|
Repeated<int> EmptyRep(0, 42);
|
|
EXPECT_THAT(EmptyRep, IsEmpty());
|
|
}
|
|
}
|
|
|
|
TEST(RepeatedTest, CTAD) {
|
|
static_assert(std::is_same_v<decltype(Repeated(3, 42)), Repeated<int>>);
|
|
std::string S = "world";
|
|
Repeated RepStr(2, S);
|
|
static_assert(std::is_same_v<decltype(RepStr), Repeated<std::string>>);
|
|
static_assert(
|
|
std::is_same_v<decltype(Repeated(1, "literal")), Repeated<const char *>>);
|
|
SUCCEED();
|
|
}
|
|
|
|
TEST(RepeatedTest, IteratorRandomAccess) {
|
|
Repeated<int> Rep(10, 7);
|
|
RepeatedIterator<int> It = Rep.begin();
|
|
|
|
EXPECT_EQ(*It, 7);
|
|
EXPECT_EQ(*(It + 5), 7);
|
|
|
|
It += 10;
|
|
EXPECT_EQ(It, Rep.end());
|
|
--It;
|
|
EXPECT_LT(It, Rep.end());
|
|
EXPECT_EQ(Rep.end() - Rep.begin(), 10);
|
|
++It;
|
|
EXPECT_EQ(It, Rep.end());
|
|
}
|
|
|
|
TEST(RepeatedTest, ReverseIterator) {
|
|
Repeated<int> Rep(5, 42);
|
|
std::vector<int> Reversed(Rep.rbegin(), Rep.rend());
|
|
EXPECT_THAT(Reversed, SizeIs(5));
|
|
EXPECT_THAT(Reversed, Each(42));
|
|
}
|
|
|
|
TEST(RepeatedTest, IteratorTraits) {
|
|
using It = RepeatedIterator<int>;
|
|
static_assert(std::is_default_constructible_v<It>);
|
|
static_assert(std::is_same_v<std::iterator_traits<It>::iterator_category,
|
|
std::random_access_iterator_tag>);
|
|
static_assert(std::is_same_v<std::iterator_traits<It>::value_type, int>);
|
|
static_assert(
|
|
std::is_same_v<std::iterator_traits<It>::difference_type, ptrdiff_t>);
|
|
SUCCEED();
|
|
}
|
|
|
|
} // anonymous namespace
|
|
} // namespace llvm
|