Skip to content

Commit

Permalink
Merge pull request #10 from typelift/modifiers
Browse files Browse the repository at this point in the history
Modifiers
  • Loading branch information
CodaFi committed Feb 8, 2015
2 parents a59135d + d0786f5 commit 71cdc45
Show file tree
Hide file tree
Showing 14 changed files with 483 additions and 130 deletions.
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "typelift/Swiftz" "v0.1.0"
github "typelift/Swiftz" "v0.1.3"
8 changes: 8 additions & 0 deletions SwiftCheck-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
84572C381A6DC25000241F68 /* DiscardSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84572C321A6DC23100241F68 /* DiscardSpec.swift */; };
84572C391A6DC25200241F68 /* PrimeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84572C331A6DC23100241F68 /* PrimeSpec.swift */; };
84572C3A1A6DC25500241F68 /* SimpleSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84572C341A6DC23100241F68 /* SimpleSpec.swift */; };
8480AB401A7B2AA100C6162D /* ModifierSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8480AB3E1A7B2A9A00C6162D /* ModifierSpec.swift */; };
84DD436D1A7703A200D492C6 /* Swiftz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84DD43681A77038A00D492C6 /* Swiftz.framework */; };
84F2C4F41A7AD43900316E5F /* Modifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F2C4F31A7AD43900316E5F /* Modifiers.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -75,7 +77,9 @@
84572C321A6DC23100241F68 /* DiscardSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DiscardSpec.swift; path = SwiftCheckTests/DiscardSpec.swift; sourceTree = SOURCE_ROOT; };
84572C331A6DC23100241F68 /* PrimeSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PrimeSpec.swift; path = SwiftCheckTests/PrimeSpec.swift; sourceTree = SOURCE_ROOT; };
84572C341A6DC23100241F68 /* SimpleSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SimpleSpec.swift; path = SwiftCheckTests/SimpleSpec.swift; sourceTree = SOURCE_ROOT; };
8480AB3E1A7B2A9A00C6162D /* ModifierSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ModifierSpec.swift; path = SwiftCheckTests/ModifierSpec.swift; sourceTree = SOURCE_ROOT; };
84DD43621A77038A00D492C6 /* Swiftz-iOS.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "Swiftz-iOS.xcodeproj"; path = "Carthage/Checkouts/Swiftz/Swiftz-iOS.xcodeproj"; sourceTree = "<group>"; };
84F2C4F31A7AD43900316E5F /* Modifiers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Modifiers.swift; path = SwiftCheck/Modifiers.swift; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -125,6 +129,7 @@
84572C301A6DC21100241F68 /* Check.swift */,
841FAE4E19FB1BDA00AF4EA2 /* Combinators.swift */,
841FAE4F19FB1BDA00AF4EA2 /* Gen.swift */,
84F2C4F31A7AD43900316E5F /* Modifiers.swift */,
841FAE5119FB1BDA00AF4EA2 /* Property.swift */,
841FAE5219FB1BDB00AF4EA2 /* Random.swift */,
841FAE5319FB1BDB00AF4EA2 /* Rose.swift */,
Expand All @@ -149,6 +154,7 @@
children = (
84572C321A6DC23100241F68 /* DiscardSpec.swift */,
84572C331A6DC23100241F68 /* PrimeSpec.swift */,
8480AB3E1A7B2A9A00C6162D /* ModifierSpec.swift */,
84572C341A6DC23100241F68 /* SimpleSpec.swift */,
841FAE4119FB1BA800AF4EA2 /* Supporting Files */,
);
Expand Down Expand Up @@ -304,6 +310,7 @@
buildActionMask = 2147483647;
files = (
841FAE8619FB1CEA00AF4EA2 /* Arbitrary.swift in Sources */,
84F2C4F41A7AD43900316E5F /* Modifiers.swift in Sources */,
841FAE8719FB1CEA00AF4EA2 /* Combinators.swift in Sources */,
84572C311A6DC21100241F68 /* Check.swift in Sources */,
841FAE8819FB1CEA00AF4EA2 /* Gen.swift in Sources */,
Expand All @@ -321,6 +328,7 @@
buildActionMask = 2147483647;
files = (
84572C391A6DC25200241F68 /* PrimeSpec.swift in Sources */,
8480AB401A7B2AA100C6162D /* ModifierSpec.swift in Sources */,
84572C3A1A6DC25500241F68 /* SimpleSpec.swift in Sources */,
84572C381A6DC25000241F68 /* DiscardSpec.swift in Sources */,
);
Expand Down
8 changes: 8 additions & 0 deletions SwiftCheck.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
84572C211A6DBA1C00241F68 /* DiscardSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84572C201A6DBA1C00241F68 /* DiscardSpec.swift */; };
84572C251A6DBAA800241F68 /* Check.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84572C241A6DBAA800241F68 /* Check.swift */; };
84572C2B1A6DBABA00241F68 /* Testable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84572C2A1A6DBABA00241F68 /* Testable.swift */; };
8480AB2D1A7B0A9700C6162D /* ModifierSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8480AB2C1A7B0A9700C6162D /* ModifierSpec.swift */; };
84DD439E1A78817100D492C6 /* Swiftz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84DD43991A78816800D492C6 /* Swiftz.framework */; };
84F2C4F71A7AD43F00316E5F /* Modifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F2C4F61A7AD43F00316E5F /* Modifiers.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -75,7 +77,9 @@
84572C201A6DBA1C00241F68 /* DiscardSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiscardSpec.swift; sourceTree = "<group>"; };
84572C241A6DBAA800241F68 /* Check.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Check.swift; sourceTree = "<group>"; };
84572C2A1A6DBABA00241F68 /* Testable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Testable.swift; sourceTree = "<group>"; };
8480AB2C1A7B0A9700C6162D /* ModifierSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModifierSpec.swift; sourceTree = "<group>"; };
84DD43931A78816800D492C6 /* Swiftz.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Swiftz.xcodeproj; path = Carthage/Checkouts/Swiftz/Swiftz.xcodeproj; sourceTree = "<group>"; };
84F2C4F61A7AD43F00316E5F /* Modifiers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Modifiers.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -125,6 +129,7 @@
84572C241A6DBAA800241F68 /* Check.swift */,
844FCCCE198F24CF00EB242A /* Combinators.swift */,
844FCCAB198B32DC00EB242A /* Gen.swift */,
84F2C4F61A7AD43F00316E5F /* Modifiers.swift */,
844FCCAD198B367000EB242A /* Property.swift */,
844FCCC2198EC4F000EB242A /* Random.swift */,
844FCCC6198EFB4700EB242A /* Rose.swift */,
Expand All @@ -150,6 +155,7 @@
844FCCC8198EFF9B00EB242A /* SimpleSpec.swift */,
84572C1A1A6DB9D800241F68 /* PrimeSpec.swift */,
84572C201A6DBA1C00241F68 /* DiscardSpec.swift */,
8480AB2C1A7B0A9700C6162D /* ModifierSpec.swift */,
844FCC9D198B320500EB242A /* Supporting Files */,
);
path = SwiftCheckTests;
Expand Down Expand Up @@ -305,6 +311,7 @@
buildActionMask = 2147483647;
files = (
844FCCAE198B367000EB242A /* Property.swift in Sources */,
84F2C4F71A7AD43F00316E5F /* Modifiers.swift in Sources */,
844FCCB0198B36BE00EB242A /* Test.swift in Sources */,
84572C251A6DBAA800241F68 /* Check.swift in Sources */,
844FCCC3198EC4F000EB242A /* Random.swift in Sources */,
Expand All @@ -324,6 +331,7 @@
84572C1B1A6DB9D800241F68 /* PrimeSpec.swift in Sources */,
844FCCC9198EFF9B00EB242A /* SimpleSpec.swift in Sources */,
84572C211A6DBA1C00241F68 /* DiscardSpec.swift in Sources */,
8480AB2D1A7B0A9700C6162D /* ModifierSpec.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
67 changes: 29 additions & 38 deletions SwiftCheck/Arbitrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Swiftz
import Darwin

public protocol Arbitrary : Printable {
public protocol Arbitrary {
// typealias A : Arbitrary
class func arbitrary() -> Gen<Self>
class func shrink(Self) -> [Self]
Expand Down Expand Up @@ -176,29 +176,28 @@ extension UnicodeScalar : Arbitrary {
}
}

//extension String : Arbitrary {
// typealias A = String
// public static func arbitrary() -> Gen<String> {
// let chars = sized({ n in vectorOf(n)(gen: UnicodeScalar.arbitrary()) })
// return chars >>- { ls in Gen<String>.pure(String(ls.map({ x in Character(x) }))) }
// }
//
// public static func shrink(x : String) -> [String] {
// return shrinkNone(x)
// }
//}
extension String : Arbitrary {
typealias A = String
public static func arbitrary() -> Gen<String> {
let chars = sized({ n in Character.arbitrary().vectorOf(n) })
return chars >>- { ls in Gen<String>.pure(String(ls)) }
}

/// rdar://19437275
//extension Character : Arbitrary {
// typealias A = Character
// public static func arbitrary() -> Gen<Character> {
// return choose((32, 255)) >>- { Gen.pure(Character(UnicodeScalar($0))) }
// }
//
// public static func shrink(x : Character) -> [Character] {
// return shrinkNone(x)
// }
//}
public static func shrink(x : String) -> [String] {
return shrinkNone(x)
}
}

extension Character : Arbitrary {
typealias A = Character
public static func arbitrary() -> Gen<Character> {
return choose((32, 255)) >>- { Gen.pure(Character(UnicodeScalar($0))) }
}

public static func shrink(x : Character) -> [Character] {
return shrinkNone(x)
}
}

public func arbitraryArray<A : Arbitrary>() -> Gen<[A]> {
return sized({ n in
Expand All @@ -212,16 +211,6 @@ public func withBounds<A : Bounded>(f : A -> A -> Gen<A>) -> Gen<A> {
return f(A.minBound())(A.maxBound())
}

public func arbitraryBoundedIntegral<A : Bounded where A : SignedIntegerType>() -> Gen<A> {
return withBounds({ (let mn : A) -> A -> Gen<A> in
return { (let mx : A) -> Gen<A> in
return choose((A(numericCast(mn)), A(numericCast(mx)))) >>- { n in
return Gen<A>.pure(n)
}
}
})
}

private func bits<N : IntegerType>(n : N) -> Int {
if n / 2 == 0 {
return 0
Expand All @@ -231,7 +220,7 @@ private func bits<N : IntegerType>(n : N) -> Int {

private func inBounds<A : IntegerType>(fi : (Int -> A)) -> Gen<Int> -> Gen<A> {
return { g in
return suchThat(g)({ x in
return g.suchThat({ x in
return (fi(x) as Int) == x
}).fmap(fi)
}
Expand Down Expand Up @@ -311,15 +300,17 @@ protocol CoArbitrary {
}

public func coarbitraryIntegral<A : IntegerType, B>(x : A) -> Gen<B> -> Gen<B> {
return variant(x)
return { $0.variant(x) }
}

extension Bool : CoArbitrary {
public static func coarbitrary<C>(x: Bool) -> Gen<C> -> Gen<C> {
if x {
return variant(1)
return { g in
if x {
return g.variant(1)
}
return g.variant(0)
}
return variant(0)
}
}

Expand Down
2 changes: 1 addition & 1 deletion SwiftCheck/Check.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct QuickCheck {
return undefined()
}
set(test) {
quickCheck(test)
quickCheck(test, name: s)
}
}
}
Loading

0 comments on commit 71cdc45

Please sign in to comment.