Skip to content

Commit

Permalink
Refactor zip to ensure type consistency (#252)
Browse files Browse the repository at this point in the history
* Refactor zip to ensure type consistency

* Deprecate static 'map' in favor of 'zipWith'

* Use zipWith in implementation of deprecated map
  • Loading branch information
sebastiangrail authored and CodaFi committed Oct 20, 2017
1 parent f0ae4a8 commit d0ac3b9
Show file tree
Hide file tree
Showing 7 changed files with 562 additions and 137 deletions.
610 changes: 510 additions & 100 deletions Sources/SwiftCheck/Cartesian.swift

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Sources/SwiftCheck/Gen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ extension Gen where A : Hashable {

extension Gen {
/// Zips together two generators and returns a generator of tuples.
public static func zip<A1, A2>(_ ga1 : Gen<A1>, _ ga2 : Gen<A2>) -> Gen<(A1, A2)> {
public static func zip<A1, A2>(_ ga1 : Gen<A1>, _ ga2 : Gen<A2>) -> Gen<(A1, A2)> where A == (A1, A2) {
return Gen<(A1, A2)> { r, n in
let (r1, r2) = r.split
return (ga1.unGen(r1, n), ga2.unGen(r2, n))
Expand All @@ -174,8 +174,8 @@ extension Gen {

/// Returns a new generator that applies a given function to any outputs the
/// given generators produce.
public static func map<A1, A2, R>(_ ga1 : Gen<A1>, _ ga2 : Gen<A2>, transform: @escaping (A1, A2) -> R) -> Gen<R> {
return zip(ga1, ga2).map({ t in transform(t.0, t.1) })
public static func map<A1, A2>(_ ga1 : Gen<A1>, _ ga2 : Gen<A2>, transform: @escaping (A1, A2) -> A) -> Gen {
return Gen<(A1, A2)>.zip(ga1, ga2).map({ t in transform(t.0, t.1) })
}
}

Expand Down
27 changes: 20 additions & 7 deletions Templates/Cartesian.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ extension Gen /*: Cartesian*/ {
# Function definition template
types_list = ['A{0}'.format(n) for n in range(1, arity + 1)]
type_parameter_list = ', '.join(types_list)
previouse_type_parameter_list = ', '.join(['A{0}'.format(n) for n in range(1, arity)])
latest_type_parameter = 'A{0}'.format(arity)
parameter_list = ', '.join(['_ ga{0} : Gen<A{0}>'.format(n) for n in range(1, arity + 1)])

# Zip body template
Expand All @@ -31,18 +33,18 @@ expanded_previous_tuple = ', '.join(['t.0.{0}'.format(n - 1) for n in previous_p
expanded_previous_tuple2 = ', '.join(['t.{0}'.format(n) for n in range(0, arity)])


# Map body template
map_zip_argument_list = ', '.join(['ga{0}'.format(n) for n in range(1, arity + 1)])
# ZipWith body template
zip_with_argument_list = ', '.join(['ga{0}'.format(n) for n in range(1, arity + 1)])
}%
/// Zips together ${arity} generators into a generator of ${arity}-tuples.
///
% for (t, p) in zip(types_list, ['ga{0}'.format(n) for n in range(1, arity + 1)]):
/// - parameter ${p}: A generator of values of type `${t}`.
% end
public static func zip<${type_parameter_list}>(${parameter_list}) -> Gen<(${type_parameter_list})> {
return Gen
public static func zip<${type_parameter_list}>(${parameter_list}) -> Gen<(${type_parameter_list})> where A == (${type_parameter_list}) {
return Gen<((${previouse_type_parameter_list}), ${latest_type_parameter})>
.zip(
.zip(${previous_zip_arguments}),
Gen<(${previouse_type_parameter_list})>.zip(${previous_zip_arguments}),
ga${arity}
).map { t in
(${expanded_previous_tuple}, t.1)
Expand All @@ -55,8 +57,19 @@ map_zip_argument_list = ', '.join(['ga{0}'.format(n) for n in range(1, arity + 1
% for (t, p) in zip(types_list, ['ga{0}'.format(n) for n in range(1, arity + 1)]):
/// - parameter ${p}: A generator of values of type `${t}`.
% end
public static func map<${type_parameter_list}, R>(${parameter_list}, transform : @escaping (${type_parameter_list}) -> R) -> Gen<R> {
return zip(${map_zip_argument_list}).map({ t in transform(${expanded_previous_tuple2}) })
@available(*, deprecated, renamed: "zipWith")
public static func map<${type_parameter_list}>(${parameter_list}, transform : @escaping (${type_parameter_list}) -> A) -> Gen<A> {
return Gen<A>.zipWith(${zip_with_argument_list}, transform: transform)
}

/// Returns a new generator that applies a given function to any outputs the
/// given generators produce.
///
% for (t, p) in zip(types_list, ['ga{0}'.format(n) for n in range(1, arity + 1)]):
/// - parameter ${p}: A generator of values of type `${t}`.
% end
public static func zipWith<${type_parameter_list}>(${parameter_list}, transform : @escaping (${type_parameter_list}) -> A) -> Gen<A> {
return Gen<(${type_parameter_list})>.zip(${zip_with_argument_list}).map({ t in transform(${expanded_previous_tuple2}) })
}

% end
Expand Down
6 changes: 3 additions & 3 deletions Templates/CartesianSpec.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ tupled_parameters = ', '.join(['x{0}'.format(n) for n in range(1, arity + 1
% end
}

func testGeneratedMaps() {
func testGeneratedZipWiths() {
% for arity in range(3, MAX_ARITY + 1):
%{
gen_type_argument_list = ', '.join(['Int' for _ in range(1, arity + 1)])
map_argument_list = ', '.join(['Gen.pure({0})'.format(n) for n in range(1, arity + 1)])
zip_with_argument_list = ', '.join(['Gen.pure({0})'.format(n) for n in range(1, arity + 1)])
tupled_parameters = ', '.join(['x{0}'.format(n) for n in range(1, arity + 1)])
max_argument_list = ', '.join(['${0}'.format(n) for n in range(0, arity)])
}%

let g${arity} = Gen<(${gen_type_argument_list})>.map(${map_argument_list}) { max(${max_argument_list}) }
let g${arity} = Gen<Int>.zipWith(${zip_with_argument_list}) { max(${max_argument_list}) }

property("Gen.zip${arity} behaves") <- forAllNoShrink(g${arity}) { maxInt in
maxInt == ${arity}
Expand Down
42 changes: 21 additions & 21 deletions Tests/SwiftCheckTests/CartesianSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,123 +142,123 @@ final class CartesianSpec : XCTestCase {
}
}

func testGeneratedMaps() {
func testGeneratedZipWiths() {

let g3 = Gen<(Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3)) { max($0, $1, $2) }
let g3 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3)) { max($0, $1, $2) }

property("Gen.zip3 behaves") <- forAllNoShrink(g3) { maxInt in
maxInt == 3
}

let g4 = Gen<(Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4)) { max($0, $1, $2, $3) }
let g4 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4)) { max($0, $1, $2, $3) }

property("Gen.zip4 behaves") <- forAllNoShrink(g4) { maxInt in
maxInt == 4
}

let g5 = Gen<(Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5)) { max($0, $1, $2, $3, $4) }
let g5 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5)) { max($0, $1, $2, $3, $4) }

property("Gen.zip5 behaves") <- forAllNoShrink(g5) { maxInt in
maxInt == 5
}

let g6 = Gen<(Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6)) { max($0, $1, $2, $3, $4, $5) }
let g6 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6)) { max($0, $1, $2, $3, $4, $5) }

property("Gen.zip6 behaves") <- forAllNoShrink(g6) { maxInt in
maxInt == 6
}

let g7 = Gen<(Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7)) { max($0, $1, $2, $3, $4, $5, $6) }
let g7 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7)) { max($0, $1, $2, $3, $4, $5, $6) }

property("Gen.zip7 behaves") <- forAllNoShrink(g7) { maxInt in
maxInt == 7
}

let g8 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8)) { max($0, $1, $2, $3, $4, $5, $6, $7) }
let g8 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8)) { max($0, $1, $2, $3, $4, $5, $6, $7) }

property("Gen.zip8 behaves") <- forAllNoShrink(g8) { maxInt in
maxInt == 8
}

let g9 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8) }
let g9 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8) }

property("Gen.zip9 behaves") <- forAllNoShrink(g9) { maxInt in
maxInt == 9
}

let g10 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9) }
let g10 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9) }

property("Gen.zip10 behaves") <- forAllNoShrink(g10) { maxInt in
maxInt == 10
}

let g11 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10) }
let g11 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10) }

property("Gen.zip11 behaves") <- forAllNoShrink(g11) { maxInt in
maxInt == 11
}

let g12 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) }
let g12 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) }

property("Gen.zip12 behaves") <- forAllNoShrink(g12) { maxInt in
maxInt == 12
}

let g13 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) }
let g13 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) }

property("Gen.zip13 behaves") <- forAllNoShrink(g13) { maxInt in
maxInt == 13
}

let g14 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) }
let g14 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) }

property("Gen.zip14 behaves") <- forAllNoShrink(g14) { maxInt in
maxInt == 14
}

let g15 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) }
let g15 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) }

property("Gen.zip15 behaves") <- forAllNoShrink(g15) { maxInt in
maxInt == 15
}

let g16 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15), Gen.pure(16)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) }
let g16 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15), Gen.pure(16)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) }

property("Gen.zip16 behaves") <- forAllNoShrink(g16) { maxInt in
maxInt == 16
}

let g17 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15), Gen.pure(16), Gen.pure(17)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16) }
let g17 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15), Gen.pure(16), Gen.pure(17)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16) }

property("Gen.zip17 behaves") <- forAllNoShrink(g17) { maxInt in
maxInt == 17
}

let g18 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15), Gen.pure(16), Gen.pure(17), Gen.pure(18)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) }
let g18 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15), Gen.pure(16), Gen.pure(17), Gen.pure(18)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) }

property("Gen.zip18 behaves") <- forAllNoShrink(g18) { maxInt in
maxInt == 18
}

let g19 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15), Gen.pure(16), Gen.pure(17), Gen.pure(18), Gen.pure(19)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18) }
let g19 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15), Gen.pure(16), Gen.pure(17), Gen.pure(18), Gen.pure(19)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18) }

property("Gen.zip19 behaves") <- forAllNoShrink(g19) { maxInt in
maxInt == 19
}

let g20 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15), Gen.pure(16), Gen.pure(17), Gen.pure(18), Gen.pure(19), Gen.pure(20)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19) }
let g20 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15), Gen.pure(16), Gen.pure(17), Gen.pure(18), Gen.pure(19), Gen.pure(20)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19) }

property("Gen.zip20 behaves") <- forAllNoShrink(g20) { maxInt in
maxInt == 20
}

let g21 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15), Gen.pure(16), Gen.pure(17), Gen.pure(18), Gen.pure(19), Gen.pure(20), Gen.pure(21)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20) }
let g21 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15), Gen.pure(16), Gen.pure(17), Gen.pure(18), Gen.pure(19), Gen.pure(20), Gen.pure(21)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20) }

property("Gen.zip21 behaves") <- forAllNoShrink(g21) { maxInt in
maxInt == 21
}

let g22 = Gen<(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)>.map(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15), Gen.pure(16), Gen.pure(17), Gen.pure(18), Gen.pure(19), Gen.pure(20), Gen.pure(21), Gen.pure(22)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21) }
let g22 = Gen<Int>.zipWith(Gen.pure(1), Gen.pure(2), Gen.pure(3), Gen.pure(4), Gen.pure(5), Gen.pure(6), Gen.pure(7), Gen.pure(8), Gen.pure(9), Gen.pure(10), Gen.pure(11), Gen.pure(12), Gen.pure(13), Gen.pure(14), Gen.pure(15), Gen.pure(16), Gen.pure(17), Gen.pure(18), Gen.pure(19), Gen.pure(20), Gen.pure(21), Gen.pure(22)) { max($0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21) }

property("Gen.zip22 behaves") <- forAllNoShrink(g22) { maxInt in
maxInt == 22
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftCheckTests/GenSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class GenSpec : XCTestCase {
// CHECK-NEXT: *** Passed 100 tests
// CHECK-NEXT: .
property("Gen.zip8 behaves") <- forAll { (x : Int, y : Int, z : Int, w : Int, a : Int, b : Int, c : Int, d : Int) in
let g = Gen<(Int, Int, Int, Int, Int, Int)>.zip(Gen.pure(x), Gen.pure(y), Gen.pure(z), Gen.pure(w), Gen.pure(a), Gen.pure(b), Gen.pure(c), Gen.pure(d))
let g = Gen<(Int, Int, Int, Int, Int, Int, Int, Int)>.zip(Gen.pure(x), Gen.pure(y), Gen.pure(z), Gen.pure(w), Gen.pure(a), Gen.pure(b), Gen.pure(c), Gen.pure(d))
return forAllNoShrink(g) { (t) in
return (t.0, t.1, t.2, t.3, t.4, t.5) == (x, y, z, w, a, b)
&& (t.6, t.7) == (c, d)
Expand Down
6 changes: 4 additions & 2 deletions Tests/SwiftCheckTests/SimpleSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ extension ArbitraryLargeFoo : Arbitrary {
, UInt8.arbitrary, UInt16.arbitrary, UInt32.arbitrary, UInt64.arbitrary
, Int.arbitrary, UInt.arbitrary)
.flatMap { t in
return Gen<(Bool, (Bool, Bool), (Bool, Bool, Bool), (Bool, Bool, Bool, Bool))>
.map(
return Gen<(Int8, Int16, Int32, Int64
, UInt8, UInt16, UInt32, UInt64
, Int , UInt, Bool, (Bool, Bool), (Bool, Bool, Bool), (Bool, Bool, Bool, Bool))>
.zipWith(
Bool.arbitrary,
Gen<(Bool, Bool)>.zip(Bool.arbitrary, Bool.arbitrary),
Gen<(Bool, Bool, Bool)>.zip(Bool.arbitrary, Bool.arbitrary, Bool.arbitrary),
Expand Down

0 comments on commit d0ac3b9

Please sign in to comment.