2014-03-09 13:27:04 +00:00
|
|
|
// Copyright 2014 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2014-03-09 13:27:04 +00:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
#include <gtest/gtest.h>
|
2014-03-09 13:27:04 +00:00
|
|
|
|
|
|
|
#include "Common/MathUtil.h"
|
|
|
|
|
|
|
|
TEST(MathUtil, Clamp)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
EXPECT_EQ(1, MathUtil::Clamp(1, 0, 2));
|
|
|
|
EXPECT_EQ(1.0, MathUtil::Clamp(1.0, 0.0, 2.0));
|
2014-03-09 13:27:04 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
EXPECT_EQ(2, MathUtil::Clamp(4, 0, 2));
|
|
|
|
EXPECT_EQ(2.0, MathUtil::Clamp(4.0, 0.0, 2.0));
|
2014-03-09 13:27:04 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
EXPECT_EQ(0, MathUtil::Clamp(-1, 0, 2));
|
|
|
|
EXPECT_EQ(0.0, MathUtil::Clamp(-1.0, 0.0, 2.0));
|
2014-03-09 13:27:04 +00:00
|
|
|
}
|
|
|
|
|
2014-08-24 18:03:07 +00:00
|
|
|
TEST(MathUtil, IntLog2)
|
2014-03-09 13:27:04 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
EXPECT_EQ(0, IntLog2(1));
|
|
|
|
EXPECT_EQ(1, IntLog2(2));
|
|
|
|
EXPECT_EQ(2, IntLog2(4));
|
|
|
|
EXPECT_EQ(3, IntLog2(8));
|
|
|
|
EXPECT_EQ(63, IntLog2(0x8000000000000000ull));
|
2014-03-09 13:27:04 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// Rounding behavior.
|
|
|
|
EXPECT_EQ(3, IntLog2(15));
|
|
|
|
EXPECT_EQ(63, IntLog2(0xFFFFFFFFFFFFFFFFull));
|
2014-03-09 13:27:04 +00:00
|
|
|
}
|
2018-05-10 23:06:19 +00:00
|
|
|
|
|
|
|
TEST(MathUtil, NextPowerOf2)
|
|
|
|
{
|
2018-06-12 13:10:07 +00:00
|
|
|
EXPECT_EQ(4U, MathUtil::NextPowerOf2(3));
|
|
|
|
EXPECT_EQ(4U, MathUtil::NextPowerOf2(4));
|
|
|
|
EXPECT_EQ(8U, MathUtil::NextPowerOf2(6));
|
|
|
|
EXPECT_EQ(0x40000000U, MathUtil::NextPowerOf2(0x23456789));
|
2018-05-10 23:06:19 +00:00
|
|
|
}
|