Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
bigintegertest.cpp File Reference
Include dependency graph for bigintegertest.cpp:

Go to the source code of this file.

Macros

#define BIGINTEGER_LITERAL(s)
 

Functions

 TEST (BigInteger, Constructor)
 
 TEST (BigInteger, AddUint64)
 
 TEST (BigInteger, MultiplyUint64)
 
 TEST (BigInteger, MultiplyUint32)
 
 TEST (BigInteger, LeftShift)
 
 TEST (BigInteger, Compare)
 

Macro Definition Documentation

◆ BIGINTEGER_LITERAL

#define BIGINTEGER_LITERAL ( s)
Value:
BigInteger(s, sizeof(s) - 1)
char * s

Definition at line 21 of file bigintegertest.cpp.

Function Documentation

◆ TEST() [1/6]

TEST ( BigInteger ,
AddUint64  )

Definition at line 44 of file bigintegertest.cpp.

44 {
45 BigInteger a = kZero;
46 a += 0u;
47 EXPECT_TRUE(kZero == a);
48
49 a += 1u;
50 EXPECT_TRUE(kOne == a);
51
52 a += 1u;
53 EXPECT_TRUE(BigInteger(2) == a);
54
55 EXPECT_TRUE(BigInteger(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0xFFFFFFFF)) == kUint64Max);
56 BigInteger b = kUint64Max;
57 b += 1u;
58 EXPECT_TRUE(kTwo64 == b);
59 b += RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0xFFFFFFFF);
60 EXPECT_TRUE(BIGINTEGER_LITERAL("36893488147419103231") == b);
61}
#define BIGINTEGER_LITERAL(s)
#define EXPECT_TRUE(condition)
Definition gtest.h:1895
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition rapidjson.h:289

◆ TEST() [2/6]

TEST ( BigInteger ,
Compare  )

Definition at line 130 of file bigintegertest.cpp.

130 {
131 EXPECT_EQ(0, kZero.Compare(kZero));
132 EXPECT_EQ(1, kOne.Compare(kZero));
133 EXPECT_EQ(-1, kZero.Compare(kOne));
134 EXPECT_EQ(0, kUint64Max.Compare(kUint64Max));
135 EXPECT_EQ(0, kTwo64.Compare(kTwo64));
136 EXPECT_EQ(-1, kUint64Max.Compare(kTwo64));
137 EXPECT_EQ(1, kTwo64.Compare(kUint64Max));
138}
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1954

◆ TEST() [3/6]

TEST ( BigInteger ,
Constructor  )

Definition at line 28 of file bigintegertest.cpp.

28 {
29 EXPECT_TRUE(kZero.IsZero());
30 EXPECT_TRUE(kZero == kZero);
31 EXPECT_TRUE(kZero == BIGINTEGER_LITERAL("0"));
32 EXPECT_TRUE(kZero == BIGINTEGER_LITERAL("00"));
33
34 const BigInteger a(123);
35 EXPECT_TRUE(a == a);
38
39 EXPECT_EQ(2u, kTwo64.GetCount());
40 EXPECT_EQ(0u, kTwo64.GetDigit(0));
41 EXPECT_EQ(1u, kTwo64.GetDigit(1));
42}

◆ TEST() [4/6]

TEST ( BigInteger ,
LeftShift  )

Definition at line 107 of file bigintegertest.cpp.

107 {
108 BigInteger a = kZero;
109 a <<= 1;
110 EXPECT_TRUE(kZero == a);
111 a <<= 64;
112 EXPECT_TRUE(kZero == a);
113
114 a = BigInteger(123);
115 a <<= 0;
116 EXPECT_TRUE(BigInteger(123) == a);
117 a <<= 1;
118 EXPECT_TRUE(BigInteger(246) == a);
119 a <<= 64;
120 EXPECT_TRUE(BIGINTEGER_LITERAL("4537899042132549697536") == a);
121 a <<= 99;
122 EXPECT_TRUE(BIGINTEGER_LITERAL("2876235222267216943024851750785644982682875244576768") == a);
123
124 a = 1;
125 a <<= 64; // a.count_ != 1
126 a <<= 256; // interShift == 0
127 EXPECT_TRUE(BIGINTEGER_LITERAL("2135987035920910082395021706169552114602704522356652769947041607822219725780640550022962086936576") == a);
128}

◆ TEST() [5/6]

TEST ( BigInteger ,
MultiplyUint32  )

Definition at line 85 of file bigintegertest.cpp.

85 {
86 BigInteger a = kZero;
87 a *= static_cast <uint32_t>(0);
88 EXPECT_TRUE(kZero == a);
89 a *= static_cast <uint32_t>(123);
90 EXPECT_TRUE(kZero == a);
91
92 BigInteger b = kOne;
93 b *= static_cast<uint32_t>(1);
94 EXPECT_TRUE(kOne == b);
95 b *= static_cast<uint32_t>(0);
96 EXPECT_TRUE(kZero == b);
97
98 BigInteger c(123);
99 c *= static_cast<uint32_t>(456u);
100 EXPECT_TRUE(BigInteger(123u * 456u) == c);
101 c *= 0xFFFFFFFFu;
102 EXPECT_TRUE(BIGINTEGER_LITERAL("240896125641960") == c);
103 c *= 0xFFFFFFFFu;
104 EXPECT_TRUE(BIGINTEGER_LITERAL("1034640981124429079698200") == c);
105}
unsigned int uint32_t
Definition stdint.h:126

◆ TEST() [6/6]

TEST ( BigInteger ,
MultiplyUint64  )

Definition at line 63 of file bigintegertest.cpp.

63 {
64 BigInteger a = kZero;
65 a *= static_cast <uint64_t>(0);
66 EXPECT_TRUE(kZero == a);
67 a *= static_cast <uint64_t>(123);
68 EXPECT_TRUE(kZero == a);
69
70 BigInteger b = kOne;
71 b *= static_cast<uint64_t>(1);
72 EXPECT_TRUE(kOne == b);
73 b *= static_cast<uint64_t>(0);
74 EXPECT_TRUE(kZero == b);
75
76 BigInteger c(123);
77 c *= static_cast<uint64_t>(456u);
78 EXPECT_TRUE(BigInteger(123u * 456u) == c);
79 c *= RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0xFFFFFFFF);
80 EXPECT_TRUE(BIGINTEGER_LITERAL("1034640981606221330982120") == c);
81 c *= RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0xFFFFFFFF);
82 EXPECT_TRUE(BIGINTEGER_LITERAL("19085757395861596536664473018420572782123800") == c);
83}
unsigned __int64 uint64_t
Definition stdint.h:136