Skip to content

Commit 50b84f0

Browse files
committed
Merge branch 'release/3.3.0' into versions
2 parents 4f1f96b + 63127a8 commit 50b84f0

File tree

12 files changed

+151
-18
lines changed

12 files changed

+151
-18
lines changed

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se
1919

2020
## [Unreleased]
2121
### Added
22-
- None.
22+
- Added `round(fractionDigits:rule:)` & `rounded(fractionDigits:rule:)` methods to `Double` type.
23+
Author: [Cihat Gündüz](https://github.com/Jeehut)
2324
### Changed
2425
- None.
2526
### Deprecated
@@ -31,6 +32,11 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se
3132
### Security
3233
- None.
3334

35+
## [3.3.0] - 2021-01-16
36+
### Added
37+
- Added `round(fractionDigits:rule:)` & `rounded(fractionDigits:rule:)` methods to `Double` type.
38+
Author: [Cihat Gündüz](https://github.com/Jeehut)
39+
3440
## [3.2.1] - 2020-10-03
3541
### Changed
3642
- `Withable` doesn't require an empty `init()` method anymore. Instead, it can be combined with any initializer. If you used the `Foo { $0.bar = 5 }` type of initializer, you will need to add `().with` behind the type like so: `Foo().with { $0.bar = 5 }`.
@@ -54,15 +60,15 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se
5460
## [3.1.0] - 2019-09-01
5561
### Added
5662
- New `Comparable.clamped(to:)` and `Comparable.clamp(to:)` interfaces for any `Comparable`, e. g. `Int`.
57-
63+
5864
## [3.0.0] - 2019-04-30
5965
### Added
6066
- New `Withable` protocol to init/copy objects and set properties in a convenient way on a single line.
6167
### Changed
6268
- Upgraded to Swift 5 & Xcode 10.2.
6369
### Removed
6470
- Remove `ExpressibleByStringLiteral` conformance of `Regex` type to only allow initialization via `init(_:options:) throws` interface.
65-
71+
6672
## [2.8.0] - 2019-02-11
6773
### Added
6874
- New `NSRange(_:in:)` initializer for converting from `Range<String.Index>`
@@ -71,13 +77,13 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se
7177
- New `fullRange` and `fullNSRange` computed properties on `String`
7278
### Changed
7379
- Made some APIs available in wider contexts (like `sample` in `RandomAccessCollection` instead of `Array`)
74-
80+
7581
## [2.7.0] - 2018-09-27
7682
### Added
7783
- Official support for Linux & Swift Package Manager.
7884
### Removed
7985
- Support for Swift 4.1 and lower was dropped.
80-
86+
8187
## [2.6.0] - 2018-04-22
8288
### Added
8389
- New swifty `Regex` type built on top of the NSRegularExpression API.

HandySwift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "HandySwift"
4-
s.version = "3.2.1"
4+
s.version = "3.3.0"
55
s.summary = "Handy Swift features that didn't make it into the Swift standard library"
66

77
s.description = <<-DESC

HandySwift.xcodeproj/project.pbxproj

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,21 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
2E18AD5A2531DD3D00D44748 /* DoubleExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E18AD592531DD3D00D44748 /* DoubleExt.swift */; };
11+
2E18AD5B2531DD3D00D44748 /* DoubleExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E18AD592531DD3D00D44748 /* DoubleExt.swift */; };
12+
2E18AD5C2531DD3D00D44748 /* DoubleExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E18AD592531DD3D00D44748 /* DoubleExt.swift */; };
13+
2E18AD732531E0FD00D44748 /* DoubleExtTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E18AD632531E0F800D44748 /* DoubleExtTests.swift */; };
14+
2E18AD7A2531E0FD00D44748 /* DoubleExtTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E18AD632531E0F800D44748 /* DoubleExtTests.swift */; };
15+
2E18AD812531E0FE00D44748 /* DoubleExtTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E18AD632531E0F800D44748 /* DoubleExtTests.swift */; };
1016
2E18B292242DECCA000C7776 /* NSObjectExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E18B291242DECCA000C7776 /* NSObjectExt.swift */; };
1117
2E18B293242DECCA000C7776 /* NSObjectExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E18B291242DECCA000C7776 /* NSObjectExt.swift */; };
1218
2E18B294242DECCA000C7776 /* NSObjectExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E18B291242DECCA000C7776 /* NSObjectExt.swift */; };
1319
2E18B296242DF436000C7776 /* NSObjectExtTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E18B295242DF436000C7776 /* NSObjectExtTests.swift */; };
1420
2E18B297242DF436000C7776 /* NSObjectExtTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E18B295242DF436000C7776 /* NSObjectExtTests.swift */; };
1521
2E18B298242DF436000C7776 /* NSObjectExtTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E18B295242DF436000C7776 /* NSObjectExtTests.swift */; };
22+
2E5A375425655F55003704D0 /* StringProtocolExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E5A375325655F55003704D0 /* StringProtocolExt.swift */; };
23+
2E5A375525655F55003704D0 /* StringProtocolExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E5A375325655F55003704D0 /* StringProtocolExt.swift */; };
24+
2E5A375625655F55003704D0 /* StringProtocolExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E5A375325655F55003704D0 /* StringProtocolExt.swift */; };
1625
2E61DF7A249E1CA9000AF3C5 /* Withable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E61DF79249E1CA9000AF3C5 /* Withable.swift */; };
1726
2E61DF7B249E1CA9000AF3C5 /* Withable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E61DF79249E1CA9000AF3C5 /* Withable.swift */; };
1827
2E61DF7C249E1CA9000AF3C5 /* Withable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E61DF79249E1CA9000AF3C5 /* Withable.swift */; };
@@ -139,9 +148,12 @@
139148
/* End PBXContainerItemProxy section */
140149

141150
/* Begin PBXFileReference section */
151+
2E18AD592531DD3D00D44748 /* DoubleExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DoubleExt.swift; sourceTree = "<group>"; };
152+
2E18AD632531E0F800D44748 /* DoubleExtTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DoubleExtTests.swift; sourceTree = "<group>"; };
142153
2E18B291242DECCA000C7776 /* NSObjectExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSObjectExt.swift; sourceTree = "<group>"; };
143154
2E18B295242DF436000C7776 /* NSObjectExtTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSObjectExtTests.swift; sourceTree = "<group>"; };
144155
2E4189DB231B971E00C65B81 /* .gitignore */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; };
156+
2E5A375325655F55003704D0 /* StringProtocolExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringProtocolExt.swift; sourceTree = "<group>"; };
145157
2E61DF79249E1CA9000AF3C5 /* Withable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Withable.swift; sourceTree = "<group>"; };
146158
2E61DF7D249E1D37000AF3C5 /* WithableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WithableTests.swift; sourceTree = "<group>"; };
147159
3F95C8D120F22A3C0045AFD0 /* CollectionExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionExt.swift; sourceTree = "<group>"; };
@@ -188,7 +200,7 @@
188200
C5C89B9320B0A0C10048B07C /* Weak.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = "<group>"; };
189201
C5CFB6AB20B0A70300830511 /* Unowned.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Unowned.swift; sourceTree = "<group>"; };
190202
CC120CC1205FDB9300C37D7C /* Regex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Regex.swift; sourceTree = "<group>"; };
191-
CC4AE0CD2087D895009931F6 /* RegexTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegexTests.swift; sourceTree = "<group>"; };
203+
CC4AE0CD2087D895009931F6 /* RegexTests.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = RegexTests.swift; sourceTree = "<group>"; tabWidth = 4; };
192204
CC66E046228199A0007ABF61 /* ComparableExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComparableExt.swift; sourceTree = "<group>"; };
193205
CC66E12322819FCF007ABF61 /* ComparableExtTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComparableExtTests.swift; sourceTree = "<group>"; };
194206
/* End PBXFileReference section */
@@ -256,8 +268,8 @@
256268
8203930420F3A63F0074974F /* HandySwiftTests */ = {
257269
isa = PBXGroup;
258270
children = (
259-
82812A9E1D06926800CD5B6C /* GlobalsTests.swift */,
260271
823B2B4E1C24ABD8007B3CDD /* Extensions */,
272+
82812A9E1D06926800CD5B6C /* GlobalsTests.swift */,
261273
8251AA23227875A10022B277 /* Protocols */,
262274
8258E4571C2E196B0031CBFF /* Structs */,
263275
);
@@ -295,10 +307,12 @@
295307
CC66E046228199A0007ABF61 /* ComparableExt.swift */,
296308
8280D7DB1C4A6EC9001172EF /* DictionaryExt.swift */,
297309
A1F221631E3CC05100419B06 /* DispatchTimeIntervalExt.swift */,
310+
2E18AD592531DD3D00D44748 /* DoubleExt.swift */,
298311
823B2B4C1C24ABA4007B3CDD /* IntExt.swift */,
299312
2E18B291242DECCA000C7776 /* NSObjectExt.swift */,
300313
8218E4D52211D193007AAAF3 /* NSRangeExt.swift */,
301314
82CAE2911C2ED1A200F934A7 /* StringExt.swift */,
315+
2E5A375325655F55003704D0 /* StringProtocolExt.swift */,
302316
A11830D21E589F6700CBE087 /* TimeIntervalExt.swift */,
303317
);
304318
path = Extensions;
@@ -312,6 +326,7 @@
312326
CC66E12322819FCF007ABF61 /* ComparableExtTests.swift */,
313327
8280D7DF1C4A6FF3001172EF /* DictionaryExtTests.swift */,
314328
827599631E520FB800787F99 /* DispatchTimeIntervalExtTests.swift */,
329+
2E18AD632531E0F800D44748 /* DoubleExtTests.swift */,
315330
823B2B4F1C24AC00007B3CDD /* IntExtTests.swift */,
316331
2E18B295242DF436000C7776 /* NSObjectExtTests.swift */,
317332
8218E4D92211D270007AAAF3 /* NSRangeExtTests.swift */,
@@ -775,10 +790,12 @@
775790
CC66E047228199A0007ABF61 /* ComparableExt.swift in Sources */,
776791
C5C89B9420B0A0C10048B07C /* Weak.swift in Sources */,
777792
82CAE2921C2ED1A200F934A7 /* StringExt.swift in Sources */,
793+
2E18AD5A2531DD3D00D44748 /* DoubleExt.swift in Sources */,
778794
82CAE2961C2EE64900F934A7 /* ArrayExt.swift in Sources */,
779795
2E61DF7A249E1CA9000AF3C5 /* Withable.swift in Sources */,
780796
C5CFB6AC20B0A70300830511 /* Unowned.swift in Sources */,
781797
82812A9B1D06877B00CD5B6C /* Globals.swift in Sources */,
798+
2E5A375425655F55003704D0 /* StringProtocolExt.swift in Sources */,
782799
63651F90231BFF2000E022DA /* DivisibleArithmetic.swift in Sources */,
783800
8280D7DC1C4A6EC9001172EF /* DictionaryExt.swift in Sources */,
784801
A11830D31E589F6700CBE087 /* TimeIntervalExt.swift in Sources */,
@@ -804,6 +821,7 @@
804821
3F95C8D520F22DEE0045AFD0 /* CollectionExtTests.swift in Sources */,
805822
2E18B296242DF436000C7776 /* NSObjectExtTests.swift in Sources */,
806823
CC4AE0CF2087D8A7009931F6 /* RegexTests.swift in Sources */,
824+
2E18AD732531E0FD00D44748 /* DoubleExtTests.swift in Sources */,
807825
);
808826
runOnlyForDeploymentPostprocessing = 0;
809827
};
@@ -822,10 +840,12 @@
822840
CC66E048228199DE007ABF61 /* ComparableExt.swift in Sources */,
823841
C5CFB6AF20B0A78F00830511 /* Weak.swift in Sources */,
824842
A1F221651E3CC05100419B06 /* DispatchTimeIntervalExt.swift in Sources */,
843+
2E18AD5B2531DD3D00D44748 /* DoubleExt.swift in Sources */,
825844
825EFE021C33358400558497 /* SortedArray.swift in Sources */,
826845
2E61DF7B249E1CA9000AF3C5 /* Withable.swift in Sources */,
827846
825EFE031C33358400558497 /* IntExt.swift in Sources */,
828847
82812A9C1D06877B00CD5B6C /* Globals.swift in Sources */,
848+
2E5A375525655F55003704D0 /* StringProtocolExt.swift in Sources */,
829849
63651F91231BFF2000E022DA /* DivisibleArithmetic.swift in Sources */,
830850
8280D7DD1C4A6EC9001172EF /* DictionaryExt.swift in Sources */,
831851
A11830D41E589F6700CBE087 /* TimeIntervalExt.swift in Sources */,
@@ -851,6 +871,7 @@
851871
3F95C8D620F22DEF0045AFD0 /* CollectionExtTests.swift in Sources */,
852872
2E18B297242DF436000C7776 /* NSObjectExtTests.swift in Sources */,
853873
CC4AE0D02087D8A8009931F6 /* RegexTests.swift in Sources */,
874+
2E18AD7A2531E0FD00D44748 /* DoubleExtTests.swift in Sources */,
854875
);
855876
runOnlyForDeploymentPostprocessing = 0;
856877
};
@@ -869,10 +890,12 @@
869890
CC66E049228199DF007ABF61 /* ComparableExt.swift in Sources */,
870891
C5CFB6B020B0A79000830511 /* Weak.swift in Sources */,
871892
A1F221661E3CC05100419B06 /* DispatchTimeIntervalExt.swift in Sources */,
893+
2E18AD5C2531DD3D00D44748 /* DoubleExt.swift in Sources */,
872894
825EFE081C33358500558497 /* SortedArray.swift in Sources */,
873895
2E61DF7C249E1CA9000AF3C5 /* Withable.swift in Sources */,
874896
825EFE091C33358500558497 /* IntExt.swift in Sources */,
875897
82812A9D1D06877B00CD5B6C /* Globals.swift in Sources */,
898+
2E5A375625655F55003704D0 /* StringProtocolExt.swift in Sources */,
876899
63651F92231BFF2800E022DA /* DivisibleArithmetic.swift in Sources */,
877900
8280D7DE1C4A6EC9001172EF /* DictionaryExt.swift in Sources */,
878901
A11830D51E589F6700CBE087 /* TimeIntervalExt.swift in Sources */,
@@ -898,6 +921,7 @@
898921
3F95C8D720F22DEF0045AFD0 /* CollectionExtTests.swift in Sources */,
899922
2E18B298242DF436000C7776 /* NSObjectExtTests.swift in Sources */,
900923
CC4AE0D12087D8A9009931F6 /* RegexTests.swift in Sources */,
924+
2E18AD812531E0FE00D44748 /* DoubleExtTests.swift in Sources */,
901925
);
902926
runOnlyForDeploymentPostprocessing = 0;
903927
};

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
alt="Coverage"/>
1414
</a>
1515
<a href="https://github.com/Flinesoft/HandySwift/releases">
16-
<img src="https://img.shields.io/badge/Version-3.2.1-blue.svg"
17-
alt="Version: 3.2.1">
16+
<img src="https://img.shields.io/badge/Version-3.3.0-blue.svg"
17+
alt="Version: 3.3.0">
1818
</a>
1919
<img src="https://img.shields.io/badge/Swift-5.1-FFAC45.svg" alt="Swift: 5.1">
2020
<img src="https://img.shields.io/badge/Platforms-iOS%20%7C%20tvOS%20%7C%20macOS%20%7C%20Linux-FF69B4.svg"
@@ -74,6 +74,7 @@ Open the Playground from within the `.xcworkspace` in order for it to work.
7474
- Extensions
7575
- [IntExtension](#intextension)
7676
- [IntegerTypeExtension](#integertypeextension)
77+
- [DoubleExtension](#doubleextension)
7778
- [StringExtension](#stringextension)
7879
- [NSRangeExtension](#nsrangeextension)
7980
- [CollectionExtension](#collectionextension)
@@ -166,6 +167,30 @@ myNum.clamp(to: 0...2)
166167
myNum // => 2
167168
```
168169

170+
### DoubleExtension
171+
172+
#### round(fractionDigits:rule:)
173+
174+
Rounds the value to an integral value using the specified fraction digits and rounding rule.
175+
176+
``` Swift
177+
var price: Double = 2.875
178+
price.round(fractionDigits: 2) // => 2.88
179+
// OR with explicit rule:
180+
price.round(fractionDigits: 2, rule: .down) // 2.87
181+
```
182+
183+
#### rounded(fractionDigits:rule:) -> Double
184+
185+
Returns this value rounded to an integral value using the specified fraction digits and rounding rule.
186+
187+
``` Swift
188+
let price: Double = 2.875
189+
price.rounded(fractionDigits: 2) // => 2.88
190+
// OR with explicit rule:
191+
price.rounded(fractionDigits: 2, rule: .down) // => 2.87
192+
```
193+
169194
### StringExtension
170195

171196
#### .stripped()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright © 2020 Flinesoft. All rights reserved.
2+
3+
import Foundation
4+
5+
extension Double {
6+
/// Rounds the value to an integral value using the specified fraction digits and rounding rule.
7+
///
8+
/// - NOTE: Dropping the `rule` parameter will default to “schoolbook rounding”.
9+
public mutating func round(fractionDigits: Int, rule: FloatingPointRoundingRule = .toNearestOrAwayFromZero) {
10+
let divisor = pow(10.0, Double(fractionDigits))
11+
self = (self * divisor).rounded(rule) / divisor
12+
}
13+
14+
/// Returns this value rounded to an integral value using the specified fraction digits and rounding rule.
15+
///
16+
/// - NOTE: Dropping the `rule` parameter will default to “schoolbook rounding”.
17+
public func rounded(fractionDigits: Int, rule: FloatingPointRoundingRule = .toNearestOrAwayFromZero) -> Double {
18+
let divisor = pow(10.0, Double(fractionDigits))
19+
return (self * divisor).rounded(rule) / divisor
20+
}
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright © 2020 Flinesoft. All rights reserved.
2+
3+
import Foundation
4+
5+
extension StringProtocol {
6+
/// Returns a variation with the first character uppercased.
7+
public var firstUppercased: String { prefix(1).uppercased() + dropFirst() }
8+
9+
/// Returns a variation with the first character capitalized.
10+
public var firstCapitalized: String { prefix(1).capitalized + dropFirst() }
11+
12+
/// Returns a variation with the first character lowercased.
13+
public var firstLowercased: String { prefix(1).lowercased() + dropFirst() }
14+
}

Sources/HandySwift/Structs/Regex.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ public struct Regex {
4747
/// - returns: An optional `Match` describing the first match, or `nil`.
4848
@inlinable
4949
public func firstMatch(in string: String) -> Match? {
50-
let firstMatch = regularExpression
50+
regularExpression
5151
.firstMatch(in: string, options: [], range: NSRange(location: 0, length: string.utf16.count))
5252
.map { Match(result: $0, in: string) }
53-
return firstMatch
5453
}
5554

5655
/// If the regex matches `string`, returns an array of `Match`, describing
@@ -62,10 +61,9 @@ public struct Regex {
6261
/// - returns: An array of `Match` describing every match in `string`.
6362
@inlinable
6463
public func matches(in string: String) -> [Match] {
65-
let matches = regularExpression
64+
regularExpression
6665
.matches(in: string, options: [], range: NSRange(location: 0, length: string.utf16.count))
6766
.map { Match(result: $0, in: string) }
68-
return matches
6967
}
7068

7169
// MARK: Replacing
@@ -246,14 +244,12 @@ extension Regex {
246244
///
247245
/// - returns: A string with `template` applied to the matched string.
248246
public func string(applyingTemplate template: String) -> String {
249-
let replacement = result.regularExpression!.replacementString(
247+
result.regularExpression!.replacementString(
250248
for: result,
251249
in: baseString,
252250
offset: 0,
253251
template: template
254252
)
255-
256-
return replacement
257253
}
258254

259255
// MARK: - CustomStringConvertible

Sources/SupportingFiles/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>3.2.1</string>
18+
<string>3.3.0</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright © 2020 Flinesoft. All rights reserved.
2+
3+
@testable import HandySwift
4+
import XCTest
5+
6+
class DoubleExtTests: XCTestCase {
7+
func testRound() {
8+
var price: Double = 2.875
9+
price.round(fractionDigits: 2)
10+
XCTAssertEqual(price, 2.88)
11+
12+
price = 2.875
13+
price.round(fractionDigits: 2, rule: .down)
14+
XCTAssertEqual(price, 2.87)
15+
}
16+
17+
func testRounded() {
18+
let price: Double = 2.875
19+
XCTAssertEqual(price.rounded(fractionDigits: 2), 2.88)
20+
XCTAssertEqual(price.rounded(fractionDigits: 2, rule: .down), 2.87)
21+
}
22+
}

0 commit comments

Comments
 (0)