Skip to content

Commit 32a942d

Browse files
committed
added test testIteratingViaIndexesValueSemantics()
1 parent 5ea51ee commit 32a942d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Sources/SwiftPriorityQueue/SwiftPriorityQueue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/// at the time of initialization.
3232
public struct PriorityQueue<T: Comparable> {
3333

34-
fileprivate var heap = [T]()
34+
fileprivate(set) var heap = [T]()
3535
private let ordered: (T, T) -> Bool
3636

3737
public init(ascending: Bool = false, startingValues: [T] = []) {

Tests/SwiftPriorityQueueTests/SwiftPriorityQueueTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,23 @@ class SwiftPriorityQueueTests: XCTestCase {
7070
}
7171

7272
XCTAssertEqual(fastIterationValues, indexIterationValue)
73+
}
74+
75+
func testIteratingViaIndexesValueSemantics() {
76+
var pq = PriorityQueue<Int>(order: <, startingValues: [1, 2, 3, 4, 5])
77+
var expectedHeap = pq.heap
78+
for i in pq.indices {
79+
let _ = pq[i]
80+
}
81+
XCTAssertEqual(pq.heap, expectedHeap)
7382

83+
// Let's also test with the other sort:
84+
pq = PriorityQueue<Int>(order: >, startingValues: [5, 4, 3, 2, 1])
85+
expectedHeap = pq.heap
86+
for i in pq.indices {
87+
let _ = pq[i]
88+
}
89+
XCTAssertEqual(pq.heap, expectedHeap)
7490
}
7591

7692
func testCustomOrder() {

0 commit comments

Comments
 (0)