[Alignment][NFC] Migrate Instructions to Align
[llvm-core.git] / unittests / ADT / PackedVectorTest.cpp
blob24df398934670b75f051881ef717cc5c4461888f
1 //===- llvm/unittest/ADT/PackedVectorTest.cpp - PackedVector tests --------===//
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 //===----------------------------------------------------------------------===//
9 // BitVectorTest tests fail on PowerPC for unknown reasons, so disable this
10 // as well since it depends on a BitVector.
11 #ifndef __ppc__
13 #include "llvm/ADT/PackedVector.h"
14 #include "gtest/gtest.h"
16 using namespace llvm;
18 namespace {
20 TEST(PackedVectorTest, Operation) {
21 PackedVector<unsigned, 2> Vec;
22 EXPECT_EQ(0U, Vec.size());
23 EXPECT_TRUE(Vec.empty());
25 Vec.resize(5);
26 EXPECT_EQ(5U, Vec.size());
27 EXPECT_FALSE(Vec.empty());
29 Vec.resize(11);
30 EXPECT_EQ(11U, Vec.size());
31 EXPECT_FALSE(Vec.empty());
33 PackedVector<unsigned, 2> Vec2(3);
34 EXPECT_EQ(3U, Vec2.size());
35 EXPECT_FALSE(Vec2.empty());
37 Vec.clear();
38 EXPECT_EQ(0U, Vec.size());
39 EXPECT_TRUE(Vec.empty());
41 Vec.push_back(2);
42 Vec.push_back(0);
43 Vec.push_back(1);
44 Vec.push_back(3);
46 EXPECT_EQ(2U, Vec[0]);
47 EXPECT_EQ(0U, Vec[1]);
48 EXPECT_EQ(1U, Vec[2]);
49 EXPECT_EQ(3U, Vec[3]);
51 EXPECT_FALSE(Vec == Vec2);
52 EXPECT_TRUE(Vec != Vec2);
54 Vec = Vec2;
55 EXPECT_TRUE(Vec == Vec2);
56 EXPECT_FALSE(Vec != Vec2);
58 Vec[1] = 1;
59 Vec2[1] = 2;
60 Vec |= Vec2;
61 EXPECT_EQ(3U, Vec[1]);
64 #ifdef EXPECT_DEBUG_DEATH
66 TEST(PackedVectorTest, UnsignedValues) {
67 PackedVector<unsigned, 2> Vec(1);
68 Vec[0] = 0;
69 Vec[0] = 1;
70 Vec[0] = 2;
71 Vec[0] = 3;
72 EXPECT_DEBUG_DEATH(Vec[0] = 4, "value is too big");
73 EXPECT_DEBUG_DEATH(Vec[0] = -1, "value is too big");
74 EXPECT_DEBUG_DEATH(Vec[0] = 0x100, "value is too big");
76 PackedVector<unsigned, 3> Vec2(1);
77 Vec2[0] = 0;
78 Vec2[0] = 7;
79 EXPECT_DEBUG_DEATH(Vec[0] = 8, "value is too big");
82 TEST(PackedVectorTest, SignedValues) {
83 PackedVector<signed, 2> Vec(1);
84 Vec[0] = -2;
85 Vec[0] = -1;
86 Vec[0] = 0;
87 Vec[0] = 1;
88 EXPECT_DEBUG_DEATH(Vec[0] = -3, "value is too big");
89 EXPECT_DEBUG_DEATH(Vec[0] = 2, "value is too big");
91 PackedVector<signed, 3> Vec2(1);
92 Vec2[0] = -4;
93 Vec2[0] = 3;
94 EXPECT_DEBUG_DEATH(Vec[0] = -5, "value is too big");
95 EXPECT_DEBUG_DEATH(Vec[0] = 4, "value is too big");
98 #endif
102 #endif