1 //===- SequenceTest.cpp - Unit tests for a sequence abstraciton -----------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "llvm/ADT/Sequence.h" 10 #include "gtest/gtest.h" 11 12 #include <list> 13 14 using namespace llvm; 15 16 namespace { 17 18 TEST(SequenceTest, Forward) { 19 int X = 0; 20 for (int I : seq(0, 10)) { 21 EXPECT_EQ(X, I); 22 ++X; 23 } 24 EXPECT_EQ(10, X); 25 } 26 27 TEST(SequenceTest, Backward) { 28 int X = 9; 29 for (int I : reverse(seq(0, 10))) { 30 EXPECT_EQ(X, I); 31 --X; 32 } 33 EXPECT_EQ(-1, X); 34 } 35 36 TEST(SequenceTest, Distance) { 37 const auto Forward = seq(0, 10); 38 EXPECT_EQ(std::distance(Forward.begin(), Forward.end()), 10); 39 EXPECT_EQ(std::distance(Forward.rbegin(), Forward.rend()), 10); 40 } 41 42 TEST(SequenceTest, Dereference) { 43 const auto Forward = seq(0, 10).begin(); 44 EXPECT_EQ(Forward[0], 0); 45 EXPECT_EQ(Forward[2], 2); 46 const auto Backward = seq(0, 10).rbegin(); 47 EXPECT_EQ(Backward[0], 9); 48 EXPECT_EQ(Backward[2], 7); 49 } 50 51 } // anonymous namespace 52