summaryrefslogtreecommitdiff
path: root/Source/UnitTests/Common/MathUtilTest.cpp
blob: c0609bbb922cc938a4b3f351dd04d397a1773c43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2014 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <gtest/gtest.h>

#include "Common/MathUtil.h"

TEST(MathUtil, IntLog2)
{
  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));

  // Rounding behavior.
  EXPECT_EQ(3, IntLog2(15));
  EXPECT_EQ(63, IntLog2(0xFFFFFFFFFFFFFFFFull));
}

TEST(MathUtil, NextPowerOf2)
{
  EXPECT_EQ(4U, MathUtil::NextPowerOf2(3));
  EXPECT_EQ(4U, MathUtil::NextPowerOf2(4));
  EXPECT_EQ(8U, MathUtil::NextPowerOf2(6));
  EXPECT_EQ(0x40000000U, MathUtil::NextPowerOf2(0x23456789));
}