-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add times implementation with tests + Empty playground for usage exam…
…ples
- Loading branch information
Showing
10 changed files
with
136 additions
and
41 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,29 @@ | ||
// | ||
// IntegerTypeExtension.swift | ||
// HandySwift | ||
// | ||
// Created by Cihat Gündüz on 18.12.15. | ||
// Copyright © 2015 Flinesoft. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension IntegerType { | ||
|
||
public func times(closure: () -> ()) { | ||
guard self > 0 else { return } | ||
|
||
for _ in 1...self { | ||
closure() | ||
} | ||
} | ||
|
||
public func times(closure: (Self) -> ()) { | ||
guard self > 0 else { return } | ||
|
||
for i in 1...self { | ||
closure(i) | ||
} | ||
} | ||
|
||
} |
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
48 changes: 48 additions & 0 deletions
48
HandySwiftTests/Extensions/IntegerTypeExtensionTests.swift
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,48 @@ | ||
// | ||
// IntegerTypeExtensionTests.swift | ||
// HandySwift | ||
// | ||
// Created by Cihat Gündüz on 18.12.15. | ||
// Copyright © 2015 Flinesoft. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
|
||
@testable import HandySwift | ||
|
||
class IntegerTypeExtensionTests: XCTestCase { | ||
|
||
func testTimesClosureWithoutArgument() { | ||
var testString = "" | ||
|
||
0.times { | ||
testString += "." | ||
} | ||
|
||
XCTAssertEqual(testString, "") | ||
|
||
3.times { | ||
testString += "." | ||
} | ||
|
||
XCTAssertEqual(testString, "...") | ||
} | ||
|
||
func testTimesClosureWithArgument() { | ||
var testString = "" | ||
|
||
0.times { i in | ||
testString += "\(i)" | ||
} | ||
|
||
XCTAssertEqual(testString, "") | ||
|
||
3.times { i in | ||
testString += "\(i)" | ||
} | ||
|
||
XCTAssertEqual(testString, "123") | ||
} | ||
|
||
|
||
} |
This file was deleted.
Oops, something went wrong.
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,2 @@ | ||
import HandySwift | ||
|
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,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='ios'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> |
7 changes: 7 additions & 0 deletions
7
UsageExamples.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Timeline | ||
version = "3.0"> | ||
<TimelineItems> | ||
</TimelineItems> | ||
</Timeline> |