@@ -1163,6 +1163,50 @@ class TestDecimal: XCTestCase {
1163
1163
XCTAssertEqual ( NSDecimalNumber ( value: 1 ) . multiplying ( byPowerOf10: - 129 ) . stringValue, " NaN " )
1164
1164
}
1165
1165
1166
+ func test_SignedNumeric( ) {
1167
+ // This really requires some tests using a BinaryInteger of bitwidth > 128 to test failures.
1168
+ let d1 = Decimal ( exactly: UInt64 . max)
1169
+ XCTAssertNotNil ( d1)
1170
+ XCTAssertEqual ( d1? . description, UInt64 . max. description)
1171
+ XCTAssertEqual ( d1? . _length, 4 )
1172
+
1173
+ let d2 = Decimal ( exactly: Int64 . min)
1174
+ XCTAssertNotNil ( d2)
1175
+ XCTAssertEqual ( d2? . description, Int64 . min. description)
1176
+ XCTAssertEqual ( d2? . _length, 4 )
1177
+
1178
+ let d3 = Decimal ( exactly: Int64 . max)
1179
+ XCTAssertNotNil ( d3)
1180
+ XCTAssertEqual ( d3? . description, Int64 . max. description)
1181
+ XCTAssertEqual ( d3? . _length, 4 )
1182
+
1183
+ let d4 = Decimal ( exactly: Int32 . min)
1184
+ XCTAssertNotNil ( d4)
1185
+ XCTAssertEqual ( d4? . description, Int32 . min. description)
1186
+ XCTAssertEqual ( d4? . _length, 2 )
1187
+
1188
+ let d5 = Decimal ( exactly: Int32 . max)
1189
+ XCTAssertNotNil ( d5)
1190
+ XCTAssertEqual ( d5? . description, Int32 . max. description)
1191
+ XCTAssertEqual ( d5? . _length, 2 )
1192
+
1193
+ let d6 = Decimal ( exactly: 0 )
1194
+ XCTAssertNotNil ( d6)
1195
+ XCTAssertEqual ( d6, Decimal . zero)
1196
+ XCTAssertEqual ( d6? . description, " 0 " )
1197
+ XCTAssertEqual ( d6? . _length, 0 )
1198
+
1199
+ let d7 = Decimal ( exactly: 1 )
1200
+ XCTAssertNotNil ( d7)
1201
+ XCTAssertEqual ( d7? . description, " 1 " )
1202
+ XCTAssertEqual ( d7? . _length, 1 )
1203
+
1204
+ let d8 = Decimal ( exactly: - 1 )
1205
+ XCTAssertNotNil ( d8)
1206
+ XCTAssertEqual ( d8? . description, " -1 " )
1207
+ XCTAssertEqual ( d8? . _length, 1 )
1208
+ }
1209
+
1166
1210
static var allTests : [ ( String , ( TestDecimal ) -> ( ) throws -> Void ) ] {
1167
1211
return [
1168
1212
( " test_NSDecimalNumberInit " , test_NSDecimalNumberInit) ,
@@ -1191,6 +1235,7 @@ class TestDecimal: XCTestCase {
1191
1235
( " test_stringWithLocale " , test_stringWithLocale) ,
1192
1236
( " test_NSDecimalString " , test_NSDecimalString) ,
1193
1237
( " test_multiplyingByPowerOf10 " , test_multiplyingByPowerOf10) ,
1238
+ ( " test_SignedNumeric " , test_SignedNumeric) ,
1194
1239
]
1195
1240
}
1196
1241
}
0 commit comments