Skip to content

Commit 5acda56

Browse files
committed
test internal function directly
1 parent 7a302e8 commit 5acda56

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Tests/SwiftAlgorithmsTests/RandomSampleTests.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
import XCTest
13-
import Algorithms
13+
@testable import Algorithms
1414

1515
func validateRandomSamples<S: Sequence>(
1616
_ samples: [Int: Int],
@@ -96,8 +96,13 @@ final class RandomSampleTests: XCTestCase {
9696
XCTAssertEqual(sample1c, sample2c)
9797
}
9898

99-
func testRandomSampleZeroRandom() {
100-
var generator = SplitMix64(seed: 0x61c8864680b583eb) // this seed starts with 0
101-
_ = c.randomSample(count: k, using: &generator) // must not crash
99+
func testRandomSampleRandomEdgeCasesInternal() {
100+
struct ZeroGenerator: RandomNumberGenerator {
101+
mutating func next() -> UInt64 { 0 }
102+
}
103+
var zero = ZeroGenerator()
104+
XCTAssertGreaterThan(nextW(k: 1, using: &zero), 0)
105+
XCTAssertGreaterThan(nextW(k: k, using: &zero), 0)
106+
_ = nextOffset(w: 1, using: &zero) // must not crash
102107
}
103108
}

0 commit comments

Comments
 (0)