Skip to content

Commit 3dc793c

Browse files
committed
StdlibUnittest: add checkStrideable()
1 parent 5cc6799 commit 3dc793c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

stdlib/private/StdlibUnittest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ add_swift_library(swiftStdlibUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STD
1515
# filename.
1616
StdlibUnittest.swift.gyb
1717

18+
CheckStrideable.swift.gyb
1819
InspectValue.cpp
1920
InspectValue.swift
2021
InterceptTraps.cpp
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
%{
14+
from gyb_stdlib_unittest_support import TRACE, stackTrace, trace
15+
}%
16+
17+
public func checkStrideable<S : Strideable>(
18+
instances: [S],
19+
distances: [S.Stride],
20+
distanceOracle: (Int, Int) -> S.Stride,
21+
${TRACE}
22+
) {
23+
for i in instances.indices {
24+
let first = instances[i]
25+
for j in instances.indices {
26+
let second = instances[j]
27+
expectEqual(distanceOracle(i, j), first.distance(to: second))
28+
expectEqual(second, first.advanced(by: distanceOracle(i, j)))
29+
}
30+
}
31+
}
32+

0 commit comments

Comments
 (0)