1*62914546SAlex Brachet //===-- Unittests for IntegerSequence -------------------------------------===//
2*62914546SAlex Brachet //
3*62914546SAlex Brachet // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*62914546SAlex Brachet // See https://llvm.org/LICENSE.txt for license information.
5*62914546SAlex Brachet // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*62914546SAlex Brachet //
7*62914546SAlex Brachet //===----------------------------------------------------------------------===//
8*62914546SAlex Brachet 
9*62914546SAlex Brachet #include "src/__support/CPP/Utility.h"
10*62914546SAlex Brachet #include "utils/UnitTest/Test.h"
11*62914546SAlex Brachet 
12*62914546SAlex Brachet using namespace __llvm_libc::cpp;
13*62914546SAlex Brachet 
TEST(LlvmLibcIntegerSequencetTest,Basic)14*62914546SAlex Brachet TEST(LlvmLibcIntegerSequencetTest, Basic) {
15*62914546SAlex Brachet   EXPECT_TRUE((IsSameV<IntegerSequence<int>, MakeIntegerSequence<int, 0>>));
16*62914546SAlex Brachet   using ISeq = IntegerSequence<int, 0, 1, 2, 3>;
17*62914546SAlex Brachet   EXPECT_TRUE((IsSameV<ISeq, MakeIntegerSequence<int, 4>>));
18*62914546SAlex Brachet   using LSeq = IntegerSequence<long, 0, 1, 2, 3>;
19*62914546SAlex Brachet   EXPECT_TRUE((IsSameV<LSeq, MakeIntegerSequence<long, 4>>));
20*62914546SAlex Brachet   using ULLSeq = IntegerSequence<unsigned long long, 0ull, 1ull, 2ull, 3ull>;
21*62914546SAlex Brachet   EXPECT_TRUE((IsSameV<ULLSeq, MakeIntegerSequence<unsigned long long, 4>>));
22*62914546SAlex Brachet }
23*62914546SAlex Brachet 
24*62914546SAlex Brachet template <typename T, T... Ts>
checkArray(IntegerSequence<T,Ts...> seq)25*62914546SAlex Brachet bool checkArray(IntegerSequence<T, Ts...> seq) {
26*62914546SAlex Brachet   T arr[sizeof...(Ts)]{Ts...};
27*62914546SAlex Brachet 
28*62914546SAlex Brachet   for (T i = 0; i < static_cast<T>(sizeof...(Ts)); i++)
29*62914546SAlex Brachet     if (arr[i] != i)
30*62914546SAlex Brachet       return false;
31*62914546SAlex Brachet 
32*62914546SAlex Brachet   return true;
33*62914546SAlex Brachet }
34*62914546SAlex Brachet 
TEST(LlvmLibcIntegerSequencetTest,Many)35*62914546SAlex Brachet TEST(LlvmLibcIntegerSequencetTest, Many) {
36*62914546SAlex Brachet   EXPECT_TRUE(checkArray(MakeIntegerSequence<int, 100>{}));
37*62914546SAlex Brachet }
38