|
37 | 37 | /// return xs.map(f.getArrow) == xs.map(f.getArrow)
|
38 | 38 | /// }
|
39 | 39 | /// }
|
40 |
| -/// |
41 |
| -/// Finally, modifiers nest to allow the generation of intricate structures that |
42 |
| -/// would not otherwise be possible due to the limitations above. For example, |
43 |
| -/// to generate an Array of Arrays of Dictionaries of Integers and Strings (a |
44 |
| -/// type that normally looks like `Array<Array<Dictionary<String, Int>>>`), |
45 |
| -/// would look like this: |
46 |
| -/// |
47 |
| -/// property("Generating monstrous data types is possible") <- forAll { (xs : ArrayOf<ArrayOf<DictionaryOf<String, Int>>>) in |
48 |
| -/// /// We're gonna need a bigger boat. |
49 |
| -/// } |
50 | 40 |
|
51 | 41 | /// For types that either do not have a `CustomStringConvertible` instance or
|
52 | 42 | /// that wish to have no description to print, Blind will create a default
|
@@ -115,48 +105,6 @@ extension Static : CoArbitrary {
|
115 | 105 | }
|
116 | 106 | }
|
117 | 107 |
|
118 |
| -/// Generates an array of arbitrary values of type A. |
119 |
| -public struct ArrayOf<A : Arbitrary> : Arbitrary, CustomStringConvertible { |
120 |
| - /// Retrieves the underlying array of values. |
121 |
| - public let getArray : [A] |
122 |
| - |
123 |
| - /// Retrieves the underlying array of values as a contiguous array. |
124 |
| - public var getContiguousArray : ContiguousArray<A> { |
125 |
| - return ContiguousArray(self.getArray) |
126 |
| - } |
127 |
| - |
128 |
| - /// Creates a new `ArrayOf` modifier from an underlying array of values. |
129 |
| - public init(_ array : [A]) { |
130 |
| - self.getArray = array |
131 |
| - } |
132 |
| - |
133 |
| - /// A textual representation of `self`. |
134 |
| - public var description : String { |
135 |
| - return "\(self.getArray)" |
136 |
| - } |
137 |
| - |
138 |
| - /// Returns a generator of `ArrayOf` values. |
139 |
| - public static var arbitrary : Gen<ArrayOf<A>> { |
140 |
| - return Array<A>.arbitrary.map(ArrayOf.init) |
141 |
| - } |
142 |
| - |
143 |
| - /// The default shrinking function for an `ArrayOf` values. |
144 |
| - public static func shrink(_ bl : ArrayOf<A>) -> [ArrayOf<A>] { |
145 |
| - return Array<A>.shrink(bl.getArray).map(ArrayOf.init) |
146 |
| - } |
147 |
| -} |
148 |
| - |
149 |
| -extension ArrayOf : CoArbitrary { |
150 |
| - /// Uses the underlying array of values to perturb a generator. |
151 |
| - public static func coarbitrary<C>(_ x : ArrayOf) -> ((Gen<C>) -> Gen<C>) { |
152 |
| - let a = x.getArray |
153 |
| - if a.isEmpty { |
154 |
| - return { $0.variant(0) } |
155 |
| - } |
156 |
| - return comp({ $0.variant(1) }, ArrayOf.coarbitrary(ArrayOf([A](a[1..<a.endIndex])))) |
157 |
| - } |
158 |
| -} |
159 |
| - |
160 | 108 | /// Generates a sorted array of arbitrary values of type A.
|
161 | 109 | public struct OrderedArrayOf<A : Arbitrary & Comparable> : Arbitrary, CustomStringConvertible {
|
162 | 110 | /// Retrieves the underlying sorted array of values.
|
@@ -193,121 +141,6 @@ public struct OrderedArrayOf<A : Arbitrary & Comparable> : Arbitrary, CustomStri
|
193 | 141 | }
|
194 | 142 | }
|
195 | 143 |
|
196 |
| - |
197 |
| -/// Generates an dictionary of arbitrary keys and values. |
198 |
| -public struct DictionaryOf<K : Hashable & Arbitrary, V : Arbitrary> : Arbitrary, CustomStringConvertible { |
199 |
| - /// Retrieves the underlying dictionary of values. |
200 |
| - public let getDictionary : Dictionary<K, V> |
201 |
| - |
202 |
| - /// Creates a new `DictionaryOf` modifier from an underlying dictionary of |
203 |
| - /// key-value pairs. |
204 |
| - public init(_ dict : Dictionary<K, V>) { |
205 |
| - self.getDictionary = dict |
206 |
| - } |
207 |
| - |
208 |
| - /// A textual representation of `self`. |
209 |
| - public var description : String { |
210 |
| - return "\(self.getDictionary)" |
211 |
| - } |
212 |
| - |
213 |
| - /// Returns a generator for a `DictionaryOf` values. |
214 |
| - public static var arbitrary : Gen<DictionaryOf<K, V>> { |
215 |
| - return Dictionary<K, V>.arbitrary.map(DictionaryOf.init) |
216 |
| - } |
217 |
| - |
218 |
| - /// The default shrinking function for a `DictionaryOf` values. |
219 |
| - public static func shrink(_ d : DictionaryOf<K, V>) -> [DictionaryOf<K, V>] { |
220 |
| - return Dictionary.shrink(d.getDictionary).map(DictionaryOf.init) |
221 |
| - } |
222 |
| -} |
223 |
| - |
224 |
| -extension DictionaryOf : CoArbitrary { |
225 |
| - /// Uses the underlying array of values to perturb a generator. |
226 |
| - public static func coarbitrary<C>(_ x : DictionaryOf) -> ((Gen<C>) -> Gen<C>) { |
227 |
| - return Dictionary.coarbitrary(x.getDictionary) |
228 |
| - } |
229 |
| -} |
230 |
| - |
231 |
| -/// Generates an Optional of arbitrary values of type A. |
232 |
| -public struct OptionalOf<A : Arbitrary> : Arbitrary, CustomStringConvertible { |
233 |
| - /// Retrieves the underlying optional value. |
234 |
| - public let getOptional : A? |
235 |
| - |
236 |
| - /// Creates a new `OptionalOf` modifier from an underlying `Optional` value. |
237 |
| - public init(_ opt : A?) { |
238 |
| - self.getOptional = opt |
239 |
| - } |
240 |
| - |
241 |
| - /// A textual representation of `self`. |
242 |
| - public var description : String { |
243 |
| - return "\(String(describing: self.getOptional))" |
244 |
| - } |
245 |
| - |
246 |
| - /// Returns a generator for `OptionalOf` values. |
247 |
| - public static var arbitrary : Gen<OptionalOf<A>> { |
248 |
| - return Optional<A>.arbitrary.map(OptionalOf.init) |
249 |
| - } |
250 |
| - |
251 |
| - /// The default shrinking function for `OptionalOf` values. |
252 |
| - public static func shrink(_ bl : OptionalOf<A>) -> [OptionalOf<A>] { |
253 |
| - return Optional<A>.shrink(bl.getOptional).map(OptionalOf.init) |
254 |
| - } |
255 |
| -} |
256 |
| - |
257 |
| -extension OptionalOf : CoArbitrary { |
258 |
| - /// Uses the underlying presence or lack of a value to perturb a generator. |
259 |
| - public static func coarbitrary<C>(_ x : OptionalOf) -> ((Gen<C>) -> Gen<C>) { |
260 |
| - if let _ = x.getOptional { |
261 |
| - return { $0.variant(0) } |
262 |
| - } |
263 |
| - return { $0.variant(1) } |
264 |
| - } |
265 |
| -} |
266 |
| - |
267 |
| -/// Generates a set of arbitrary values of type A. |
268 |
| -public struct SetOf<A : Hashable & Arbitrary> : Arbitrary, CustomStringConvertible { |
269 |
| - /// Retrieves the underlying set of values. |
270 |
| - public let getSet : Set<A> |
271 |
| - |
272 |
| - /// Creates a new `SetOf` modifier from an underlying set of values. |
273 |
| - public init(_ set : Set<A>) { |
274 |
| - self.getSet = set |
275 |
| - } |
276 |
| - |
277 |
| - /// A textual representation of `self`. |
278 |
| - public var description : String { |
279 |
| - return "\(self.getSet)" |
280 |
| - } |
281 |
| - |
282 |
| - /// Returns a generator for a `SetOf` values. |
283 |
| - public static var arbitrary : Gen<SetOf<A>> { |
284 |
| - return Gen.sized { n in |
285 |
| - return Gen<Int>.choose((0, n)).flatMap { k in |
286 |
| - if k == 0 { |
287 |
| - return Gen.pure(SetOf(Set([]))) |
288 |
| - } |
289 |
| - |
290 |
| - return sequence(Array((0...k)).map { _ in A.arbitrary }).map(comp(SetOf.init, Set.init)) |
291 |
| - } |
292 |
| - } |
293 |
| - } |
294 |
| - |
295 |
| - /// The default shrinking function for a `SetOf` values. |
296 |
| - public static func shrink(_ s : SetOf<A>) -> [SetOf<A>] { |
297 |
| - return ArrayOf.shrink(ArrayOf([A](s.getSet))).map({ SetOf(Set($0.getArray)) }) |
298 |
| - } |
299 |
| -} |
300 |
| - |
301 |
| -extension SetOf : CoArbitrary { |
302 |
| - /// Uses the underlying set of values to perturb a generator. |
303 |
| - public static func coarbitrary<C>(_ x : SetOf) -> ((Gen<C>) -> Gen<C>) { |
304 |
| - if x.getSet.isEmpty { |
305 |
| - return { $0.variant(0) } |
306 |
| - } |
307 |
| - return { $0.variant(1) } |
308 |
| - } |
309 |
| -} |
310 |
| - |
311 | 144 | /// Generates pointers of varying size of random values of type T.
|
312 | 145 | public struct PointerOf<T : Arbitrary> : Arbitrary, CustomStringConvertible {
|
313 | 146 | fileprivate let _impl : PointerOfImpl<T>
|
@@ -663,10 +496,8 @@ private final class PointerOfImpl<T : Arbitrary> : Arbitrary {
|
663 | 496 | }
|
664 | 497 |
|
665 | 498 | deinit {
|
666 |
| - if self.size > 0 && self.ptr != nil { |
667 |
| - self.ptr?.deallocate(capacity: self.size) |
668 |
| - self.ptr = nil |
669 |
| - } |
| 499 | + self.ptr?.deallocate() |
| 500 | + self.ptr = nil |
670 | 501 | }
|
671 | 502 |
|
672 | 503 | static var arbitrary : Gen<PointerOfImpl<T>> {
|
|
0 commit comments