-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathCartesianSpec.swift.gyb
57 lines (48 loc) · 1.63 KB
/
CartesianSpec.swift.gyb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// CartesianSpec.swift
// SwiftCheck
//
// Created by Adam Kuipers on 9/21/16.
// Copyright © 2016 Typelift. All rights reserved.
//
// This is a GYB generated file; any changes will be overwritten
// during the build phase. Edit the template instead,
// found in Templates/CartesianSpec.swift.gyb
%{
MAX_ARITY = 22
}%
import SwiftCheck
import XCTest
#if SWIFT_PACKAGE
import FileCheck
#endif
import Foundation
final class CartesianSpec : XCTestCase {
func testGeneratedZips() {
% for arity in range(3, MAX_ARITY + 1):
%{
gen_type_argument_list = ', '.join(['Int' for _ in range(1, arity + 1)])
zip_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)])
}%
let g${arity} = Gen<(${gen_type_argument_list})>.zip(${zip_argument_list})
property("Gen.zip${arity} behaves") <- forAllNoShrink(g${arity}) { (tuple : (${gen_type_argument_list})) -> Bool in
tuple.0 == 1 && tuple.${arity - 1} == ${arity}
}
% end
}
func testGeneratedZipWiths() {
% for arity in range(3, MAX_ARITY + 1):
%{
gen_type_argument_list = ', '.join(['Int' for _ 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<Int>.zipWith(${zip_with_argument_list}) { max(${max_argument_list}) }
property("Gen.zip${arity} behaves") <- forAllNoShrink(g${arity}) { maxInt in
maxInt == ${arity}
}
% end
}
}