Fix test issues with single-module variant

This commit is contained in:
Karoy Lorentey committed 2023-03-21 18:43:46 -07:00
1 parent cbab9e3737
commit ea60d293b4
8 files changed
+27 -90

No files matched your search

@@ -27,7 +27,7 @@ public func expectFailure(
}
}
internal func _expectFailure(
public func _expectFailure(
_ diagnostic: String,
_ message: () -> String,
trapping: Bool,
@@ -9,40 +9,40 @@
//
//===----------------------------------------------------------------------===//
var globalSeed: Int {
#if COLLECTIONS_RANDOMIZED_TESTING
42.hashValue
#else
0
#endif
}
public struct RepeatableRandomNumberGenerator: RandomNumberGenerator {
public static var globalSeed: Int {
#if COLLECTIONS_RANDOMIZED_TESTING
42.hashValue
#else
0
#endif
}
// This uses the same linear congruential generator as rand48.
// FIXME: Replace with something better.
internal static let _m: UInt64 = 1 << 48
internal static let _a: UInt64 = 25214903917
internal static let _c: UInt64 = 11
internal var _state: UInt64
public init(seed: Int) {
self.init(seed: UInt64(truncatingIfNeeded: seed))
}
public init(seed: UInt64) {
// Perturb the seed a little so that the sequence doesn't start with a
// zero value in the common case of seed == 0. (Using a zero seed is a
// rather silly thing to do, but it's the easy thing.)
let global = UInt64(truncatingIfNeeded: globalSeed)
let global = UInt64(truncatingIfNeeded: Self.globalSeed)
_state = seed ^ global ^ 0x536f52616e646f6d // "SoRandom"
}
private mutating func _next() -> UInt64 {
_state = (Self._a &* _state &+ Self._c) & (Self._m - 1)
return _state &>> 16
}
public mutating func next() -> UInt64 {
return (_next() &<< 32) | _next()
}
@@ -1,40 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
public struct RepeatableRandomNumberGenerator: RandomNumberGenerator {
// This uses the same linear congruential generator as rand48.
// FIXME: Replace with something better.
internal static let _m: UInt64 = 1 << 48
internal static let _a: UInt64 = 25214903917
internal static let _c: UInt64 = 11
internal var _state: UInt64
public init(seed: Int) {
self.init(seed: UInt64(truncatingIfNeeded: seed))
}
public init(seed: UInt64) {
// Perturb the seed a little so that the sequence doesn't start with a
// zero value in the common case of seed == 0. (Using a zero seed is a
// rather silly thing to do, but it's the easy thing.)
_state = seed ^ 0x536f52616e646f6d // "SoRandom"
}
private mutating func _next() -> UInt64 {
_state = (Self._a &* _state &+ Self._c) & (Self._m - 1)
return _state &>> 16
}
public mutating func next() -> UInt64 {
return (_next() &<< 32) | _next()
}
}
@@ -118,22 +118,6 @@ extension LifetimeTracker {
}
}
func _expectFailure(
_ diagnostic: String,
_ message: () -> String,
trapping: Bool,
file: StaticString,
line: UInt
) {
expectFailure(
"""
\(diagnostic)
\(message())
""",
trapping: trapping,
file: file, line: line)
}
func expectEqualSets<Element: Hashable>(
_ set: TreeSet<Element>,
_ ref: [Element],
@@ -11,16 +11,20 @@
#if DEBUG // These unit tests need access to HeapModule internals
import XCTest
#if COLLECTIONS_SINGLE_MODULE
import Collections
#else
@testable import HeapModule
#endif
class NodeTests: XCTestCase {
class HeapNodeTests: 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)
let node = _HeapNode(offset: offset)
XCTAssertEqual(node.isMinLevel, isMin)
}
isMin.toggle()
@@ -9,17 +9,11 @@
//
//===----------------------------------------------------------------------===//
#if !COLLECTIONS_SINGLE_MODULE
import _CollectionsUtilities
#endif
extension RandomAccessCollection {
@inline(__always)
internal func _index(at offset: Int) -> Index {
index(startIndex, offsetBy: offset)
}
@inline(__always)
internal func _offset(of index: Index) -> Int {
distance(from: startIndex, to: index)
}
@inline(__always)
internal func _indexRange(at offsets: Range<Int>) -> Range<Index> {
_index(at: offsets.lowerBound) ..< _index(at: offsets.upperBound)
@@ -42,11 +36,6 @@ extension RandomAccessCollection {
return _offsetRange(of: range.relative(to: self))
}
@inline(__always)
internal subscript(_offset offset: Int) -> Element {
self[_index(at: offset)]
}
@inline(__always)
internal subscript(_offsets range: Range<Int>) -> SubSequence {
self[_indexRange(at: range)]
+1 -1
View File
@@ -30,7 +30,7 @@ class TestBigString: CollectionTestCase {
}
override func setUp() {
print("Global seed: \(globalSeed)")
print("Global seed: \(RepeatableRandomNumberGenerator.globalSeed)")
super.setUp()
}
+1 -1
View File
@@ -116,7 +116,7 @@ struct Chunk: RopeElement, Equatable, CustomStringConvertible {
class TestRope: XCTestCase {
override func setUp() {
print("Global seed: \(globalSeed)")
print("Global seed: \(RepeatableRandomNumberGenerator.globalSeed)")
}
func test_empty() {