1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +01:00
llvm-mirror/unittests/ADT/EquivalenceClassesTest.cpp
Chandler Carruth ae65e281f3 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00

85 lines
2.5 KiB
C++

//=== llvm/unittest/ADT/EquivalenceClassesTest.cpp - the structure 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/EquivalenceClasses.h"
#include "gtest/gtest.h"
using namespace llvm;
namespace llvm {
TEST(EquivalenceClassesTest, NoMerges) {
EquivalenceClasses<int> EqClasses;
// Until we merged any sets, check that every element is only equivalent to
// itself.
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
if (i == j)
EXPECT_TRUE(EqClasses.isEquivalent(i, j));
else
EXPECT_FALSE(EqClasses.isEquivalent(i, j));
}
TEST(EquivalenceClassesTest, SimpleMerge1) {
EquivalenceClasses<int> EqClasses;
// Check that once we merge (A, B), (B, C), (C, D), then all elements belong
// to one set.
EqClasses.unionSets(0, 1);
EqClasses.unionSets(1, 2);
EqClasses.unionSets(2, 3);
for (int i = 0; i < 4; ++i)
for (int j = 0; j < 4; ++j)
EXPECT_TRUE(EqClasses.isEquivalent(i, j));
}
TEST(EquivalenceClassesTest, SimpleMerge2) {
EquivalenceClasses<int> EqClasses;
// Check that once we merge (A, B), (C, D), (A, C), then all elements belong
// to one set.
EqClasses.unionSets(0, 1);
EqClasses.unionSets(2, 3);
EqClasses.unionSets(0, 2);
for (int i = 0; i < 4; ++i)
for (int j = 0; j < 4; ++j)
EXPECT_TRUE(EqClasses.isEquivalent(i, j));
}
TEST(EquivalenceClassesTest, TwoSets) {
EquivalenceClasses<int> EqClasses;
// Form sets of odd and even numbers, check that we split them into these
// two sets correcrly.
for (int i = 0; i < 30; i += 2)
EqClasses.unionSets(0, i);
for (int i = 1; i < 30; i += 2)
EqClasses.unionSets(1, i);
for (int i = 0; i < 30; i++)
for (int j = 0; j < 30; j++)
if (i % 2 == j % 2)
EXPECT_TRUE(EqClasses.isEquivalent(i, j));
else
EXPECT_FALSE(EqClasses.isEquivalent(i, j));
}
TEST(EquivalenceClassesTest, MultipleSets) {
EquivalenceClasses<int> EqClasses;
// Split numbers from [0, 100) into sets so that values in the same set have
// equal remainders (mod 17).
for (int i = 0; i < 100; i++)
EqClasses.unionSets(i % 17, i);
for (int i = 0; i < 100; i++)
for (int j = 0; j < 100; j++)
if (i % 17 == j % 17)
EXPECT_TRUE(EqClasses.isEquivalent(i, j));
else
EXPECT_FALSE(EqClasses.isEquivalent(i, j));
}
} // llvm