mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-12 13:30:51 +00:00
Support: Add unit tests for BranchProbability
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207540 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4b26377660
commit
4afab2afa8
90
unittests/Support/BranchProbabilityTest.cpp
Normal file
90
unittests/Support/BranchProbabilityTest.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
//===- unittest/Support/BranchProbabilityTest.cpp - BranchProbability tests -=//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Support/BranchProbability.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace llvm {
|
||||
void PrintTo(const BranchProbability &P, ::std::ostream *os) {
|
||||
*os << P.getNumerator() << "/" << P.getDenominator();
|
||||
}
|
||||
}
|
||||
namespace {
|
||||
|
||||
typedef BranchProbability BP;
|
||||
TEST(BranchProbabilityTest, Accessors) {
|
||||
EXPECT_EQ(1u, BP(1, 7).getNumerator());
|
||||
EXPECT_EQ(7u, BP(1, 7).getDenominator());
|
||||
EXPECT_EQ(0u, BP::getZero().getNumerator());
|
||||
EXPECT_EQ(1u, BP::getZero().getDenominator());
|
||||
EXPECT_EQ(1u, BP::getOne().getNumerator());
|
||||
EXPECT_EQ(1u, BP::getOne().getDenominator());
|
||||
}
|
||||
|
||||
TEST(BranchProbabilityTest, Operators) {
|
||||
EXPECT_TRUE(BP(1, 7) < BP(2, 7));
|
||||
EXPECT_TRUE(BP(1, 7) < BP(1, 4));
|
||||
EXPECT_TRUE(BP(5, 7) < BP(3, 4));
|
||||
EXPECT_FALSE(BP(1, 7) < BP(1, 7));
|
||||
EXPECT_FALSE(BP(1, 7) < BP(2, 14));
|
||||
EXPECT_FALSE(BP(4, 7) < BP(1, 2));
|
||||
EXPECT_FALSE(BP(4, 7) < BP(3, 7));
|
||||
|
||||
EXPECT_FALSE(BP(1, 7) > BP(2, 7));
|
||||
EXPECT_FALSE(BP(1, 7) > BP(1, 4));
|
||||
EXPECT_FALSE(BP(5, 7) > BP(3, 4));
|
||||
EXPECT_FALSE(BP(1, 7) > BP(1, 7));
|
||||
EXPECT_FALSE(BP(1, 7) > BP(2, 14));
|
||||
EXPECT_TRUE(BP(4, 7) > BP(1, 2));
|
||||
EXPECT_TRUE(BP(4, 7) > BP(3, 7));
|
||||
|
||||
EXPECT_TRUE(BP(1, 7) <= BP(2, 7));
|
||||
EXPECT_TRUE(BP(1, 7) <= BP(1, 4));
|
||||
EXPECT_TRUE(BP(5, 7) <= BP(3, 4));
|
||||
EXPECT_TRUE(BP(1, 7) <= BP(1, 7));
|
||||
EXPECT_TRUE(BP(1, 7) <= BP(2, 14));
|
||||
EXPECT_FALSE(BP(4, 7) <= BP(1, 2));
|
||||
EXPECT_FALSE(BP(4, 7) <= BP(3, 7));
|
||||
|
||||
EXPECT_FALSE(BP(1, 7) >= BP(2, 7));
|
||||
EXPECT_FALSE(BP(1, 7) >= BP(1, 4));
|
||||
EXPECT_FALSE(BP(5, 7) >= BP(3, 4));
|
||||
EXPECT_TRUE(BP(1, 7) >= BP(1, 7));
|
||||
EXPECT_TRUE(BP(1, 7) >= BP(2, 14));
|
||||
EXPECT_TRUE(BP(4, 7) >= BP(1, 2));
|
||||
EXPECT_TRUE(BP(4, 7) >= BP(3, 7));
|
||||
|
||||
EXPECT_FALSE(BP(1, 7) == BP(2, 7));
|
||||
EXPECT_FALSE(BP(1, 7) == BP(1, 4));
|
||||
EXPECT_FALSE(BP(5, 7) == BP(3, 4));
|
||||
EXPECT_TRUE(BP(1, 7) == BP(1, 7));
|
||||
EXPECT_TRUE(BP(1, 7) == BP(2, 14));
|
||||
EXPECT_FALSE(BP(4, 7) == BP(1, 2));
|
||||
EXPECT_FALSE(BP(4, 7) == BP(3, 7));
|
||||
|
||||
EXPECT_TRUE(BP(1, 7) != BP(2, 7));
|
||||
EXPECT_TRUE(BP(1, 7) != BP(1, 4));
|
||||
EXPECT_TRUE(BP(5, 7) != BP(3, 4));
|
||||
EXPECT_FALSE(BP(1, 7) != BP(1, 7));
|
||||
EXPECT_FALSE(BP(1, 7) != BP(2, 14));
|
||||
EXPECT_TRUE(BP(4, 7) != BP(1, 2));
|
||||
EXPECT_TRUE(BP(4, 7) != BP(3, 7));
|
||||
}
|
||||
|
||||
TEST(BranchProbabilityTest, getCompl) {
|
||||
EXPECT_EQ(BP(5, 7), BP(2, 7).getCompl());
|
||||
EXPECT_EQ(BP(2, 7), BP(5, 7).getCompl());
|
||||
EXPECT_EQ(BP::getZero(), BP(7, 7).getCompl());
|
||||
EXPECT_EQ(BP::getOne(), BP(0, 7).getCompl());
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ add_llvm_unittest(SupportTests
|
||||
AllocatorTest.cpp
|
||||
ArrayRecyclerTest.cpp
|
||||
BlockFrequencyTest.cpp
|
||||
BranchProbabilityTest.cpp
|
||||
Casting.cpp
|
||||
CommandLineTest.cpp
|
||||
CompressionTest.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user