Skip to content

Commit 776410b

Browse files
authored
Merge pull request apple#115 from just-gull/heap-tests-release
[Heap] Enable heap tests in optimized builds (apple#101)
2 parents aba0791 + 8b3af12 commit 776410b

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

Tests/PriorityQueueTests/HeapTests.swift

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
#if DEBUG
1312
import XCTest
14-
@testable import PriorityQueueModule
13+
import PriorityQueueModule
1514

1615
final class HeapTests: XCTestCase {
1716
func test_isEmpty() {
@@ -352,19 +351,6 @@ final class HeapTests: XCTestCase {
352351

353352
// MARK: -
354353

355-
func test_levelCalculation() {
356-
// Check alternating min and max levels in the heap
357-
var isMin = true
358-
for exp in 0...12 {
359-
// Check [2^exp, 2^(exp + 1))
360-
for offset in Int(pow(2, Double(exp)) - 1)..<Int(pow(2, Double(exp + 1)) - 1) {
361-
let node = _Node(offset: offset)
362-
XCTAssertEqual(node.isMinLevel, isMin)
363-
}
364-
isMin.toggle()
365-
}
366-
}
367-
368354
func test_initializer_fromCollection() {
369355
var heap = Heap((1...20).shuffled())
370356
XCTAssertEqual(heap.max(), 20)
@@ -407,4 +393,3 @@ final class HeapTests: XCTestCase {
407393
XCTAssertEqual(heap.popMax(), 1)
408394
}
409395
}
410-
#endif
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift Collections open source project
4+
//
5+
// Copyright (c) 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
//
10+
//===----------------------------------------------------------------------===//
11+
12+
#if DEBUG // These unit tests need access to PriorityQueueModule internals
13+
import XCTest
14+
@testable import PriorityQueueModule
15+
16+
class NodeTests: XCTestCase {
17+
func test_levelCalculation() {
18+
// Check alternating min and max levels in the heap
19+
var isMin = true
20+
for exp in 0...12 {
21+
// Check [2^exp, 2^(exp + 1))
22+
for offset in Int(pow(2, Double(exp)) - 1)..<Int(pow(2, Double(exp + 1)) - 1) {
23+
let node = _Node(offset: offset)
24+
XCTAssertEqual(node.isMinLevel, isMin)
25+
}
26+
isMin.toggle()
27+
}
28+
}
29+
}
30+
#endif // DEBUG

0 commit comments

Comments
 (0)