|
4 | 4 | #include <cstdint> |
5 | 5 |
|
6 | 6 | #include "../lib/InfInt.h" |
| 7 | +#include "../vmobjects/ObjectFormats.h" |
7 | 8 |
|
8 | 9 | void InfIntTest::testBasicNumbers() { |
9 | 10 | InfInt const zero(int64_t(0LL)); |
10 | | - CPPUNIT_ASSERT_EQUAL(int64_t(0LL), zero.toLongLong()); |
| 11 | + CPPUNIT_ASSERT_EQUAL(int64_t(0LL), zero.toInt64()); |
11 | 12 |
|
12 | 13 | InfInt const one(int64_t(1LL)); |
13 | | - CPPUNIT_ASSERT_EQUAL(int64_t(1LL), one.toLongLong()); |
| 14 | + CPPUNIT_ASSERT_EQUAL(int64_t(1LL), one.toInt64()); |
14 | 15 |
|
15 | 16 | InfInt const a500(int64_t(500LL)); |
16 | | - CPPUNIT_ASSERT_EQUAL(int64_t(500LL), a500.toLongLong()); |
| 17 | + CPPUNIT_ASSERT_EQUAL(int64_t(500LL), a500.toInt64()); |
17 | 18 |
|
18 | 19 | InfInt const a32bitNum(int64_t(3221258751LL)); |
19 | | - CPPUNIT_ASSERT_EQUAL(int64_t(3221258751LL), a32bitNum.toLongLong()); |
| 20 | + CPPUNIT_ASSERT_EQUAL(int64_t(3221258751LL), a32bitNum.toInt64()); |
20 | 21 |
|
21 | 22 | InfInt const a48bitNum(int64_t(211109453791743LL)); |
22 | | - CPPUNIT_ASSERT_EQUAL(int64_t(211109453791743LL), a48bitNum.toLongLong()); |
| 23 | + CPPUNIT_ASSERT_EQUAL(int64_t(211109453791743LL), a48bitNum.toInt64()); |
23 | 24 |
|
24 | 25 | InfInt const a63bitNum(int64_t(8070661641701720575LL)); |
25 | | - CPPUNIT_ASSERT_EQUAL(int64_t(8070661641701720575LL), |
26 | | - a63bitNum.toLongLong()); |
| 26 | + CPPUNIT_ASSERT_EQUAL(int64_t(8070661641701720575LL), a63bitNum.toInt64()); |
27 | 27 | } |
28 | 28 |
|
29 | 29 | void InfIntTest::testIsZero() { |
30 | 30 | InfInt const zero{}; |
31 | | - CPPUNIT_ASSERT_EQUAL(int64_t(0LL), zero.toLongLong()); |
| 31 | + CPPUNIT_ASSERT_EQUAL(int64_t(0LL), zero.toInt64()); |
32 | 32 | CPPUNIT_ASSERT(zero.isZero()); |
33 | 33 |
|
34 | 34 | InfInt const zeroInt64(int64_t(0LL)); |
35 | | - CPPUNIT_ASSERT_EQUAL(int64_t(0LL), zeroInt64.toLongLong()); |
| 35 | + CPPUNIT_ASSERT_EQUAL(int64_t(0LL), zeroInt64.toInt64()); |
36 | 36 | CPPUNIT_ASSERT(zeroInt64.isZero()); |
37 | 37 |
|
38 | 38 | InfInt const zeroStr("0"); |
39 | | - CPPUNIT_ASSERT_EQUAL(int64_t(0LL), zeroStr.toLongLong()); |
| 39 | + CPPUNIT_ASSERT_EQUAL(int64_t(0LL), zeroStr.toInt64()); |
40 | 40 | CPPUNIT_ASSERT(zeroStr.isZero()); |
41 | 41 |
|
42 | 42 | InfInt const negZeroStr("-0"); |
43 | | - CPPUNIT_ASSERT_EQUAL(int64_t(0LL), negZeroStr.toLongLong()); |
| 43 | + CPPUNIT_ASSERT_EQUAL(int64_t(0LL), negZeroStr.toInt64()); |
44 | 44 | CPPUNIT_ASSERT(negZeroStr.isZero()); |
45 | 45 | } |
| 46 | + |
| 47 | +void InfIntTest::testIsWithinSmallIntRange() { |
| 48 | + InfInt const smallIntMax(VMTAGGEDINTEGER_MAX); |
| 49 | + CPPUNIT_ASSERT_EQUAL(int64_t(VMTAGGEDINTEGER_MAX), smallIntMax.toInt64()); |
| 50 | + CPPUNIT_ASSERT(smallIntMax.isWithinSmallIntRange()); |
| 51 | + |
| 52 | + InfInt const smallIntMin(VMTAGGEDINTEGER_MIN); |
| 53 | + CPPUNIT_ASSERT_EQUAL(int64_t(VMTAGGEDINTEGER_MIN), smallIntMin.toInt64()); |
| 54 | + CPPUNIT_ASSERT(smallIntMin.isWithinSmallIntRange()); |
| 55 | + |
| 56 | + InfInt const smallIntMaxPlusOne(VMTAGGEDINTEGER_MAX + 1LL); |
| 57 | + CPPUNIT_ASSERT_EQUAL(int64_t(VMTAGGEDINTEGER_MAX + 1LL), |
| 58 | + smallIntMaxPlusOne.toInt64()); |
| 59 | + CPPUNIT_ASSERT(!smallIntMaxPlusOne.isWithinSmallIntRange()); |
| 60 | + |
| 61 | + InfInt const smallIntMinMinusOne(VMTAGGEDINTEGER_MIN - 1LL); |
| 62 | + CPPUNIT_ASSERT_EQUAL(int64_t(VMTAGGEDINTEGER_MIN - 1LL), |
| 63 | + smallIntMinMinusOne.toInt64()); |
| 64 | + CPPUNIT_ASSERT(!smallIntMinMinusOne.isWithinSmallIntRange()); |
| 65 | + |
| 66 | + InfInt const smallIntMaxMinusOne(VMTAGGEDINTEGER_MAX - 1LL); |
| 67 | + CPPUNIT_ASSERT_EQUAL(int64_t(VMTAGGEDINTEGER_MAX - 1LL), |
| 68 | + smallIntMaxMinusOne.toInt64()); |
| 69 | + CPPUNIT_ASSERT(smallIntMaxMinusOne.isWithinSmallIntRange()); |
| 70 | + |
| 71 | + InfInt const smallIntMinPlusOne(VMTAGGEDINTEGER_MIN + 1LL); |
| 72 | + CPPUNIT_ASSERT_EQUAL(int64_t(VMTAGGEDINTEGER_MIN + 1LL), |
| 73 | + smallIntMinPlusOne.toInt64()); |
| 74 | + CPPUNIT_ASSERT(smallIntMinPlusOne.isWithinSmallIntRange()); |
| 75 | +} |
0 commit comments