This file contains hidden or 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
.DS_Store | |
/.build | |
/Packages | |
/*.xcodeproj | |
Package.resolved | |
!*.xcodeproj/project.pbxproj | |
!*.xcodeproj/xcshareddata/ | |
!*.xcodeproj/*_Info.plist |
This file contains hidden or 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
// swift-tools-version:4.0 | |
// The swift-tools-version declares the minimum version of Swift required to build this package. | |
import PackageDescription | |
let package = Package( | |
name: "xProcs", | |
products: [ | |
// Products define the executables and libraries produced by a package, and make them visible to other packages. | |
.library( |
This file contains hidden or 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
import XCTest | |
import xProcs | |
class IntTests: XCTestCase { | |
func testIntPow() { | |
XCTAssertEqual(IntPow(5, exp: 2), 25) | |
XCTAssertEqual(IntPow(5, exp: 1), 5) | |
XCTAssertEqual(IntPow(5, exp: 0), 1) | |
} |
This file contains hidden or 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
import Foundation | |
public func IntPow(_ base: Int, exp: Int) -> Int { | |
guard exp >= 0 else { | |
return 0 | |
} | |
guard exp > 0 else { | |
return 1 | |
} | |
return (1..<exp).reduce(base) { (accu, _) in accu * abs(base) } |
OlderNewer