Skip to content

Commit

Permalink
Lower Expect+Random.swift utilities (#110).
Browse files Browse the repository at this point in the history
  • Loading branch information
oscbyspro committed Nov 7, 2024
1 parent 4fdd918 commit 0c04d99
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 41 deletions.
32 changes: 0 additions & 32 deletions Sources/TestKit/Expect+Random.swift

This file was deleted.

1 change: 0 additions & 1 deletion Tests/DoubleIntKitTests/TripleInt+Division.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import TestKit
try Ɣrequire(Y(low: 0, mid: ~0, high: ~x), by: X(low: ~0, high: x), is: D(quotient: ~1 as B, remainder: X(low: ~1, high: 1))) // 1
try Ɣrequire(Y(low: ~0, mid: ~0, high: ~x), by: X(low: ~0, high: x), is: D(quotient: ~1 as B, remainder: X(low: ~2, high: 2))) // 1


func Ɣrequire(_ dividend: Y, by divisor: X, is expectation: D) throws {
try #require(Bool(divisor.msb))

Expand Down
44 changes: 36 additions & 8 deletions Tests/UltimathnumTests/Utilities/Utilities+Integers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,32 @@ import TestKit
// MARK: Tests
//=------------------------------------------------------------------------=

@Test("BinaryInteger.entropic(through:as:using:) - max index for each domain", arguments: typesAsCoreIntegerAsByte, fuzzers)
func entropicThroughMaxIndexForEachDomain(type: any SystemsInteger.Type, randomness: consuming FuzzerInt) {
whereIs(type)
@Test(
"Utilities/integers: entropic through max index for each domain",
Tag.List.tags(.generic, .random),
arguments: typesAsCoreIntegerAsByte, fuzzers
) func entropicThroughMaxIndexForEachDomainAsByte(
type: any SystemsInteger.Type, randomness: consuming FuzzerInt
) throws {

func whereIs<T>(_ type: T.Type) where T: SystemsInteger {
try whereIs(type)
func whereIs<T>(_ type: T.Type) throws where T: SystemsInteger {
Ɣexpect(entropic: &randomness, through: Shift.max, as: Domain.binary, is: Set(T.all))
Ɣexpect(entropic: &randomness, through: Shift.max, as: Domain.finite, is: Set(T.all))
Ɣexpect(entropic: &randomness, through: Shift.max, as: Domain.natural, is: Set(T.nonnegatives))
}
}

@Test("BinaryInteger.entropic(through:as:using:) - small indices for each domain", arguments: typesAsBinaryInteger, fuzzers)
func entropicThroughSmallIndicesForEachDomain(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) {
whereIs(type)
@Test(
"Utilities/integers: entropic through small indices for each domain",
Tag.List.tags(.generic, .random),
arguments: typesAsBinaryInteger, fuzzers
) func entropicThroughSmallIndicesForEachDomain(
type: any BinaryInteger.Type, randomness: consuming FuzzerInt
) throws {

func whereIs<T>(_ type: T.Type) where T: BinaryInteger {
try whereIs(type)
func whereIs<T>(_ type: T.Type) throws where T: BinaryInteger {
if T.isSigned {
Ɣexpect(entropic: &randomness, through: Shift.min, as: Domain.binary, is: [ -1, 0 ] as Set<T>)
Ɣexpect(entropic: &randomness, through: Shift.min, as: Domain.finite, is: [ -1, 0 ] as Set<T>)
Expand All @@ -56,4 +66,22 @@ import TestKit
}
}
}

private func Ɣexpect<T>(
entropic randomness: inout some Randomness,
through index: Shift<T.Magnitude>,
as domain: Domain,
is expectation: Set<T>,
at location: SourceLocation = #_sourceLocation
) where T: BinaryInteger {
var result = Set<T>()

while result.count < expectation.count {
for _ in 000 ..< expectation.count {
result.insert(T.entropic(through: index, as: domain, using: &randomness))
}
}

#expect(result == expectation, sourceLocation: location)
}
}

0 comments on commit 0c04d99

Please sign in to comment.