aboutsummaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authorErick Tryzelaar <idadesub@users.sourceforge.net>2009-08-21 03:15:28 +0000
committerErick Tryzelaar <idadesub@users.sourceforge.net>2009-08-21 03:15:28 +0000
commitae8f78d4de403965603ed2b61898d820db2449f9 (patch)
treeddc274606143a4aa9f246ba9e1b1498088696905 /unittests
parentbb97531a5a13c9d5b2f04b3b714037b1eff7e9a9 (diff)
downloadexternal_llvm-ae8f78d4de403965603ed2b61898d820db2449f9.zip
external_llvm-ae8f78d4de403965603ed2b61898d820db2449f9.tar.gz
external_llvm-ae8f78d4de403965603ed2b61898d820db2449f9.tar.bz2
Fix bug with APInt::getBitsNeeded with for base 10 numbers 0-9.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79593 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ADT/APIntTest.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp
index 8208af3..0e094ff 100644
--- a/unittests/ADT/APIntTest.cpp
+++ b/unittests/ADT/APIntTest.cpp
@@ -235,6 +235,88 @@ TEST(APIntTest, fromString) {
EXPECT_EQ(APInt(32, -32), APInt(32, "-20", 16));
}
+TEST(APIntTest, StringBitsNeeded2) {
+ EXPECT_EQ(1U, APInt::getBitsNeeded( "0", 2));
+ EXPECT_EQ(1U, APInt::getBitsNeeded( "1", 2));
+ EXPECT_EQ(2U, APInt::getBitsNeeded( "10", 2));
+ EXPECT_EQ(2U, APInt::getBitsNeeded( "11", 2));
+ EXPECT_EQ(3U, APInt::getBitsNeeded("100", 2));
+
+ EXPECT_EQ(1U, APInt::getBitsNeeded( "+0", 2));
+ EXPECT_EQ(1U, APInt::getBitsNeeded( "+1", 2));
+ EXPECT_EQ(2U, APInt::getBitsNeeded( "+10", 2));
+ EXPECT_EQ(2U, APInt::getBitsNeeded( "+11", 2));
+ EXPECT_EQ(3U, APInt::getBitsNeeded("+100", 2));
+
+ EXPECT_EQ(2U, APInt::getBitsNeeded( "-0", 2));
+ EXPECT_EQ(2U, APInt::getBitsNeeded( "-1", 2));
+ EXPECT_EQ(3U, APInt::getBitsNeeded( "-10", 2));
+ EXPECT_EQ(3U, APInt::getBitsNeeded( "-11", 2));
+ EXPECT_EQ(4U, APInt::getBitsNeeded("-100", 2));
+}
+
+TEST(APIntTest, StringBitsNeeded8) {
+ EXPECT_EQ(3U, APInt::getBitsNeeded( "0", 8));
+ EXPECT_EQ(3U, APInt::getBitsNeeded( "7", 8));
+ EXPECT_EQ(6U, APInt::getBitsNeeded("10", 8));
+ EXPECT_EQ(6U, APInt::getBitsNeeded("17", 8));
+ EXPECT_EQ(6U, APInt::getBitsNeeded("20", 8));
+
+ EXPECT_EQ(3U, APInt::getBitsNeeded( "+0", 8));
+ EXPECT_EQ(3U, APInt::getBitsNeeded( "+7", 8));
+ EXPECT_EQ(6U, APInt::getBitsNeeded("+10", 8));
+ EXPECT_EQ(6U, APInt::getBitsNeeded("+17", 8));
+ EXPECT_EQ(6U, APInt::getBitsNeeded("+20", 8));
+
+ EXPECT_EQ(4U, APInt::getBitsNeeded( "-0", 8));
+ EXPECT_EQ(4U, APInt::getBitsNeeded( "-7", 8));
+ EXPECT_EQ(7U, APInt::getBitsNeeded("-10", 8));
+ EXPECT_EQ(7U, APInt::getBitsNeeded("-17", 8));
+ EXPECT_EQ(7U, APInt::getBitsNeeded("-20", 8));
+}
+
+TEST(APIntTest, StringBitsNeeded10) {
+ EXPECT_EQ(1U, APInt::getBitsNeeded( "0", 10));
+ EXPECT_EQ(2U, APInt::getBitsNeeded( "3", 10));
+ EXPECT_EQ(4U, APInt::getBitsNeeded( "9", 10));
+ EXPECT_EQ(4U, APInt::getBitsNeeded("10", 10));
+ EXPECT_EQ(5U, APInt::getBitsNeeded("19", 10));
+ EXPECT_EQ(5U, APInt::getBitsNeeded("20", 10));
+
+ EXPECT_EQ(1U, APInt::getBitsNeeded( "+0", 10));
+ EXPECT_EQ(4U, APInt::getBitsNeeded( "+9", 10));
+ EXPECT_EQ(4U, APInt::getBitsNeeded("+10", 10));
+ EXPECT_EQ(5U, APInt::getBitsNeeded("+19", 10));
+ EXPECT_EQ(5U, APInt::getBitsNeeded("+20", 10));
+
+ EXPECT_EQ(2U, APInt::getBitsNeeded( "-0", 10));
+ EXPECT_EQ(5U, APInt::getBitsNeeded( "-9", 10));
+ EXPECT_EQ(5U, APInt::getBitsNeeded("-10", 10));
+ EXPECT_EQ(6U, APInt::getBitsNeeded("-19", 10));
+ EXPECT_EQ(6U, APInt::getBitsNeeded("-20", 10));
+}
+
+TEST(APIntTest, StringBitsNeeded16) {
+ EXPECT_EQ(4U, APInt::getBitsNeeded( "0", 16));
+ EXPECT_EQ(4U, APInt::getBitsNeeded( "F", 16));
+ EXPECT_EQ(8U, APInt::getBitsNeeded("10", 16));
+ EXPECT_EQ(8U, APInt::getBitsNeeded("1F", 16));
+ EXPECT_EQ(8U, APInt::getBitsNeeded("20", 16));
+
+ EXPECT_EQ(4U, APInt::getBitsNeeded( "+0", 16));
+ EXPECT_EQ(4U, APInt::getBitsNeeded( "+F", 16));
+ EXPECT_EQ(8U, APInt::getBitsNeeded("+10", 16));
+ EXPECT_EQ(8U, APInt::getBitsNeeded("+1F", 16));
+ EXPECT_EQ(8U, APInt::getBitsNeeded("+20", 16));
+
+ EXPECT_EQ(5U, APInt::getBitsNeeded( "-0", 16));
+ EXPECT_EQ(5U, APInt::getBitsNeeded( "-F", 16));
+ EXPECT_EQ(9U, APInt::getBitsNeeded("-10", 16));
+ EXPECT_EQ(9U, APInt::getBitsNeeded("-1F", 16));
+ EXPECT_EQ(9U, APInt::getBitsNeeded("-20", 16));
+}
+
+
#ifdef GTEST_HAS_DEATH_TEST
TEST(APIntTest, StringDeath) {
EXPECT_DEATH(APInt(0, "", 0), "Bitwidth too small");