Skip to content

Commit

Permalink
Merge pull request #210 from CodaFi/cosmetics
Browse files Browse the repository at this point in the history
Cleanup some messes I left in the docs
  • Loading branch information
CodaFi authored Feb 8, 2017
2 parents 7175b6b + 43b0f34 commit e07a71a
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 49 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ matrix:
- echo $SIMULATOR_ID
- echo $iOS_DEVICE_NAME
- echo $iOS_RUNTIME_VERSION
# !!!: Start simulator w/ desired device—helps avoid issues w/ Xcode timing out when waiting for simulator to become ready
- open -b com.apple.iphonesimulator --args -CurrentDeviceUDID $SIMULATOR_ID
- xcodebuild build-for-testing -scheme SwiftCheck-iOS -destination "platform=iOS Simulator,name=${iOS_DEVICE_NAME},OS=${iOS_RUNTIME_VERSION}" | xcpretty -c
- xcodebuild test -scheme SwiftCheck-iOS -destination "platform=iOS Simulator,name=${iOS_DEVICE_NAME},OS=${iOS_RUNTIME_VERSION}" | xcpretty -c
# -- End iOS --
- xcodebuild build-for-testing -scheme SwiftCheck-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 1080p' | xcpretty -c
- xcodebuild test -scheme SwiftCheck-tvOS -destination 'platform=tvOS Simulator,name=Apple TV 1080p' | xcpretty -c
- os: linux
language: generic
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ let vowels = Gen.fromElements(of: [ "A", "E", "I", "O", "U" ])

let randomHexValue = Gen<UInt>.choose((0, 15))

let uppers : Gen<Character>= Gen<Character>.fromElements(in: "A"..."Z")
let uppers : Gen<Character> = Gen<Character>.fromElements(in: "A"..."Z")
let lowers : Gen<Character> = Gen<Character>.fromElements(in: "a"..."z")
let numbers : Gen<Character> = Gen<Character>.fromElements(in: "0"..."9")

Expand Down
2 changes: 1 addition & 1 deletion Sources/Arbitrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
///
/// While testing, SwiftCheck will invoke `arbitrary` a given amount of times
/// (usually 100 if the default settings are used). During that time, the
/// receiver has an opportunity to call through to any data or sources of
/// callee has an opportunity to call through to any data or sources of
/// randomness it needs to return what it deems an "Arbitrary" value.
///
/// Shrinking is reduction in the complexity of a tested value to remove noise
Expand Down
2 changes: 1 addition & 1 deletion Sources/CoArbitrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/// given generator (more than likely using `Gen.variant()`) based on the value
/// it observes.
public protocol CoArbitrary {
/// Uses an instance of the receiver to return a function that perturbs a
/// Uses an instance of the this type to return a function that perturbs a
/// generator.
static func coarbitrary<C>(_ x : Self) -> ((Gen<C>) -> Gen<C>)
}
Expand Down
20 changes: 10 additions & 10 deletions Sources/Gen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// generator relies on its size to help control aspects like the length of
/// generated arrays and the magnitude of integral values.
public struct Gen<A> {
/// The function underlying the receiver.
/// The function underlying the generator.
///
/// +--- An RNG
/// | +--- The size of generated values.
Expand Down Expand Up @@ -64,7 +64,7 @@ public struct Gen<A> {

/// Constructs a Generator that uses a given array to produce smaller arrays
/// composed of its initial segments. The size of each initial segment
/// increases with the receiver's size parameter.
/// increases with the generator's size parameter.
///
/// The input array is required to be non-empty.
public static func fromInitialSegments<S>(of xs : [S]) -> Gen<[S]> {
Expand Down Expand Up @@ -182,7 +182,7 @@ extension Gen {
// MARK: Generator Modifiers

extension Gen {
/// Shakes up the receiver's internal Random Number Generator with a seed.
/// Shakes up the generator's internal Random Number Generator with a seed.
public func variant<S : Integer>(_ seed : S) -> Gen<A> {
return Gen(unGen: { rng, n in
return self.unGen(vary(seed, rng), n)
Expand Down Expand Up @@ -218,7 +218,7 @@ extension Gen {

var size = n
var r1 = r
var scrutinee : A? = valGen.unGen(r, size)
var scrutinee : A? = valGen.unGen(r1, size)
while scrutinee == nil {
let (rl, rr) = r1.split
size = size + 1
Expand Down Expand Up @@ -254,15 +254,15 @@ extension Gen {
}

/// Modifies a Generator such that it produces arrays with a length
/// determined by the receiver's size parameter.
/// determined by the generator's size parameter.
public var proliferate : Gen<[A]> {
return Gen<[A]>.sized { n in
return Gen.choose((0, n)).flatMap(self.proliferate(withSize:))
}
}

/// Modifies a Generator such that it produces non-empty arrays with a
/// length determined by the receiver's size parameter.
/// length determined by the generator's size parameter.
public var proliferateNonEmpty : Gen<[A]> {
return Gen<[A]>.sized { n in
return Gen.choose((1, max(1, n))).flatMap(self.proliferate(withSize:))
Expand Down Expand Up @@ -317,13 +317,13 @@ extension Gen {

extension Gen /*: Functor*/ {
/// Returns a new generator that applies a given function to any outputs the
/// receiver creates.
/// generator creates.
///
/// This function is most useful for converting between generators of inter-
/// related types. For example, you might have a Generator of `Character`
/// values that you then `.proliferate` into an `Array` of `Character`s. You
/// can then use `fmap` to convert that generator of `Array`s to a generator of
/// `String`s.
/// can then use `map` to convert that generator of `Array`s to a generator
/// of `String`s.
public func map<B>(_ f : @escaping (A) -> B) -> Gen<B> {
return Gen<B>(unGen: { r, n in
return f(self.unGen(r, n))
Expand All @@ -340,7 +340,7 @@ extension Gen /*: Applicative*/ {
}

/// Given a generator of functions, applies any generated function to any
/// outputs the receiver creates.
/// outputs the generator creates.
public func ap<B>(_ fn : Gen<(A) -> B>) -> Gen<B> {
return Gen<B>(unGen: { r, n in
let (r1, r2) = r.split
Expand Down
7 changes: 6 additions & 1 deletion Sources/Lattice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,16 @@ extension AnyIndex : LatticeType {
#if os(Linux)
import Glibc

/// Matches http://www.opensource.apple.com/source/gcc/gcc-934.3/float.h
// Matches http://www.opensource.apple.com/source/gcc/gcc-934.3/float.h

/// Maximum value of `Float`.
public var FLT_MAX: Float = 3.40282347e+38
/// Minimum value of `Float`.
public var FLT_MIN: Float = 1.17549435e-38

/// Maximum value of `Double`.
public var DBL_MAX: Double = 1.7976931348623157e+308
/// Minimum value of `Double`.
public var DBL_MIN: Double = 2.2250738585072014e-308
#else
import Darwin
Expand Down
35 changes: 30 additions & 5 deletions Sources/Modifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public struct Blind<A : Arbitrary> : Arbitrary, CustomStringConvertible {
/// Retrieves the underlying value.
public let getBlind : A

/// Creates a new `Blind` modifier from an underlying value.
public init(_ blind : A) {
self.getBlind = blind
}
Expand All @@ -78,8 +79,9 @@ public struct Blind<A : Arbitrary> : Arbitrary, CustomStringConvertible {
}

extension Blind : CoArbitrary {
// Take the lazy way out.
/// Uses the underlying value to perturb a generator.
public static func coarbitrary<C>(_ x : Blind) -> ((Gen<C>) -> Gen<C>) {
// Take the lazy way out.
return coarbitraryPrintable(x)
}
}
Expand All @@ -89,6 +91,7 @@ public struct Static<A : Arbitrary> : Arbitrary, CustomStringConvertible {
/// Retrieves the underlying value.
public let getStatic : A

/// Creates a new `Static` modifier from an underlying value.
public init(_ fixed : A) {
self.getStatic = fixed
}
Expand All @@ -105,8 +108,9 @@ public struct Static<A : Arbitrary> : Arbitrary, CustomStringConvertible {
}

extension Static : CoArbitrary {
// Take the lazy way out.
/// Uses the underlying value to perturb a generator.
public static func coarbitrary<C>(_ x : Static) -> ((Gen<C>) -> Gen<C>) {
// Take the lazy way out.
return coarbitraryPrintable(x)
}
}
Expand All @@ -121,6 +125,7 @@ public struct ArrayOf<A : Arbitrary> : Arbitrary, CustomStringConvertible {
return ContiguousArray(self.getArray)
}

/// Creates a new `ArrayOf` modifier from an underlying array of values.
public init(_ array : [A]) {
self.getArray = array
}
Expand All @@ -142,6 +147,7 @@ public struct ArrayOf<A : Arbitrary> : Arbitrary, CustomStringConvertible {
}

extension ArrayOf : CoArbitrary {
/// Uses the underlying array of values to perturb a generator.
public static func coarbitrary<C>(_ x : ArrayOf) -> ((Gen<C>) -> Gen<C>) {
let a = x.getArray
if a.isEmpty {
Expand All @@ -162,6 +168,11 @@ public struct OrderedArrayOf<A : Arbitrary & Comparable> : Arbitrary, CustomStri
return ContiguousArray(self.getOrderedArray)
}

/// Creates a new `OrderedArrayOf` modifier from an underlying array of
/// values.
///
/// The values in the array are not required to be sorted, they will
/// be sorted by the initializer.
public init(_ array : [A]) {
self.getOrderedArray = array.sorted()
}
Expand All @@ -188,6 +199,8 @@ public struct DictionaryOf<K : Hashable & Arbitrary, V : Arbitrary> : Arbitrary,
/// Retrieves the underlying dictionary of values.
public let getDictionary : Dictionary<K, V>

/// Creates a new `DictionaryOf` modifier from an underlying dictionary of
/// key-value pairs.
public init(_ dict : Dictionary<K, V>) {
self.getDictionary = dict
}
Expand All @@ -209,6 +222,7 @@ public struct DictionaryOf<K : Hashable & Arbitrary, V : Arbitrary> : Arbitrary,
}

extension DictionaryOf : CoArbitrary {
/// Uses the underlying array of values to perturb a generator.
public static func coarbitrary<C>(_ x : DictionaryOf) -> ((Gen<C>) -> Gen<C>) {
return Dictionary.coarbitrary(x.getDictionary)
}
Expand All @@ -219,13 +233,14 @@ public struct OptionalOf<A : Arbitrary> : Arbitrary, CustomStringConvertible {
/// Retrieves the underlying optional value.
public let getOptional : A?

/// Creates a new `OptionalOf` modifier from an underlying `Optional` value.
public init(_ opt : A?) {
self.getOptional = opt
}

/// A textual representation of `self`.
public var description : String {
return "\(self.getOptional)"
return "\(String(describing: self.getOptional))"
}

/// Returns a generator for `OptionalOf` values.
Expand All @@ -240,6 +255,7 @@ public struct OptionalOf<A : Arbitrary> : Arbitrary, CustomStringConvertible {
}

extension OptionalOf : CoArbitrary {
/// Uses the underlying presence or lack of a value to perturb a generator.
public static func coarbitrary<C>(_ x : OptionalOf) -> ((Gen<C>) -> Gen<C>) {
if let _ = x.getOptional {
return { $0.variant(0) }
Expand All @@ -253,6 +269,7 @@ public struct SetOf<A : Hashable & Arbitrary> : Arbitrary, CustomStringConvertib
/// Retrieves the underlying set of values.
public let getSet : Set<A>

/// Creates a new `SetOf` modifier from an underlying set of values.
public init(_ set : Set<A>) {
self.getSet = set
}
Expand Down Expand Up @@ -282,6 +299,7 @@ public struct SetOf<A : Hashable & Arbitrary> : Arbitrary, CustomStringConvertib
}

extension SetOf : CoArbitrary {
/// Uses the underlying set of values to perturb a generator.
public static func coarbitrary<C>(_ x : SetOf) -> ((Gen<C>) -> Gen<C>) {
if x.getSet.isEmpty {
return { $0.variant(0) }
Expand Down Expand Up @@ -384,6 +402,7 @@ public struct Large<A : RandomType & LatticeType & Integer> : Arbitrary {
/// Retrieves the underlying large value.
public let getLarge : A

/// Creates a new `Large` modifier from a given bounded integral value.
public init(_ lrg : A) {
self.getLarge = lrg
}
Expand All @@ -409,6 +428,7 @@ public struct Positive<A : Arbitrary & SignedNumber> : Arbitrary, CustomStringCo
/// Retrieves the underlying positive value.
public let getPositive : A

/// Creates a new `Positive` modifier from a given signed integral value.
public init(_ pos : A) {
self.getPositive = pos
}
Expand All @@ -430,8 +450,9 @@ public struct Positive<A : Arbitrary & SignedNumber> : Arbitrary, CustomStringCo
}

extension Positive : CoArbitrary {
// Take the lazy way out.
/// Uses the underlying positive integral value to perturb a generator.
public static func coarbitrary<C>(_ x : Positive) -> ((Gen<C>) -> Gen<C>) {
// Take the lazy way out.
return coarbitraryPrintable(x)
}
}
Expand All @@ -441,6 +462,7 @@ public struct NonZero<A : Arbitrary & Integer> : Arbitrary, CustomStringConverti
/// Retrieves the underlying non-zero value.
public let getNonZero : A

/// Creates a new `NonZero` modifier from a given integral value.
public init(_ non : A) {
self.getNonZero = non
}
Expand All @@ -462,6 +484,7 @@ public struct NonZero<A : Arbitrary & Integer> : Arbitrary, CustomStringConverti
}

extension NonZero : CoArbitrary {
/// Uses the underlying non-zero integral value to perturb a generator.
public static func coarbitrary<C>(_ x : NonZero) -> ((Gen<C>) -> Gen<C>) {
return x.getNonZero.coarbitraryIntegral()
}
Expand All @@ -472,6 +495,7 @@ public struct NonNegative<A : Arbitrary & Integer> : Arbitrary, CustomStringConv
/// Retrieves the underlying non-negative value.
public let getNonNegative : A

/// Creates a new `NonNegative` modifier from a given integral value.
public init(_ non : A) {
self.getNonNegative = non
}
Expand All @@ -493,6 +517,7 @@ public struct NonNegative<A : Arbitrary & Integer> : Arbitrary, CustomStringConv
}

extension NonNegative : CoArbitrary {
/// Uses the underlying non-negative integral value to perturb a generator.
public static func coarbitrary<C>(_ x : NonNegative) -> ((Gen<C>) -> Gen<C>) {
return x.getNonNegative.coarbitraryIntegral()
}
Expand Down Expand Up @@ -626,7 +651,7 @@ private final class PointerOfImpl<T : Arbitrary> : Arbitrary {
let size : Int

var description : String {
return "\(self.ptr)"
return "\(String(describing: self.ptr))"
}

init(_ ptr : UnsafeMutablePointer<T>, _ size : Int) {
Expand Down
14 changes: 7 additions & 7 deletions Sources/Random.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
/// type. It is analogous to `GeneratorType`, but rather than consume a
/// sequence it uses sources of randomness to generate values indefinitely.
public protocol RandomGeneneratorType {
/// The next operation returns an Int that is uniformly distributed in the
/// range returned by `genRange` (including both end points), and a new
/// generator.
/// Returns an `Int` that is uniformly distributed in the range returned by
/// `genRange` (including both end points), and a new random value generator.
var next : (Int, Self) { get }
/// The genRange operation yields the range of values returned by the
/// generator.
/// Yields the range of values returned by the generator.
///
/// This property must return integers in ascending order.
var genRange : (Int, Int) { get }
/// Splits the receiver into two distinct random value generators.
/// Splits the current random value generator into two distinct random value
/// generators.
var split : (Self, Self) { get }
}

Expand Down Expand Up @@ -69,7 +68,8 @@ public struct StdGen : RandomGeneneratorType {
return (z_, StdGen(s1__, s2__))
}

/// Splits the receiver and returns two distinct random number generators.
/// Splits the random number generator and returns two distinct random
/// number generators.
public var split : (StdGen, StdGen) {
let s1 = self.seed1
let s2 = self.seed2
Expand Down
Loading

0 comments on commit e07a71a

Please sign in to comment.