mirror of
https://github.com/apple/swift-collections
synced 2026-11-26 04:47:48 +00:00
[Heap] Enable heap tests in optimized builds (#101)
@testable import is replaced with @_spi(Testing) import. A test for _Node is moved to another file because this test needs access to internals of PriorityQueueModule and this test will not work in optimized builds.
This commit is contained in:
1 parent
52d426a116
commit
cfb6dd1810
2 files changed
+31
-16
No files matched your search
@@ -9,9 +9,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if DEBUG
|
||||
import XCTest
|
||||
@testable import PriorityQueueModule
|
||||
@_spi(Testing) import PriorityQueueModule
|
||||
|
||||
final class HeapTests: XCTestCase {
|
||||
func test_isEmpty() {
|
||||
@@ -349,19 +348,6 @@ final class HeapTests: XCTestCase {
|
||||
|
||||
// MARK: -
|
||||
|
||||
func test_levelCalculation() {
|
||||
// Check alternating min and max levels in the heap
|
||||
var isMin = true
|
||||
for exp in 0...12 {
|
||||
// Check [2^exp, 2^(exp + 1))
|
||||
for offset in Int(pow(2, Double(exp)) - 1)..<Int(pow(2, Double(exp + 1)) - 1) {
|
||||
let node = _Node(offset: offset)
|
||||
XCTAssertEqual(node.isMinLevel, isMin)
|
||||
}
|
||||
isMin.toggle()
|
||||
}
|
||||
}
|
||||
|
||||
func test_initializer_fromCollection() {
|
||||
var heap = Heap((1...20).shuffled())
|
||||
XCTAssertEqual(heap.max(), 20)
|
||||
@@ -420,4 +406,3 @@ final class HeapTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift Collections open source project
|
||||
//
|
||||
// Copyright (c) 2021 Apple Inc. and the Swift project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if DEBUG // These unit tests need access to PriorityQueueModule internals
|
||||
import XCTest
|
||||
@_spi(Testing) @testable import PriorityQueueModule
|
||||
|
||||
class NodeTests: XCTestCase {
|
||||
func test_levelCalculation() {
|
||||
// Check alternating min and max levels in the heap
|
||||
var isMin = true
|
||||
for exp in 0...12 {
|
||||
// Check [2^exp, 2^(exp + 1))
|
||||
for offset in Int(pow(2, Double(exp)) - 1)..<Int(pow(2, Double(exp + 1)) - 1) {
|
||||
let node = _Node(offset: offset)
|
||||
XCTAssertEqual(node.isMinLevel, isMin)
|
||||
}
|
||||
isMin.toggle()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // DEBUG
|
||||
Reference in new issue
Block a user