Skip to content

Commit cb840b5

Browse files
gribozavrMax Moiseev
authored andcommitted
StdlibUnittest: expose cartesianProduct() helper
1 parent 5a904b7 commit cb840b5

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -468,18 +468,6 @@ internal enum _SubSequenceSubscriptOnRangeMode {
468468
}
469469
}
470470

471-
internal func _product<C1 : Collection, C2 : Collection>(
472-
_ c1: C1, _ c2: C2
473-
) -> [(C1.Iterator.Element, C2.Iterator.Element)] {
474-
var result: [(C1.Iterator.Element, C2.Iterator.Element)] = []
475-
for e1 in c1 {
476-
for e2 in c2 {
477-
result.append((e1, e2))
478-
}
479-
}
480-
return result
481-
}
482-
483471
%{
484472
from gyb_stdlib_support import collectionForTraversal
485473
def testConstraints(protocol):
@@ -623,7 +611,7 @@ extension TestSuite {
623611
_blackHole(c[index])
624612
}
625613

626-
let tests = _product(
614+
let tests = cartesianProduct(
627615
subscriptRangeTests,
628616
_SubSequenceSubscriptOnIndexMode.all)
629617

@@ -722,7 +710,7 @@ extension TestSuite {
722710
_blackHole(c[index..<index])
723711
}
724712

725-
let tests = _product(
713+
let tests = cartesianProduct(
726714
subscriptRangeTests,
727715
_SubSequenceSubscriptOnRangeMode.all)
728716

stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ if resiliencyChecks.subscriptOnOutOfBoundsIndicesBehavior != .none {
172172
c[index] = wrapValue(OpaqueValue(9999))
173173
}
174174

175-
let tests = _product(
175+
let tests = cartesianProduct(
176176
subscriptRangeTests,
177177
_SubSequenceSubscriptOnIndexMode.all)
178178

@@ -325,7 +325,7 @@ if isFixedLengthCollection {
325325
}
326326

327327
if resiliencyChecks.subscriptRangeOnOutOfBoundsRangesBehavior != .none {
328-
let tests = _product(
328+
let tests = cartesianProduct(
329329
subscriptRangeTests,
330330
_SubSequenceSubscriptOnRangeMode.all)
331331

stdlib/private/StdlibUnittest/StdlibCoreExtras.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,16 @@ public func forAllPermutations<S : Sequence>(
232232
return ()
233233
}
234234
}
235+
236+
public func cartesianProduct<C1 : Collection, C2 : Collection>(
237+
_ c1: C1, _ c2: C2
238+
) -> [(C1.Iterator.Element, C2.Iterator.Element)] {
239+
var result: [(C1.Iterator.Element, C2.Iterator.Element)] = []
240+
for e1 in c1 {
241+
for e2 in c2 {
242+
result.append((e1, e2))
243+
}
244+
}
245+
return result
246+
}
247+

0 commit comments

Comments
 (0)