Skip to content

Commit

Permalink
Round out the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
CodaFi committed Feb 7, 2017
1 parent f2c1fae commit 43b0f34
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 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
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
31 changes: 28 additions & 3 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,6 +233,7 @@ 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
}
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
3 changes: 2 additions & 1 deletion Sources/Testable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public struct Prop : Testable {

/// When returned from a test case, that particular case is discarded.
public struct Discard : Testable {
/// Create a `Discard` suitable for
/// Create a `Discard` suitable for disregarding a test case as though a
/// precondition was false.
public init() { }

/// Returns a property that always rejects whatever result occurs.
Expand Down

0 comments on commit 43b0f34

Please sign in to comment.