99// Redistribution and use in source and binary forms with or without
1010// modifications are permitted.
1111
12- using FluentAssertions ;
1312using Neo . Extensions ;
1413using Neo . Json ;
1514using System ;
@@ -25,53 +24,53 @@ public class UT_BigIntegerExtensions
2524 public void TestGetLowestSetBit ( )
2625 {
2726 var big1 = new BigInteger ( 0 ) ;
28- big1 . GetLowestSetBit ( ) . Should ( ) . Be ( - 1 ) ;
27+ Assert . AreEqual ( - 1 , big1 . GetLowestSetBit ( ) ) ;
2928
3029 var big2 = new BigInteger ( 512 ) ;
31- big2 . GetLowestSetBit ( ) . Should ( ) . Be ( 9 ) ;
30+ Assert . AreEqual ( 9 , big2 . GetLowestSetBit ( ) ) ;
3231
3332 var big3 = new BigInteger ( int . MinValue ) ;
34- big3 . GetLowestSetBit ( ) . Should ( ) . Be ( 31 ) ;
33+ Assert . AreEqual ( 31 , big3 . GetLowestSetBit ( ) ) ;
3534
3635 var big4 = new BigInteger ( long . MinValue ) ;
37- big4 . GetLowestSetBit ( ) . Should ( ) . Be ( 63 ) ;
36+ Assert . AreEqual ( 63 , big4 . GetLowestSetBit ( ) ) ;
3837
3938 var big5 = new BigInteger ( - 18 ) ;
40- big5 . GetLowestSetBit ( ) . Should ( ) . Be ( 1 ) ;
39+ Assert . AreEqual ( 1 , big5 . GetLowestSetBit ( ) ) ;
4140
4241 var big6 = BigInteger . Pow ( 2 , 1000 ) ;
43- big6 . GetLowestSetBit ( ) . Should ( ) . Be ( 1000 ) ;
42+ Assert . AreEqual ( 1000 , big6 . GetLowestSetBit ( ) ) ;
4443 }
4544
4645 [ TestMethod ]
4746 public void TestGetLowestSetBit_EdgeCases ( )
4847 {
49- BigInteger . MinusOne . GetLowestSetBit ( ) . Should ( ) . Be ( 0 ) ;
50- BigInteger . One . GetLowestSetBit ( ) . Should ( ) . Be ( 0 ) ;
51- new BigInteger ( ulong . MaxValue ) . GetLowestSetBit ( ) . Should ( ) . Be ( 0 ) ;
52- ( BigInteger . One << 1000 ) . GetLowestSetBit ( ) . Should ( ) . Be ( 1000 ) ;
48+ Assert . AreEqual ( 0 , BigInteger . MinusOne . GetLowestSetBit ( ) ) ;
49+ Assert . AreEqual ( 0 , BigInteger . One . GetLowestSetBit ( ) ) ;
50+ Assert . AreEqual ( 0 , new BigInteger ( ulong . MaxValue ) . GetLowestSetBit ( ) ) ;
51+ Assert . AreEqual ( 1000 , ( BigInteger . One << 1000 ) . GetLowestSetBit ( ) ) ;
5352 }
5453
5554 [ TestMethod ]
5655 public void TestToByteArrayStandard ( )
5756 {
5857 BigInteger number = BigInteger . Zero ;
59- number . ToByteArrayStandard ( ) . Should ( ) . BeEmpty ( ) ;
58+ CollectionAssert . AreEqual ( Array . Empty < byte > ( ) , number . ToByteArrayStandard ( ) ) ;
6059
6160 number = BigInteger . One ;
62- number . ToByteArrayStandard ( ) . Should ( ) . Equal ( new byte [ ] { 0x01 } ) ;
61+ CollectionAssert . AreEqual ( new byte [ ] { 0x01 } , number . ToByteArrayStandard ( ) ) ;
6362
6463 number = new BigInteger ( 256 ) ; // Binary: 100000000
65- number . ToByteArrayStandard ( ) . Should ( ) . Equal ( new byte [ ] { 0x00 , 0x01 } ) ;
64+ CollectionAssert . AreEqual ( new byte [ ] { 0x00 , 0x01 } , number . ToByteArrayStandard ( ) ) ;
6665 }
6766
6867 [ TestMethod ]
6968 public void TestToByteArrayStandard_EdgeCases ( )
7069 {
71- BigInteger . MinusOne . ToByteArrayStandard ( ) . Should ( ) . Equal ( new byte [ ] { 0xFF } ) ;
72- new BigInteger ( byte . MaxValue ) . ToByteArrayStandard ( ) . Should ( ) . Equal ( new byte [ ] { 0xFF , 0x00 } ) ;
73- new BigInteger ( ushort . MaxValue ) . ToByteArrayStandard ( ) . Should ( ) . Equal ( new byte [ ] { 0xFF , 0xFF , 0x00 } ) ;
74- new BigInteger ( JNumber . MIN_SAFE_INTEGER ) . ToByteArrayStandard ( ) . Should ( ) . Equal ( new byte [ ] { 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xE0 } ) ;
70+ CollectionAssert . AreEqual ( new byte [ ] { 0xFF } , BigInteger . MinusOne . ToByteArrayStandard ( ) ) ;
71+ CollectionAssert . AreEqual ( new byte [ ] { 0xFF , 0x00 } , new BigInteger ( byte . MaxValue ) . ToByteArrayStandard ( ) ) ;
72+ CollectionAssert . AreEqual ( new byte [ ] { 0xFF , 0xFF , 0x00 } , new BigInteger ( ushort . MaxValue ) . ToByteArrayStandard ( ) ) ;
73+ CollectionAssert . AreEqual ( new byte [ ] { 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xE0 } , new BigInteger ( JNumber . MIN_SAFE_INTEGER ) . ToByteArrayStandard ( ) ) ;
7574 }
7675
7776 [ TestMethod ]
@@ -80,35 +79,35 @@ public void TestMod()
8079 var x = new BigInteger ( - 13 ) ;
8180 var y = new BigInteger ( 5 ) ;
8281 var result = x . Mod ( y ) ;
83- result . Should ( ) . Be ( 2 ) ; // -13 % 5 is -3, but Mod method should return 2
82+ Assert . AreEqual ( 2 , result ) ; // -13 % 5 is -3, but Mod method should return 2
8483 }
8584
8685 [ TestMethod ]
8786 public void TestMod_EdgeCases ( )
8887 {
8988 // Test case 1: Mod of zero
90- BigInteger . Zero . Mod ( 5 ) . Should ( ) . Be ( 0 , "Mod of zero should always be zero" ) ;
89+ Assert . AreEqual ( 0 , BigInteger . Zero . Mod ( 5 ) , "Mod of zero should always be zero" ) ;
9190
9291 // Test case 2: Mod of -1
93- BigInteger . MinusOne . Mod ( 5 ) . Should ( ) . Be ( 4 , "Mod of -1 should return the modulus minus 1" ) ;
92+ Assert . AreEqual ( 4 , BigInteger . MinusOne . Mod ( 5 ) , "Mod of -1 should return the modulus minus 1" ) ;
9493
9594 // Test case 3: Mod with large numbers
9695 BigInteger minValue = new BigInteger ( long . MinValue ) ;
9796 BigInteger maxValue = new BigInteger ( long . MaxValue ) ;
98- minValue . Mod ( maxValue ) . Should ( ) . Be ( 9223372036854775806 , "Mod with large numbers should be calculated correctly" ) ;
97+ Assert . AreEqual ( 9223372036854775806 , minValue . Mod ( maxValue ) , "Mod with large numbers should be calculated correctly" ) ;
9998
10099 // Test case 4: Comparing Mod with % operator
101100 BigInteger result = minValue . Mod ( maxValue ) ;
102- result . Should ( ) . NotBe ( long . MinValue % long . MaxValue , "Mod should always return non-negative values, unlike % operator" ) ;
101+ Assert . AreNotEqual ( long . MinValue % long . MaxValue , result , "Mod should always return non-negative values, unlike % operator" ) ;
103102
104103 // Test case 5: Verifying % operator behavior
105- ( long . MinValue % long . MaxValue ) . Should ( ) . Be ( ( long ) ( minValue % maxValue ) , "% operator should behave consistently for BigInteger and long" ) ;
104+ Assert . AreEqual ( ( long ) ( minValue % maxValue ) , long . MinValue % long . MaxValue , "% operator should behave consistently for BigInteger and long" ) ;
106105
107106 // Test case 6: Mod with prime numbers
108- new BigInteger ( 17 ) . Mod ( 19 ) . Should ( ) . Be ( 17 , "Mod with a larger prime should return the original number" ) ;
107+ Assert . AreEqual ( 17 , new BigInteger ( 17 ) . Mod ( 19 ) , "Mod with a larger prime should return the original number" ) ;
109108
110109 // Test case 7: Mod with powers of 2
111- new BigInteger ( 1024 ) . Mod ( 16 ) . Should ( ) . Be ( 0 , "Mod with powers of 2 should utilize bitwise operations efficiently" ) ;
110+ Assert . AreEqual ( 0 , new BigInteger ( 1024 ) . Mod ( 16 ) , "Mod with powers of 2 should utilize bitwise operations efficiently" ) ;
112111 }
113112
114113 [ TestMethod ]
@@ -117,76 +116,70 @@ public void TestModInverse()
117116 var a = new BigInteger ( 3 ) ;
118117 var n = new BigInteger ( 11 ) ;
119118 var result = a . ModInverse ( n ) ;
120- result . Should ( ) . Be ( 4 ) ; // 3 * 4 % 11 == 1
119+ Assert . AreEqual ( 4 , result ) ; // 3 * 4 % 11 == 1
121120
122121 a = new BigInteger ( 1 ) ;
123122 n = new BigInteger ( 11 ) ;
124123 result = a . ModInverse ( n ) ;
125- result . Should ( ) . Be ( 1 ) ; // 1 * 1 % 11 == 1
124+ Assert . AreEqual ( 1 , result ) ; // 1 * 1 % 11 == 1
126125
127126 a = new BigInteger ( 13 ) ;
128127 n = new BigInteger ( 11 ) ;
129128 result = a . ModInverse ( n ) ;
130- result . Should ( ) . Be ( 6 ) ; // 13 % 11 = 2, and 2 * 6 % 11 == 1
129+ Assert . AreEqual ( 6 , result ) ; // 13 % 11 = 2, and 2 * 6 % 11 == 1
131130
132131 a = new BigInteger ( 6 ) ;
133132 n = new BigInteger ( 12 ) ; // 6 and 12 are not coprime
134- Action act = ( ) => a . ModInverse ( n ) ;
135- act . Should ( ) . Throw < ArithmeticException > ( )
136- . WithMessage ( "No modular inverse exists for the given inputs." ) ;
133+ Assert . ThrowsException < ArithmeticException > ( ( ) => a . ModInverse ( n ) ) ;
137134 }
138135
139136 [ TestMethod ]
140137 public void TestModInverse_EdgeCases ( )
141138 {
142- Action act = ( ) => BigInteger . Zero . ModInverse ( 11 ) ;
143- act . Should ( ) . Throw < ArithmeticException > ( ) ;
139+ Assert . ThrowsException < ArithmeticException > ( ( ) => BigInteger . Zero . ModInverse ( 11 ) ) ;
144140
145- BigInteger . One . ModInverse ( 2 ) . Should ( ) . Be ( 1 ) ;
141+ Assert . AreEqual ( 1 , BigInteger . One . ModInverse ( 2 ) ) ;
146142
147- act = ( ) => new BigInteger ( 2 ) . ModInverse ( 4 ) ;
148- act . Should ( ) . Throw < ArithmeticException > ( ) ;
143+ Assert . ThrowsException < ArithmeticException > ( ( ) => new BigInteger ( 2 ) . ModInverse ( 4 ) ) ;
149144
150- new BigInteger ( long . MaxValue - 1 ) . ModInverse ( long . MaxValue ) . Should ( ) . Be ( long . MaxValue - 1 ) ;
145+ Assert . AreEqual ( long . MaxValue - 1 , new BigInteger ( long . MaxValue - 1 ) . ModInverse ( long . MaxValue ) ) ;
151146 }
152147
153148 [ TestMethod ]
154149 public void TestBit ( )
155150 {
156151 var bigInteger = new BigInteger ( 5 ) ; // Binary: 101
157- var result = bigInteger . TestBit ( 2 ) ;
158- result . Should ( ) . BeTrue ( ) ; // Bit at index 2 is set (1)
152+ Assert . IsTrue ( bigInteger . TestBit ( 2 ) ) ; // Bit at index 2 is set (1)
159153
160154 bigInteger = new BigInteger ( 5 ) ; // Binary: 101
161- result = bigInteger . TestBit ( 1 ) ;
162- result . Should ( ) . BeFalse ( ) ; // Bit at index 1 is not set (0)
155+ Assert . IsFalse ( bigInteger . TestBit ( 1 ) ) ; // Bit at index 1 is not set (0)
163156 }
164157
165158 [ TestMethod ]
166159 public void TestBit_EdgeCases ( )
167160 {
168- BigInteger . Zero . TestBit ( 0 ) . Should ( ) . BeFalse ( ) ;
169- BigInteger . Zero . TestBit ( 100 ) . Should ( ) . BeFalse ( ) ;
170- BigInteger . MinusOne . TestBit ( 0 ) . Should ( ) . BeTrue ( ) ;
171- BigInteger . MinusOne . TestBit ( 1000 ) . Should ( ) . BeTrue ( ) ;
172- ( BigInteger . One << 1000 ) . TestBit ( 1000 ) . Should ( ) . BeTrue ( ) ;
173- ( BigInteger . One << 1000 ) . TestBit ( 999 ) . Should ( ) . BeFalse ( ) ;
161+ Assert . IsFalse ( BigInteger . Zero . TestBit ( 0 ) ) ;
162+ Assert . IsFalse ( BigInteger . Zero . TestBit ( 100 ) ) ;
163+ Assert . IsTrue ( BigInteger . MinusOne . TestBit ( 0 ) ) ;
164+ Assert . IsTrue ( BigInteger . MinusOne . TestBit ( 1000 ) ) ;
165+ Assert . IsTrue ( ( BigInteger . One << 1000 ) . TestBit ( 1000 ) ) ;
166+ Assert . IsFalse ( ( BigInteger . One << 1000 ) . TestBit ( 999 ) ) ;
174167 }
175168
176169 [ TestMethod ]
177170 public void TestSum ( )
178171 {
179172 var bigIntegers = new List < BigInteger > { 1 , 2 , 3 , 4 } ;
180173 var result = bigIntegers . Sum ( ) ;
181- result . Should ( ) . Be ( 10 ) ;
174+ Assert . AreEqual ( 10 , result ) ;
182175 }
183176
184177 [ TestMethod ]
185178 public void TestSum_EdgeCases ( )
186179 {
187- new List < BigInteger > ( ) . Sum ( ) . Should ( ) . Be ( 0 ) ;
188- new List < BigInteger > { JNumber . MIN_SAFE_INTEGER , JNumber . MAX_SAFE_INTEGER } . Sum ( ) . Should ( ) . Be ( 0 ) ;
189- new List < BigInteger > { JNumber . MAX_SAFE_INTEGER , JNumber . MAX_SAFE_INTEGER } . Sum ( ) . Should ( ) . Be ( JNumber . MAX_SAFE_INTEGER * 2 ) ;
180+ Assert . AreEqual ( 0 , new List < BigInteger > ( ) . Sum ( ) ) ;
181+ Assert . AreEqual ( 0 , new List < BigInteger > { JNumber . MIN_SAFE_INTEGER , JNumber . MAX_SAFE_INTEGER } . Sum ( ) ) ;
182+ Assert . AreEqual ( JNumber . MAX_SAFE_INTEGER * 2 , new List < BigInteger > { JNumber . MAX_SAFE_INTEGER , JNumber . MAX_SAFE_INTEGER } . Sum ( ) ) ;
190183 }
191184 }
192185}
0 commit comments