Sort a few more #include lines in tools/... unittests/... and utils/...
[oota-llvm.git] / unittests / ADT / ilistTest.cpp
1 //===- llvm/unittest/ADT/APInt.cpp - APInt unit tests ---------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "llvm/ADT/ilist.h"
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/ADT/ilist_node.h"
13 #include "gtest/gtest.h"
14 #include <ostream>
15
16 using namespace llvm;
17
18 namespace {
19
20 struct Node : ilist_node<Node> {
21   int Value;
22
23   Node() {}
24   Node(int _Value) : Value(_Value) {}
25 };
26
27 TEST(ilistTest, Basic) {
28   ilist<Node> List;
29   List.push_back(Node(1));
30   EXPECT_EQ(1, List.back().Value);
31   EXPECT_EQ(0, List.back().getPrevNode());
32   EXPECT_EQ(0, List.back().getNextNode());
33
34   List.push_back(Node(2));
35   EXPECT_EQ(2, List.back().Value);
36   EXPECT_EQ(2, List.front().getNextNode()->Value);
37   EXPECT_EQ(1, List.back().getPrevNode()->Value);
38
39   const ilist<Node> &ConstList = List;
40   EXPECT_EQ(2, ConstList.back().Value);
41   EXPECT_EQ(2, ConstList.front().getNextNode()->Value);
42   EXPECT_EQ(1, ConstList.back().getPrevNode()->Value);
43 }
44
45 TEST(ilistTest, SpliceOne) {
46   ilist<Node> List;
47   List.push_back(1);
48
49   // The single-element splice operation supports noops.
50   List.splice(List.begin(), List, List.begin());
51   EXPECT_EQ(1u, List.size());
52   EXPECT_EQ(1, List.front().Value);
53   EXPECT_TRUE(llvm::next(List.begin()) == List.end());
54
55   // Altenative noop. Move the first element behind itself.
56   List.push_back(2);
57   List.push_back(3);
58   List.splice(llvm::next(List.begin()), List, List.begin());
59   EXPECT_EQ(3u, List.size());
60   EXPECT_EQ(1, List.front().Value);
61   EXPECT_EQ(2, llvm::next(List.begin())->Value);
62   EXPECT_EQ(3, List.back().Value);
63 }
64
65 }