Skip to content

Commit

Permalink
Merge pull request #9 from bkase/swift31
Browse files Browse the repository at this point in the history
Port to Swift 3.1 + PackageManager
  • Loading branch information
CodaFi authored May 20, 2017
2 parents 549e02d + 9fb62c3 commit 94206cc
Show file tree
Hide file tree
Showing 20 changed files with 312 additions and 161 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ DerivedData
*.xcscmblueprint
Carthage/

# SwiftPM
.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
Expand Down
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.1
24 changes: 13 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@ matrix:
include:
- os: osx
language: objective-c
osx_image: xcode7.3
osx_image: xcode8.3
before_install:
- git submodule update --init --recursive
script:
# Restore pod build before shipping for 3.0
# Restore pod build before shipping for 3.0
# - pod lib lint
# Generate xcodeprojects for the pure Swift PM deps
- (cd Carthage/Checkouts/Operadics && xcrun swift package generate-xcodeproj --xcconfig-overrides ../../../deployments.xcconfig)
- carthage build --no-skip-current
- os: osx
language: objective-c
osx_image: xcode7.3
osx_image: xcode8.3
before_install:
# Generate xcodeprojects for the pure Swift PM deps
- (cd Carthage/Checkouts/Operadics && xcrun swift package generate-xcodeproj --xcconfig-overrides ../../../deployments.xcconfig)
- git submodule update --init --recursive
script:
- set -o pipefail
- xcodebuild test -scheme Algebra | xcpretty -c
# !!!: Make sure desired device name & OS version are suitable for the Xcode version installed on osx_image
- iOS_DEVICE_NAME="iPad Pro"
- iOS_RUNTIME_VERSION="9.3"
- iOS_DEVICE_NAME="iPad Air"
- iOS_RUNTIME_VERSION="10.3"
# Get simulator identifier for desired device/runtime pair
- SIMULATOR_ID=$(xcrun instruments -s | grep -o "${iOS_DEVICE_NAME} (${iOS_RUNTIME_VERSION}) \[.*\]" | grep -o "\[.*\]" | sed "s/^\[\(.*\)\]$/\1/")
- echo $SIMULATOR_ID
Expand All @@ -36,13 +40,11 @@ matrix:
dist: trusty
before_install:
- git submodule update --init --recursive
- wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -
- wget https://swift.org/builds/swift-2.2.1-release/ubuntu1404/swift-2.2.1-RELEASE/swift-2.2.1-RELEASE-ubuntu14.04.tar.gz
- tar xzf swift-2.2.1-RELEASE-ubuntu14.04.tar.gz
- export PATH=${PWD}/swift-2.2.1-RELEASE-ubuntu14.04/usr/bin:"${PATH}"
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
- rm -rf Carthage
script:
# Uncomment when releasing Swift 3.0
# - swift build
- swift build
- SWIFTPM_TEST_Algebra=YES swift test
notifications:
webhooks:
urls:
Expand Down
193 changes: 155 additions & 38 deletions Algebra.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@

},
"DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : {
"53964F28C4CCA0826677C9F951DD3F64C20326C4" : 0,
"570C4D95BE80B5E8C6FFC0BED8318BC62404E6A6" : 0,
"B1566CF92CFABA5E37554B7B555A1BA50691C03A" : 0
"53964F28C4CCA0826677C9F951DD3F64C20326C4" : 9223372036854775807,
"570C4D95BE80B5E8C6FFC0BED8318BC62404E6A6" : 9223372036854775807,
"B1566CF92CFABA5E37554B7B555A1BA50691C03A" : 9223372036854775807
},
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "7463F262-5386-4D27-88FC-7EDEE3B15B7F",
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "B9716910-90F7-4DC2-BC98-DD5F4D526F33",
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
"53964F28C4CCA0826677C9F951DD3F64C20326C4" : "Algebra\/Carthage\/Checkouts\/SwiftCheck\/",
"53964F28C4CCA0826677C9F951DD3F64C20326C4" : "Algebra\/.build\/checkouts\/SwiftCheck.git--4306398712468813520\/",
"570C4D95BE80B5E8C6FFC0BED8318BC62404E6A6" : "Algebra\/",
"B1566CF92CFABA5E37554B7B555A1BA50691C03A" : "Algebra\/Carthage\/Checkouts\/SwiftCheck\/Carthage\/Checkouts\/Operadics\/"
"B1566CF92CFABA5E37554B7B555A1BA50691C03A" : "Algebra\/Carthage\/Checkouts\/Operadics\/"
},
"DVTSourceControlWorkspaceBlueprintNameKey" : "Algebra",
"DVTSourceControlWorkspaceBlueprintVersion" : 203,
"DVTSourceControlWorkspaceBlueprintVersion" : 204,
"DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "Algebra.xcodeproj",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [
{
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/typelift\/SwiftCheck.git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "\/Users\/bkase\/Algebra\/.build\/repositories\/SwiftCheck.git--4306398712468813520",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "53964F28C4CCA0826677C9F951DD3F64C20326C4"
},
{
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/CodaFi\/Algebra.git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:bkase\/Algebra.git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "570C4D95BE80B5E8C6FFC0BED8318BC62404E6A6"
},
{
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/typelift\/Operadics.git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "\/Users\/bkase\/Algebra\/.build\/repositories\/Operadics.git-5626071303828032414",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "B1566CF92CFABA5E37554B7B555A1BA50691C03A"
}
Expand Down
5 changes: 3 additions & 2 deletions Algebra/AlgebraOperators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
// Copyright (c) 2014 TypeLift. All rights reserved.
//

infix operator *<> { }
infix operator <>* { }
// TODO: Uncomment these operators when we figure out a way to use them with Modules
// infix operator *<>
// infix operator <>*
12 changes: 6 additions & 6 deletions Algebra/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
///
/// a <> b = b <> a = e
protocol Group : Additive {
static func invert(_ : M) -> M
static func invert(_ : Self) -> Self
}

/// An Abelian Group is a group where the binary operation is commutative. That is forall 'a', 'b',
Expand All @@ -21,19 +21,19 @@ protocol Group : Additive {
protocol AbelianGroup : Group { }

extension Int : Group {
static func invert(l : Int) -> Int { return -l }
static func invert(_ l : Int) -> Int { return -l }
}
extension Int8 : Group {
static func invert(l : Int8) -> Int8 { return -l }
static func invert(_ l : Int8) -> Int8 { return -l }
}
extension Int16 : Group {
static func invert(l : Int16) -> Int16 { return -l }
static func invert(_ l : Int16) -> Int16 { return -l }
}
extension Int32 : Group {
static func invert(l : Int32) -> Int32 { return -l }
static func invert(_ l : Int32) -> Int32 { return -l }
}
extension Int64 : Group {
static func invert(l : Int64) -> Int64 { return -l }
static func invert(_ l : Int64) -> Int64 { return -l }
}

extension Int : AbelianGroup { }
Expand Down
8 changes: 4 additions & 4 deletions Algebra/Lattice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
/// operation that computes the least upper bound).
protocol JoinSemilattice {
associatedtype L
static func join(_ : L) -> L -> L
static func join(_ : L) -> (L) -> L
}

/// A Meet-Semilattice is a partially ordered set that defines a meet operation (that is, has an
/// operation that computes the greatest lower bound).
protocol MeetSemilattice {
associatedtype L
static func meet(_ : L) -> L -> L
static func meet(_ : L) -> (L) -> L
}

/// A Lattice is a partially ordered set that defines both a meet and join operation.
Expand All @@ -41,13 +41,13 @@ protocol BoundedLattice : BoundedJoinSemilattice, BoundedMeetSemilattice { }

extension Bool : JoinSemilattice {
typealias L = Bool
public static func join(l : Bool) -> Bool -> Bool {
public static func join(_ l : Bool) -> (Bool) -> Bool {
return { r in l || r }
}
}

extension Bool : MeetSemilattice {
public static func meet(l : Bool) -> Bool -> Bool {
public static func meet(_ l : Bool) -> (Bool) -> Bool {
return { r in l && r }
}
}
Expand Down
70 changes: 42 additions & 28 deletions Algebra/Magma.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,62 @@
// Copyright (c) 2014 TypeLift. All rights reserved.
//

import Operadics

/// A magma is a set and a closed binary operator. It is usually not studied because it forms the
/// basis of more interesting structures.
protocol Magma {
associatedtype M
func <>(_ : M, _ : M) -> M
static func <>(_ : Self, _ : Self) -> Self
}

extension Bool : Magma { typealias M = Bool }
public func <>(l : Bool, r : Bool) -> Bool { return l || r }
extension Bool : Magma {
public static func <>(l : Bool, r : Bool) -> Bool { return l || r }
}

extension UInt : Magma { typealias M = UInt }
public func <>(l : UInt, r : UInt) -> UInt { return l &+ r }
extension UInt : Magma {
public static func <>(l : UInt, r : UInt) -> UInt { return l &+ r }
}

extension UInt8 : Magma { typealias M = UInt8 }
public func <>(l : UInt8, r : UInt8) -> UInt8 { return l &+ r }
extension UInt8 : Magma {
public static func <>(l : UInt8, r : UInt8) -> UInt8 { return l &+ r }
}

extension UInt16 : Magma { typealias M = UInt16 }
public func <>(l : UInt16, r : UInt16) -> UInt16 { return l &+ r }
extension UInt16 : Magma {
public static func <>(l : UInt16, r : UInt16) -> UInt16 { return l &+ r }
}

extension UInt32 : Magma { typealias M = UInt32 }
public func <>(l : UInt32, r : UInt32) -> UInt32 { return l &+ r }
extension UInt32 : Magma {
public static func <>(l : UInt32, r : UInt32) -> UInt32 { return l &+ r }
}

extension UInt64 : Magma { typealias M = UInt64 }
public func <>(l : UInt64, r : UInt64) -> UInt64 { return l &+ r }
extension UInt64 : Magma {
public static func <>(l : UInt64, r : UInt64) -> UInt64 { return l &+ r }
}

extension Int : Magma { typealias M = Int }
public func <>(l : Int, r : Int) -> Int { return l &+ r }
extension Int : Magma {
public static func <>(l : Int, r : Int) -> Int { return l &+ r }
}

extension Int8 : Magma { typealias M = Int8 }
public func <>(l : Int8, r : Int8) -> Int8 { return l &+ r }
extension Int8 : Magma {
public static func <>(l : Int8, r : Int8) -> Int8 { return l &+ r }
}

extension Int16 : Magma { typealias M = Int16 }
public func <>(l : Int16, r : Int16) -> Int16 { return l &+ r }
extension Int16 : Magma {
public static func <>(l : Int16, r : Int16) -> Int16 { return l &+ r }
}

extension Int32 : Magma { typealias M = Int32 }
public func <>(l : Int32, r : Int32) -> Int32 { return l &+ r }
extension Int32 : Magma {
public static func <>(l : Int32, r : Int32) -> Int32 { return l &+ r }
}

extension Int64 : Magma { typealias M = Int64 }
public func <>(l : Int64, r : Int64) -> Int64 { return l &+ r }
extension Int64 : Magma {
public static func <>(l : Int64, r : Int64) -> Int64 { return l &+ r }
}

extension Float : Magma { typealias M = Float }
public func <>(l : Float, r : Float) -> Float { return l + r }
extension Float : Magma {
public static func <>(l : Float, r : Float) -> Float { return l + r }
}

extension Double : Magma { typealias M = Double }
public func <>(l : Double, r : Double) -> Double { return l + r }
extension Double : Magma {
public static func <>(l : Double, r : Double) -> Double { return l + r }
}
83 changes: 27 additions & 56 deletions Algebra/Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,38 @@
//

/// If R is a Ring and M is an abelian group, a Left Module defines a binary operation R *<> M -> M.
protocol LeftModule {
associatedtype R : Semiring
associatedtype A : Additive
func *<>(_ : R, _ : A) -> A
struct LeftModule<R: Semiring, A: Additive> {
let multiply: (R, A) -> A
}
enum LeftModules {
static let int = LeftModule<Int, Int>(multiply: *)
static let int8 = LeftModule<Int, Int8>(multiply: { Int8($0) * $1 })
static let int16 = LeftModule<Int, Int16>(multiply: { Int16($0) * $1 })
static let int32 = LeftModule<Int, Int32>(multiply: { Int32($0) * $1 })
static let int64 = LeftModule<Int, Int64>(multiply: { Int64($0) * $1 })
}

/// If R is a Ring and M is an abelian group, a Right Module defines a binary operation M <>* R -> M.
protocol RightModule {
associatedtype R : Semiring
associatedtype M : Additive
func <>* (_ : M, _ : R) -> M
struct RightModule<A: Additive, R: Semiring> {
let multiply: (A, R) -> A
}
enum RightModules {
static let int = RightModule<Int, Int>(multiply: *)
static let int8 = RightModule<Int8, Int>(multiply: { $0 * Int8($1) })
static let int16 = RightModule<Int16, Int>(multiply: { $0 * Int16($1) })
static let int32 = RightModule<Int32, Int>(multiply: { $0 * Int32($1) })
static let int64 = RightModule<Int64, Int>(multiply: { $0 * Int64($1) })
}

/// A bimodule is a module with compatible left and right operations.
protocol Bimodule : LeftModule, RightModule {}

extension Int : LeftModule {
typealias R = Int
typealias A = Int
}
public func *<>(l : Int, r : Int) -> Int { return l * r }
extension Int8 : LeftModule {
typealias R = Int
typealias A = Int8
struct Bimodule<R: Semiring, A: Additive> {
let left: LeftModule<R, A>
let right: RightModule<A, R>
}
public func *<>(l : Int, r : Int8) -> Int8 { return Int8(l) * r }
extension Int16 : LeftModule {
typealias R = Int
typealias A = Int16
enum Bimodules {
static let int = Bimodule(left: LeftModules.int, right: RightModules.int)
static let int8 = Bimodule(left: LeftModules.int8, right: RightModules.int8)
static let int16 = Bimodule(left: LeftModules.int16, right: RightModules.int16)
static let int32 = Bimodule(left: LeftModules.int32, right: RightModules.int32)
static let int64 = Bimodule(left: LeftModules.int64, right: RightModules.int64)
}
public func *<>(l : Int, r : Int16) -> Int16 { return Int16(l) * r }
extension Int32 : LeftModule {
typealias R = Int
typealias A = Int32
}
public func *<>(l : Int, r : Int32) -> Int32 { return Int32(l) * r }
extension Int64 : LeftModule {
typealias R = Int
typealias A = Int64
}
public func *<>(l : Int, r : Int64) -> Int64 { return Int64(l) * r }


extension Int : RightModule { }
public func <>*(l : Int, r : Int) -> Int { return l * r }

extension Int8 : RightModule { }
public func <>*(l : Int8, r : Int) -> Int8 { return l * Int8(r) }

extension Int16 : RightModule { }
public func <>*(l : Int16, r : Int) -> Int16 { return l * Int16(r) }

extension Int32 : RightModule { }
public func <>*(l : Int32, r : Int) -> Int32 { return l * Int32(r) }

extension Int64 : RightModule { }
public func <>*(l : Int64, r : Int) -> Int64 { return l * Int64(r) }


extension Int : Bimodule { }
extension Int8 : Bimodule { }
extension Int16 : Bimodule { }
extension Int32 : Bimodule { }
extension Int64 : Bimodule { }
4 changes: 2 additions & 2 deletions Algebra/Monoid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

/// Semigroups with a zero identity.
protocol Additive : Semigroup {
static var zero : M { get }
static var zero : Self { get }
}

/// Semigroups with a one identity.
protocol Multiplicative : Semigroup {
static var one : M { get }
static var one : Self { get }
}

extension Bool : Additive {
Expand Down
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "typelift/Operadics" "0.2.0"
github "typelift/SwiftCheck" "v0.6.2"
github "typelift/Operadics" "0.2.3"
github "typelift/SwiftCheck" "0.8.0"
2 changes: 1 addition & 1 deletion Carthage/Checkouts/Operadics
2 changes: 1 addition & 1 deletion Carthage/Checkouts/SwiftCheck
Submodule SwiftCheck updated 66 files
+3 −0 .gitignore
+0 −3 .gitmodules
+1 −0 .swift-version
+19 −15 .travis.yml
+0 −1 Cartfile.private
+0 −1 Cartfile.resolved
+0 −1 Carthage/Checkouts/Operadics
+0 −2 Package.swift
+36 −62 README.md
+79 −103 Sources/Arbitrary.swift
+896 −0 Sources/Cartesian.swift
+73 −72 Sources/Check.swift
+58 −55 Sources/CoArbitrary.swift
+89 −0 Sources/Compose.swift
+214 −340 Sources/Gen.swift
+26 −33 Sources/Lattice.swift
+149 −192 Sources/Modifiers.swift
+0 −246 Sources/Operators.swift
+382 −268 Sources/Property.swift
+94 −55 Sources/Random.swift
+64 −81 Sources/Rose.swift
+46 −45 Sources/State.swift
+0 −1 Sources/SwiftCheck.h
+600 −382 Sources/Test.swift
+20 −44 Sources/Testable.swift
+65 −25 Sources/Witness.swift
+61 −95 Sources/WitnessedArbitrary.swift
+2 −2 SwiftCheck.podspec
+219 −151 SwiftCheck.xcodeproj/project.pbxproj
+1 −1 SwiftCheck.xcodeproj/xcshareddata/xcschemes/SwiftCheck-iOS.xcscheme
+1 −1 SwiftCheck.xcodeproj/xcshareddata/xcschemes/SwiftCheck-tvOS.xcscheme
+1 −1 SwiftCheck.xcodeproj/xcshareddata/xcschemes/SwiftCheck.xcscheme
+62 −0 Templates/Cartesian.swift.gyb
+54 −0 Templates/CartesianSpec.swift.gyb
+0 −60 Tests/BooleanIdentitySpec.swift
+0 −73 Tests/ComplexSpec.swift
+0 −27 Tests/DiscardSpec.swift
+0 −327 Tests/GenSpec.swift
+30 −0 Tests/LinuxMain.swift
+0 −65 Tests/ModifierSpec.swift
+0 −153 Tests/PropertySpec.swift
+0 −42 Tests/RawRepresentableSpec.swift
+0 −50 Tests/ShrinkSpec.swift
+0 −207 Tests/SimpleSpec.swift
+88 −0 Tests/SwiftCheckTests/BooleanIdentitySpec.swift
+264 −0 Tests/SwiftCheckTests/CartesianSpec.swift
+93 −0 Tests/SwiftCheckTests/ComplexSpec.swift
+40 −0 Tests/SwiftCheckTests/DiscardSpec.swift
+22 −9 Tests/SwiftCheckTests/FailureSpec.swift
+1,212 −0 Tests/SwiftCheckTests/FileCheck.swift
+88 −0 Tests/SwiftCheckTests/FormatterSpec.swift
+462 −0 Tests/SwiftCheckTests/GenSpec.swift
+52 −45 Tests/SwiftCheckTests/LambdaSpec.swift
+93 −0 Tests/SwiftCheckTests/ModifierSpec.swift
+39 −33 Tests/SwiftCheckTests/PathSpec.swift
+227 −0 Tests/SwiftCheckTests/PropertySpec.swift
+8 −2 Tests/SwiftCheckTests/ReplaySpec.swift
+46 −40 Tests/SwiftCheckTests/RoseSpec.swift
+73 −0 Tests/SwiftCheckTests/ShrinkSpec.swift
+230 −0 Tests/SwiftCheckTests/SimpleSpec.swift
+79 −0 Tests/SwiftCheckTests/TestSpec.swift
+0 −67 Tests/TestSpec.swift
+34 −99 Tutorial.playground/Contents.swift
+4 −0 Utilities/compile.sh
+3 −0 Utilities/gyb
+1,146 −0 Utilities/gyb.py
Loading

0 comments on commit 94206cc

Please sign in to comment.