2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2022 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2022 - 2023 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -28,11 +28,13 @@ final class StaticBigIntTests {
28
28
static func main( ) {
29
29
let testCase = StaticBigIntTests ( )
30
30
let testSuite = TestSuite ( " StaticBigIntTests " )
31
- testSuite. test ( " BinaryRepresentation " , testCase. testBinaryRepresentation)
32
- testSuite. test ( " TextualRepresentation " , testCase. testTextualRepresentation)
31
+ testSuite. test ( " BinaryRepresentation " , testCase. testBinaryRepresentation)
32
+ testSuite. test ( " TextualRepresentation " , testCase. testTextualRepresentation)
33
33
testSuite. test ( " PrefixPlusTypeInference " , testCase. testPrefixPlusTypeInference)
34
34
testSuite. test ( " PrefixMinusTypeInference " , testCase. testPrefixMinusTypeInference)
35
- testSuite. test ( " WrapperAssociatedType " , testCase. testWrapperAssociatedType)
35
+ testSuite. test ( " WrapperNegativeValue " , testCase. testWrapperNegativeValue)
36
+ testSuite. test ( " WrapperPositiveValue " , testCase. testWrapperPositiveValue)
37
+ testSuite. test ( " WrapperFibonacciSequence " , testCase. testWrapperFibonacciSequence)
36
38
runAllTests ( )
37
39
}
38
40
}
@@ -132,23 +134,11 @@ extension StaticBigIntTests {
132
134
}
133
135
134
136
//===----------------------------------------------------------------------===//
135
- // MARK: - Wrapper Associated Type
137
+ // MARK: - Type Inference
136
138
//===----------------------------------------------------------------------===//
137
139
138
140
@available ( SwiftStdlib 5 . 8 , * )
139
141
extension StaticBigIntTests {
140
-
141
- @available ( SwiftStdlib 5 . 8 , * )
142
- struct Wrapper : ExpressibleByIntegerLiteral {
143
-
144
- @available ( SwiftStdlib 5 . 8 , * )
145
- let actual : StaticBigInt
146
-
147
- @available ( SwiftStdlib 5 . 8 , * )
148
- init ( integerLiteral actual: StaticBigInt ) {
149
- self . actual = actual
150
- }
151
- }
152
142
153
143
func testPrefixPlusTypeInference( ) {
154
144
let a : Int = 7
@@ -169,70 +159,96 @@ extension StaticBigIntTests {
169
159
let b = - 1
170
160
let c = a + b
171
161
}
162
+ }
163
+
164
+ //===----------------------------------------------------------------------===//
165
+ // MARK: - Wrapper Associated Type
166
+ //===----------------------------------------------------------------------===//
167
+
168
+ @available ( SwiftStdlib 5 . 8 , * )
169
+ extension StaticBigIntTests {
170
+
171
+ @available ( SwiftStdlib 5 . 8 , * )
172
+ struct Wrapper : ExpressibleByIntegerLiteral {
173
+
174
+ @available ( SwiftStdlib 5 . 8 , * )
175
+ let actual : StaticBigInt
176
+
177
+ @available ( SwiftStdlib 5 . 8 , * )
178
+ init ( integerLiteral actual: StaticBigInt ) {
179
+ self . actual = actual
180
+ }
181
+ }
172
182
173
183
@available ( SwiftStdlib 5 . 8 , * )
174
- func testWrapperAssociatedType( ) {
175
- do {
176
- let negative = Wrapper ( - 0x00112233_44556677_8899AABB_CCDDEEFF )
177
- expectEqual ( - 1 , negative. actual. signum ( ) )
178
- expectEqual ( 118 , negative. actual. bitWidth)
184
+ func testWrapperNegativeValue( ) {
185
+ let negative = Wrapper ( - 0x00112233_44556677_8899AABB_CCDDEEFF )
186
+ expectEqual ( - 1 , negative. actual. signum ( ) )
187
+ expectEqual ( 118 , negative. actual. bitWidth)
179
188
#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) || arch(powerpc)
180
- expectEqual ( 0x33221101 , negative. actual [ 0 ] )
181
- expectEqual ( 0x77665544 , negative. actual [ 1 ] )
182
- expectEqual ( 0xBBAA9988 , negative. actual [ 2 ] )
183
- expectEqual ( 0xFFEEDDCC , negative. actual [ 3 ] )
184
- expectEqual ( 0xFFFFFFFF , negative. actual [ 4 ] )
185
- expectEqual ( 0xFFFFFFFF , negative. actual [ . max] )
189
+ expectEqual ( 0x33221101 , negative. actual [ 0 ] )
190
+ expectEqual ( 0x77665544 , negative. actual [ 1 ] )
191
+ expectEqual ( 0xBBAA9988 , negative. actual [ 2 ] )
192
+ expectEqual ( 0xFFEEDDCC , negative. actual [ 3 ] )
193
+ expectEqual ( 0xFFFFFFFF , negative. actual [ 4 ] )
194
+ expectEqual ( 0xFFFFFFFF , negative. actual [ . max] )
186
195
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64)
187
- expectEqual ( 0x77665544_33221101 , negative. actual [ 0 ] )
188
- expectEqual ( 0xFFEEDDCC_BBAA9988 , negative. actual [ 1 ] )
189
- expectEqual ( 0xFFFFFFFF_FFFFFFFF , negative. actual [ 2 ] )
190
- expectEqual ( 0xFFFFFFFF_FFFFFFFF , negative. actual [ . max] )
196
+ expectEqual ( 0x77665544_33221101 , negative. actual [ 0 ] )
197
+ expectEqual ( 0xFFEEDDCC_BBAA9988 , negative. actual [ 1 ] )
198
+ expectEqual ( 0xFFFFFFFF_FFFFFFFF , negative. actual [ 2 ] )
199
+ expectEqual ( 0xFFFFFFFF_FFFFFFFF , negative. actual [ . max] )
191
200
#else
192
201
#error("Unimplemented")
193
202
#endif
194
- }
195
- do {
196
- let positive = Wrapper ( 0x00112233_44556677_8899AABB_CCDDEEFF )
197
- expectEqual ( + 1 , positive. actual. signum ( ) )
198
- expectEqual ( 118 , positive. actual. bitWidth)
203
+ }
204
+
205
+ @available ( SwiftStdlib 5 . 8 , * )
206
+ func testWrapperPositiveValue( ) {
207
+ let positive = Wrapper ( 0x00112233_44556677_8899AABB_CCDDEEFF )
208
+ expectEqual ( + 1 , positive. actual. signum ( ) )
209
+ expectEqual ( 118 , positive. actual. bitWidth)
199
210
#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) || arch(powerpc)
200
- expectEqual ( 0xCCDDEEFF , positive. actual [ 0 ] )
201
- expectEqual ( 0x8899AABB , positive. actual [ 1 ] )
202
- expectEqual ( 0x44556677 , positive. actual [ 2 ] )
203
- expectEqual ( 0x00112233 , positive. actual [ 3 ] )
204
- expectEqual ( 0x00000000 , positive. actual [ 4 ] )
205
- expectEqual ( 0x00000000 , positive. actual [ . max] )
211
+ expectEqual ( 0xCCDDEEFF , positive. actual [ 0 ] )
212
+ expectEqual ( 0x8899AABB , positive. actual [ 1 ] )
213
+ expectEqual ( 0x44556677 , positive. actual [ 2 ] )
214
+ expectEqual ( 0x00112233 , positive. actual [ 3 ] )
215
+ expectEqual ( 0x00000000 , positive. actual [ 4 ] )
216
+ expectEqual ( 0x00000000 , positive. actual [ . max] )
206
217
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64)
207
- expectEqual ( 0x8899AABB_CCDDEEFF , positive. actual [ 0 ] )
208
- expectEqual ( 0x00112233_44556677 , positive. actual [ 1 ] )
209
- expectEqual ( 0x00000000_00000000 , positive. actual [ 2 ] )
210
- expectEqual ( 0x00000000_00000000 , positive. actual [ . max] )
218
+ expectEqual ( 0x8899AABB_CCDDEEFF , positive. actual [ 0 ] )
219
+ expectEqual ( 0x00112233_44556677 , positive. actual [ 1 ] )
220
+ expectEqual ( 0x00000000_00000000 , positive. actual [ 2 ] )
221
+ expectEqual ( 0x00000000_00000000 , positive. actual [ . max] )
211
222
#else
212
223
#error("Unimplemented")
213
224
#endif
214
- }
215
- do {
225
+ }
226
+
227
+ @available ( SwiftStdlib 5 . 8 , * )
228
+ func testWrapperFibonacciSequence( ) {
216
229
#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) || arch(powerpc)
217
- // Unimplemented.
230
+ let wordCount = 48
231
+ let fibonacciSequence = Wrapper (
232
+ 0xB11924E1_6D73E55F_43A53F82_29CEA5DD_19D699A5_0FF80C38_09DE8D6D_06197ECB_03C50EA2_02547029_01709E79_00E3D1B0_008CCCC9_005704E7_0035C7E2_00213D05_00148ADD_000CB228_0007D8B5_0004D973_0002FF42_0001DA31_00012511_0000B520_00006FF1_0000452F_00002AC2_00001A6D_00001055_00000A18_0000063D_000003DB_00000262_00000179_000000E9_00000090_00000059_00000037_00000022_00000015_0000000D_00000008_00000005_00000003_00000002_00000001_00000001_00000000
233
+ )
218
234
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) || arch(riscv64)
219
- let fibonacciSequence = Wrapper (
220
- 0xA94FAD42221F2702_68A3DD8E61ECCFBD_40ABCFB3C0325745_27F80DDAA1BA7878_18B3C1D91E77DECD_0F444C01834299AB_096F75D79B354522_05D4D629E80D5489_039A9FADB327F099_023A367C34E563F0_016069317E428CA9_00D9CD4AB6A2D747_00869BE6C79FB562_00533163EF0321E5_00336A82D89C937D_001FC6E116668E68_0013A3A1C2360515_000C233F54308953_000780626E057BC2_0004A2DCE62B0D91_0002DD8587DA6E31_0001C5575E509F60_0001182E2989CED1_0000AD2934C6D08F_00006B04F4C2FE42_000042244003D24D_000028E0B4BF2BF5_000019438B44A658_00000F9D297A859D_000009A661CA20BB_000005F6C7B064E2_000003AF9A19BBD9_000002472D96A909_000001686C8312D0_000000DEC1139639_00000089AB6F7C97_0000005515A419A2_0000003495CB62F5_000000207FD8B6AD_0000001415F2AC48_0000000C69E60A65_00000007AC0CA1E3_00000004BDD96882_00000002EE333961_00000001CFA62F21_000000011E8D0A40_00000000B11924E1_000000006D73E55F_0000000043A53F82_0000000029CEA5DD_0000000019D699A5_000000000FF80C38_0000000009DE8D6D_0000000006197ECB_0000000003C50EA2_0000000002547029_0000000001709E79_0000000000E3D1B0_00000000008CCCC9_00000000005704E7_000000000035C7E2_0000000000213D05_0000000000148ADD_00000000000CB228_000000000007D8B5_000000000004D973_000000000002FF42_000000000001DA31_0000000000012511_000000000000B520_0000000000006FF1_000000000000452F_0000000000002AC2_0000000000001A6D_0000000000001055_0000000000000A18_000000000000063D_00000000000003DB_0000000000000262_0000000000000179_00000000000000E9_0000000000000090_0000000000000059_0000000000000037_0000000000000022_0000000000000015_000000000000000D_0000000000000008_0000000000000005_0000000000000003_0000000000000002_0000000000000001_0000000000000001_0000000000000000
221
- )
222
- expectEqual (
223
- 1 + ( 94 * UInt. bitWidth) , //-> 6017 bits.
224
- fibonacciSequence. actual. bitWidth
225
- )
226
- for wordIndex in 2 ..< 94 {
227
- expectEqual (
228
- fibonacciSequence. actual [ wordIndex] ,
229
- fibonacciSequence. actual [ wordIndex - 1 ] +
230
- fibonacciSequence. actual [ wordIndex - 2 ]
231
- )
232
- }
235
+ let wordCount = 94
236
+ let fibonacciSequence = Wrapper (
237
+ 0xA94FAD42221F2702_68A3DD8E61ECCFBD_40ABCFB3C0325745_27F80DDAA1BA7878_18B3C1D91E77DECD_0F444C01834299AB_096F75D79B354522_05D4D629E80D5489_039A9FADB327F099_023A367C34E563F0_016069317E428CA9_00D9CD4AB6A2D747_00869BE6C79FB562_00533163EF0321E5_00336A82D89C937D_001FC6E116668E68_0013A3A1C2360515_000C233F54308953_000780626E057BC2_0004A2DCE62B0D91_0002DD8587DA6E31_0001C5575E509F60_0001182E2989CED1_0000AD2934C6D08F_00006B04F4C2FE42_000042244003D24D_000028E0B4BF2BF5_000019438B44A658_00000F9D297A859D_000009A661CA20BB_000005F6C7B064E2_000003AF9A19BBD9_000002472D96A909_000001686C8312D0_000000DEC1139639_00000089AB6F7C97_0000005515A419A2_0000003495CB62F5_000000207FD8B6AD_0000001415F2AC48_0000000C69E60A65_00000007AC0CA1E3_00000004BDD96882_00000002EE333961_00000001CFA62F21_000000011E8D0A40_00000000B11924E1_000000006D73E55F_0000000043A53F82_0000000029CEA5DD_0000000019D699A5_000000000FF80C38_0000000009DE8D6D_0000000006197ECB_0000000003C50EA2_0000000002547029_0000000001709E79_0000000000E3D1B0_00000000008CCCC9_00000000005704E7_000000000035C7E2_0000000000213D05_0000000000148ADD_00000000000CB228_000000000007D8B5_000000000004D973_000000000002FF42_000000000001DA31_0000000000012511_000000000000B520_0000000000006FF1_000000000000452F_0000000000002AC2_0000000000001A6D_0000000000001055_0000000000000A18_000000000000063D_00000000000003DB_0000000000000262_0000000000000179_00000000000000E9_0000000000000090_0000000000000059_0000000000000037_0000000000000022_0000000000000015_000000000000000D_0000000000000008_0000000000000005_0000000000000003_0000000000000002_0000000000000001_0000000000000001_0000000000000000
238
+ )
233
239
#else
234
240
#error("Unimplemented")
235
241
#endif
242
+ expectEqual (
243
+ 1 + ( wordCount * UInt. bitWidth) ,
244
+ fibonacciSequence. actual. bitWidth
245
+ )
246
+ for wordIndex in 2 ..< wordCount {
247
+ expectEqual (
248
+ fibonacciSequence. actual [ wordIndex] ,
249
+ fibonacciSequence. actual [ wordIndex - 1 ] +
250
+ fibonacciSequence. actual [ wordIndex - 2 ]
251
+ )
236
252
}
237
253
}
238
254
}
0 commit comments