-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Negative sizes are not possible anymore Signed-off-by: Henrik Panhans <[email protected]>
- Loading branch information
1 parent
8c2949e
commit b6c1749
Showing
7 changed files
with
84 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Foundation | ||
|
||
enum Pluralizer { | ||
|
||
static func pluralize(_ value: Int, singular: String, plural: String, zero: String? = nil) -> String { | ||
let absoluteValue = abs(value) | ||
return switch absoluteValue { | ||
case 0: | ||
"\(value) \(zero ?? plural)" | ||
case 1: | ||
"\(value) \(singular)" | ||
default: | ||
"\(value) \(plural)" | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Foundation | ||
import XCTest | ||
@testable import SwiftFrameCore | ||
|
||
class PluralizerTests: XCTestCase { | ||
|
||
func testPluralizer_ProducesSingularString_WhenSpecifyingOne() { | ||
XCTAssertEqual(Pluralizer.pluralize(1, singular: "slice", plural: "slices"), "1 slice") | ||
} | ||
|
||
func testPluralizer_ProducesPluralString_WhenSpecifyingBigNumber() { | ||
XCTAssertEqual(Pluralizer.pluralize(32, singular: "slice", plural: "slices"), "32 slices") | ||
} | ||
|
||
func testPluralizer_ProducesPluralString_WhenSpecifyingZero() { | ||
XCTAssertEqual(Pluralizer.pluralize(0, singular: "slice", plural: "slices"), "0 slices") | ||
} | ||
|
||
func testPluralizer_ProducesZeroString_WhenSpecifyingZero() { | ||
XCTAssertEqual(Pluralizer.pluralize(0, singular: "slice", plural: "slices", zero: "bogus"), "0 bogus") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters