@@ -23,7 +23,7 @@ var LazyTestSuite = TestSuite("Lazy")
23
23
protocol TestProtocol1 {}
24
24
25
25
//===----------------------------------------------------------------------===//
26
- // Repeated
26
+ // repeatElement(), Repeated<Element>
27
27
//===----------------------------------------------------------------------===//
28
28
29
29
// Check that the generic parameter is called 'Element'.
@@ -33,20 +33,40 @@ extension Repeated where Element : TestProtocol1 {
33
33
}
34
34
}
35
35
36
- LazyTestSuite.test("Repeated") {
37
- checkRandomAccessCollection(
38
- [] as Array<OpaqueValue<Int>>,
39
- repeatElement(OpaqueValue(42), count: 0))
40
- { $0.value == $1.value }
36
+ LazyTestSuite.test("Repeated/AssociatedTypes") {
37
+ typealias Subject = Repeated<OpaqueValue<Int>>
38
+ expectRandomAccessCollectionAssociatedTypes(
39
+ collectionType: Subject.self,
40
+ iteratorType: IndexingIterator<Subject>.self,
41
+ subSequenceType: RandomAccessSlice<Subject>.self,
42
+ indexType: Int.self,
43
+ indexDistanceType: Int.self,
44
+ indicesType: CountableRange<Int>.self)
45
+ }
41
46
42
- checkRandomAccessCollection(
43
- [ OpaqueValue(42) ] as Array<OpaqueValue<Int>>,
44
- repeatElement(OpaqueValue(42), count: 1))
45
- { $0.value == $1.value }
47
+ LazyTestSuite.test("repeatedValue()/TypeInference") {
48
+ var r = repeatElement(OpaqueValue(42), count: 42)
49
+ expectType(Repeated<OpaqueValue<Int>>.self, &r)
50
+ }
51
+
52
+ LazyTestSuite.test("repeatedValue()/NegativeCount") {
53
+ expectCrashLater()
54
+ _ = repeatElement(OpaqueValue(42), count: -1)
55
+ }
56
+
57
+ LazyTestSuite.test("Repeated")
58
+ .forEach(in: [ 0, 1, 3 ]) {
59
+ count in
60
+
61
+ let c = repeatElement(OpaqueValue(42), count: count)
62
+ expectEqual(0, c.startIndex)
63
+ expectEqual(count, c.endIndex)
64
+ expectEqual(count, c.count)
65
+ expectEqual(42, c.repeatedValue.value)
46
66
67
+ let expected = (0..<count).map { _ in OpaqueValue(42) }
47
68
checkRandomAccessCollection(
48
- [ OpaqueValue(42), OpaqueValue(42), OpaqueValue(42) ] as Array<OpaqueValue<Int>>,
49
- repeatElement(OpaqueValue(42), count: 3))
69
+ expected, c)
50
70
{ $0.value == $1.value }
51
71
}
52
72
0 commit comments