diff options
author | Tim King <taking@cs.nyu.edu> | 2012-11-26 21:38:28 +0000 |
---|---|---|
committer | Tim King <taking@cs.nyu.edu> | 2012-11-26 21:38:28 +0000 |
commit | 1e4c37a3ef7b1c16914b181c189716aa4a3df6b8 (patch) | |
tree | e8e905504deaface2e563adb54564d04cf7e568b /test/unit/util | |
parent | a7aad4ae3a1cd80f0e035e1a77b8e42c38c99c8d (diff) |
Improved implementation of Integer::length() with CLN enabled. Additional tests to sanity check both versions CLN and GMP versions of length.
Diffstat (limited to 'test/unit/util')
-rw-r--r-- | test/unit/util/integer_black.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/unit/util/integer_black.h b/test/unit/util/integer_black.h index ead11e4df..d2f697637 100644 --- a/test/unit/util/integer_black.h +++ b/test/unit/util/integer_black.h @@ -366,4 +366,25 @@ public: TS_ASSERT( ! Integer(64).testBit(1) ); TS_ASSERT( ! Integer(64).testBit(0) ); } + + unsigned int internalLength(int i){ + if ( i == 0){ + return 1; + }else{ + int absi = i < 0 ? -i : i; + unsigned int n = 0; + int powN = 1; + do { + powN <<= 1; + ++n; + }while(absi >= powN); + return n; + } + } + + void testTestLength() { + for(int i = -17; i <= 17; ++i){ + TS_ASSERT_EQUALS(Integer(i).length(), internalLength(i)); + } + } }; |