Skip to content

Commit

Permalink
Merge pull request #91 from CodaFi/Begriffsschrift
Browse files Browse the repository at this point in the history
Tutorial Playground
  • Loading branch information
CodaFi committed Sep 8, 2015
2 parents 20cfac2 + 7cde84d commit 3541405
Show file tree
Hide file tree
Showing 13 changed files with 758 additions and 155 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ SwiftCheck

QuickCheck for Swift.

For those already familiar with the Haskell library, check out the source. For
everybody else, see the [Tutorial Playground](Tutorial.playground) for a
beginner-level introduction to the major concepts and use-cases of this library.

Introduction
============

Expand Down
6 changes: 2 additions & 4 deletions SwiftCheck/Gen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ public struct Gen<A> {
/// only that value.
///
/// The input collection is required to be non-empty.
public static func fromElementsOf<S : CollectionType where S.Generator.Element == A, S.Index : protocol<RandomType, BidirectionalIndexType>>(xs : S) -> Gen<A> {
assert(!xs.isEmpty, "Gen.fromElementsOf used with empty sequence")

return choose((xs.startIndex, xs.endIndex.predecessor())).fmap { i in
public static func fromElementsOf<S : Indexable where S.Index : protocol<Comparable, RandomType>>(xs : S) -> Gen<S._Element> {
return Gen.fromElementsIn(xs.startIndex...xs.endIndex.advancedBy(-1)).fmap { i in
return xs[i]
}
}
Expand Down
122 changes: 0 additions & 122 deletions SwiftCheck/SwiftCheck.playground/Contents.swift

This file was deleted.

3 changes: 0 additions & 3 deletions SwiftCheck/SwiftCheck.playground/Sources/SupportCode.swift

This file was deleted.

4 changes: 0 additions & 4 deletions SwiftCheck/SwiftCheck.playground/contents.xcplayground

This file was deleted.

4 changes: 2 additions & 2 deletions SwiftCheck/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ internal func reportMinimumCaseFound(st : CheckerState, res : TestResult) -> (In
let shrinkMsg = st.successfulShrinkCount > 1 ? (" and \(st.successfulShrinkCount) shrink") : ""

print("Proposition: " + st.name)
print(res.reason + pluralize(testMsg, i: st.successfulTestCount.successor()) + pluralize(shrinkMsg, i: st.successfulShrinkCount) + "):")
print(res.reason + pluralize(testMsg, i: st.successfulTestCount.successor()) + (st.successfulShrinkCount > 1 ? pluralize(shrinkMsg, i: st.successfulShrinkCount) : "") + "):")
dispatchAfterFinalFailureCallbacks(st, res: res)
return (st.successfulShrinkCount, st.failedShrinkStepCount - st.failedShrinkStepDistance, st.failedShrinkStepDistance)
}
Expand Down Expand Up @@ -631,7 +631,7 @@ internal func cons<T>(lhs : T, var _ rhs : [T]) -> [T] {
}

private func pluralize(s : String, i : Int) -> String {
if i == 0 {
if i == 1 {
return s
}
return s + "s"
Expand Down
2 changes: 1 addition & 1 deletion SwiftCheckTests/ComplexSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SwiftCheck
let upper : Gen<Character>= Gen<Character>.fromElementsIn("A"..."Z")
let lower : Gen<Character> = Gen<Character>.fromElementsIn("a"..."z")
let numeric : Gen<Character> = Gen<Character>.fromElementsIn("0"..."9")
let special = Gen<Character>.fromElementsOf(["!", "#", "$", "%", "&", "'", "*", "+", "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~", "."])
let special : Gen<Character> = Gen<Character>.fromElementsOf(["!", "#", "$", "%", "&", "'", "*", "+", "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~", "."])
let hexDigits = Gen<Character>.oneOf([
Gen<Character>.fromElementsIn("A"..."F"),
numeric,
Expand Down
37 changes: 19 additions & 18 deletions SwiftCheckTests/GenSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,25 @@ class GenSpec : XCTestCase {
return forAll(g) { $0 == 0 }
}

property("Gen.fromElementsOf only generates the elements of the given array") <- forAll { (xss : Array<Int>) in
if xss.isEmpty {
return Discard()
}
let l = Set(xss)
return forAll(Gen.fromElementsOf(xss)) { l.contains($0) }
}

property("Gen.fromElementsOf only generates the elements of the given array") <- forAll { (n1 : Int, n2 : Int) in
return forAll(Gen.fromElementsOf([n1, n2])) { $0 == n1 || $0 == n2 }
}

property("Gen.fromElementsOf only generates the elements of the given interval") <- forAll { (n1 : Int, n2 : Int) in
return (n1 < n2) ==> {
let interval = n1..<n2
return forAll(Gen<Int>.fromElementsOf(interval)) { interval.contains($0) }
}
}
// This crashes swiftc.
// property("Gen.fromElementsOf only generates the elements of the given array") <- forAll { (xss : Array<Int>) in
// if xss.isEmpty {
// return Discard()
// }
// let l = Set(xss)
// return forAll(Gen<Int>.fromElementsOf(xss)) { l.contains($0) }
// }
//
// property("Gen.fromElementsOf only generates the elements of the given array") <- forAll { (n1 : Int, n2 : Int) in
// return forAll(Gen.fromElementsOf([n1, n2])) { $0 == n1 || $0 == n2 }
// }
//
// property("Gen.fromElementsOf only generates the elements of the given interval") <- forAll { (n1 : Int, n2 : Int) in
// return (n1 < n2) ==> {
// let interval = n1...n2
// return forAll(Gen<Int>.fromElementsOf(interval)) { interval.contains($0) }
// }
// }

property("oneOf n") <- forAll { (xss : ArrayOf<Int>) in
if xss.getArray.isEmpty {
Expand Down

0 comments on commit 3541405

Please sign in to comment.