From b0a7cc32a8f9de8dc692aa717ed407e9b7daed46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Bystr=C3=B6m=20Ericsson?= Date: Tue, 19 Nov 2024 06:46:10 +0100 Subject: [PATCH] Helping the compiler infer array literals types in parameterized tests (#131). --- Sources/TestKit/Utilities+Literals.swift | 29 ++ Tests/CoreKitTests/Bit+Bitwise.swift | 36 +-- Tests/CoreKitTests/Bit+Comparison.swift | 4 +- Tests/CoreKitTests/Bit+Text.swift | 2 +- Tests/CoreKitTests/Bit.swift | 12 +- Tests/CoreKitTests/Division+Rounding.swift | 70 ++--- .../Division+Validation.swift.swift | 3 +- Tests/CoreKitTests/Division.swift | 30 ++- Tests/CoreKitTests/Fallible+Comparison.swift | 2 +- Tests/CoreKitTests/Fallible+Sink.swift | 5 +- Tests/CoreKitTests/Fallible+Text.swift | 3 +- Tests/CoreKitTests/Fallible+Validation.swift | 4 +- Tests/CoreKitTests/Fallible+Veto.swift | 3 +- Tests/CoreKitTests/Fallible.swift | 8 +- .../CoreKitTests/LiteralInt+Comparison.swift | 5 +- Tests/CoreKitTests/LiteralInt+Count.swift | 5 +- Tests/CoreKitTests/LiteralInt+Elements.swift | 15 +- Tests/CoreKitTests/LiteralInt+Text.swift | 5 +- Tests/CoreKitTests/Order+Comparison.swift | 7 +- Tests/CoreKitTests/Order.swift | 15 +- Tests/CoreKitTests/Sign+Bitwise.swift | 12 +- Tests/CoreKitTests/Sign+Comparison.swift | 5 +- Tests/CoreKitTests/Sign+Text.swift | 15 +- Tests/CoreKitTests/Sign.swift | 49 ++-- .../CoreKitTests/Signedness+Comparison.swift | 5 +- Tests/CoreKitTests/Signedness.swift | 10 +- Tests/CoreKitTests/Signum+Addition.swift | 5 +- Tests/CoreKitTests/Signum+Comparison.swift | 12 +- Tests/CoreKitTests/Signum.swift | 8 +- .../Stdlib/Swift+BinaryInteger.swift | 33 +-- .../CoreKitTests/Stdlib/Swift+Optional.swift | 44 +-- .../DoubleInt+Addition.swift | 4 +- .../DoubleInt+Multiplication.swift | 4 +- Tests/FibonacciKitTests/Indexacci+Text.swift | 5 +- Tests/FibonacciKitTests/Tupleacci+Text.swift | 5 +- Tests/RandomIntKitTests/FuzzerInt.swift | 5 +- .../StdlibInt+Addition.swift | 76 +++--- .../StdlibIntKitTests/StdlibInt+Bitwise.swift | 30 ++- .../StdlibInt+Comparison.swift | 7 +- Tests/StdlibIntKitTests/StdlibInt+Count.swift | 13 +- .../StdlibInt+Division.swift | 3 +- .../StdlibIntKitTests/StdlibInt+Floats.swift | 2 +- .../StdlibInt+Integers.swift | 40 +-- .../StdlibInt+Literals.swift | 7 +- .../StdlibInt+Multiplication.swift | 2 +- Tests/StdlibIntKitTests/StdlibInt+Shift.swift | 33 ++- .../StdlibIntKitTests/StdlibInt+Stride.swift | 7 +- Tests/StdlibIntKitTests/StdlibInt+Words.swift | 83 +++--- Tests/StdlibIntKitTests/StdlibInt.swift | 6 +- .../BinaryInteger+Addition.swift | 18 +- .../BinaryInteger+Bitwise.swift | 90 ++++--- .../BinaryInteger+Clamping.swift | 60 +++-- .../BinaryInteger+Comparison.swift | 124 +++++---- .../BinaryInteger+Complement.swift | 8 +- .../BinaryInteger+Count.swift | 54 ++-- .../BinaryInteger+Division.swift.swift | 8 +- .../BinaryInteger+Elements.swift | 9 +- .../BinaryInteger+Exponentiation.swift | 57 ++-- .../BinaryInteger+Factorial.swift | 116 ++++---- .../BinaryInteger+Factorization.swift | 72 +++-- .../BinaryInteger+Fibonacci.swift | 11 +- .../BinaryInteger+Floats.swift | 81 ++++-- .../BinaryInteger+Geometry.swift | 38 +-- .../BinaryInteger+Integers.swift | 24 +- .../BinaryInteger+Literals.swift | 66 ++--- .../BinaryInteger+Loading.swift | 18 +- .../BinaryInteger+Logarithm.swift | 2 +- .../BinaryInteger+Metadata.swift | 33 ++- .../BinaryInteger+Multiplication.swift | 209 +++++++------- .../BinaryInteger+Random.swift | 9 +- .../BinaryInteger+Shift.swift | 144 ++++++---- .../BinaryInteger+Stdlib.swift | 6 +- .../BinaryInteger+Stride.swift | 16 +- .../UltimathnumTests/BinaryInteger+Text.swift | 54 ++-- .../BinaryInteger+Values.swift | 6 +- Tests/UltimathnumTests/Count+Comparison.swift | 38 ++- Tests/UltimathnumTests/Count+Integers.swift | 164 ++++++----- Tests/UltimathnumTests/Count+Text.swift | 38 ++- Tests/UltimathnumTests/Count.swift | 18 +- Tests/UltimathnumTests/Divider+Division.swift | 12 +- .../UltimathnumTests/Divider+Validation.swift | 12 +- Tests/UltimathnumTests/Divider.swift | 254 +++++++++--------- Tests/UltimathnumTests/Doublet.swift | 6 +- .../UltimathnumTests/Guarantees/Finite.swift | 26 +- .../UltimathnumTests/Guarantees/Natural.swift | 28 +- .../UltimathnumTests/Guarantees/Nonzero.swift | 32 ++- Tests/UltimathnumTests/Guarantees/Shift.swift | 101 ++++--- .../TextInt+Exponentiation.swift | 11 +- Tests/UltimathnumTests/TextInt+Letters.swift | 34 ++- Tests/UltimathnumTests/TextInt+Numerals.swift | 30 ++- Tests/UltimathnumTests/TextInt.swift | 25 +- Tests/UltimathnumTests/Triplet.swift | 6 +- .../Utilities/Utilities+Text.swift | 92 ++++--- 93 files changed, 1764 insertions(+), 1289 deletions(-) create mode 100644 Sources/TestKit/Utilities+Literals.swift diff --git a/Sources/TestKit/Utilities+Literals.swift b/Sources/TestKit/Utilities+Literals.swift new file mode 100644 index 00000000..097bc9b2 --- /dev/null +++ b/Sources/TestKit/Utilities+Literals.swift @@ -0,0 +1,29 @@ +//=----------------------------------------------------------------------------= +// This source file is part of the Ultimathnum open source project. +// +// Copyright (c) 2023 Oscar Byström Ericsson +// Licensed under Apache License, Version 2.0 +// +// See http://www.apache.org/licenses/LICENSE-2.0 for license information. +//=----------------------------------------------------------------------------= + +//*============================================================================* +// MARK: * Utilities x Literals +//*============================================================================* + +extension ExpressibleByArrayLiteral { + + //=------------------------------------------------------------------------= + // MARK: Initializers + //=------------------------------------------------------------------------= + + /// An initializer that helps infer the type of a literal. + @inlinable public static func infer(_ instance: consuming Self) -> Self { + instance + } + + /// An initializer that helps infer the type of a literal. + @inlinable public static func group(_ instance: consuming Self) -> CollectionOfOne { + CollectionOfOne(instance) + } +} diff --git a/Tests/CoreKitTests/Bit+Bitwise.swift b/Tests/CoreKitTests/Bit+Bitwise.swift index 794999cd..050bb29e 100644 --- a/Tests/CoreKitTests/Bit+Bitwise.swift +++ b/Tests/CoreKitTests/Bit+Bitwise.swift @@ -24,10 +24,10 @@ import TestKit "Bit/bitwise: ~(_:)", Tag.List.tags(.documentation, .exhaustive), ParallelizationTrait.serialized, - arguments: Array<(Bit, Bit)>([ + arguments: Array<(Bit, Bit)>.infer([ - (instance: Bit.zero, expectation: Bit.one ), - (instance: Bit.one, expectation: Bit.zero), + (Bit.zero, Bit.one ), + (Bit.one, Bit.zero), ])) func not(instance: Bit, expectation: Bit) { #expect(reduce(instance, { ~$0 }) == expectation) @@ -39,12 +39,12 @@ import TestKit "Bit/bitwise: &(_:_:)", Tag.List.tags(.documentation, .exhaustive), ParallelizationTrait.serialized, - arguments: Array<(Bit, Bit, Bit)>([ + arguments: Array<(Bit, Bit, Bit)>.infer([ - (lhs: Bit.zero, rhs: Bit.zero, expectation: Bit.zero), - (lhs: Bit.zero, rhs: Bit.one, expectation: Bit.zero), - (lhs: Bit.one, rhs: Bit.zero, expectation: Bit.zero), - (lhs: Bit.one, rhs: Bit.one, expectation: Bit.one ), + (Bit.zero, Bit.zero, Bit.zero), + (Bit.zero, Bit.one, Bit.zero), + (Bit.one, Bit.zero, Bit.zero), + (Bit.one, Bit.one, Bit.one ), ])) func and(lhs: Bit, rhs: Bit, expectation: Bit) { #expect(reduce(lhs, &, rhs) == expectation) @@ -55,12 +55,12 @@ import TestKit "Bit/bitwise: |(_:_:)", Tag.List.tags(.documentation, .exhaustive), ParallelizationTrait.serialized, - arguments: Array<(Bit, Bit, Bit)>([ + arguments: Array<(Bit, Bit, Bit)>.infer([ - (lhs: Bit.zero, rhs: Bit.zero, expectation: Bit.zero), - (lhs: Bit.zero, rhs: Bit.one, expectation: Bit.one ), - (lhs: Bit.one, rhs: Bit.zero, expectation: Bit.one ), - (lhs: Bit.one, rhs: Bit.one, expectation: Bit.one ), + (Bit.zero, Bit.zero, Bit.zero), + (Bit.zero, Bit.one, Bit.one ), + (Bit.one, Bit.zero, Bit.one ), + (Bit.one, Bit.one, Bit.one ), ])) func or(lhs: Bit, rhs: Bit, expectation: Bit) { #expect(reduce(lhs, |, rhs) == expectation) @@ -71,12 +71,12 @@ import TestKit "Bit/bitwise: ^(_:_:)", Tag.List.tags(.documentation, .exhaustive), ParallelizationTrait.serialized, - arguments: Array<(Bit, Bit, Bit)>([ + arguments: Array<(Bit, Bit, Bit)>.infer([ - (lhs: Bit.zero, rhs: Bit.zero, expectation: Bit.zero), - (lhs: Bit.zero, rhs: Bit.one, expectation: Bit.one ), - (lhs: Bit.one, rhs: Bit.zero, expectation: Bit.one ), - (lhs: Bit.one, rhs: Bit.one, expectation: Bit.zero), + (Bit.zero, Bit.zero, Bit.zero), + (Bit.zero, Bit.one, Bit.one ), + (Bit.one, Bit.zero, Bit.one ), + (Bit.one, Bit.one, Bit.zero), ])) func xor(lhs: Bit, rhs: Bit, expectation: Bit) { #expect(reduce(lhs, ^, rhs) == expectation) diff --git a/Tests/CoreKitTests/Bit+Comparison.swift b/Tests/CoreKitTests/Bit+Comparison.swift index 17a7a5b6..53295ec9 100644 --- a/Tests/CoreKitTests/Bit+Comparison.swift +++ b/Tests/CoreKitTests/Bit+Comparison.swift @@ -23,7 +23,7 @@ import TestKit @Test( "Bit/comparison: is 0", Tag.List.tags(.documentation, .exhaustive), - arguments: Array<(Bit, Bool)>([ + arguments: Array<(Bit, Bool)>.infer([ (Bit.zero, true ), (Bit.one, false), @@ -35,7 +35,7 @@ import TestKit @Test( "Bit/comparison: Bit vs Bit", Tag.List.tags(.documentation, .exhaustive), - arguments: Array<(Bit, Bit, Signum)>([ + arguments: Array<(Bit, Bit, Signum)>.infer([ (Bit.zero, Bit.zero, Signum.zero), (Bit.zero, Bit.one, Signum.negative), diff --git a/Tests/CoreKitTests/Bit+Text.swift b/Tests/CoreKitTests/Bit+Text.swift index 0d5f743c..1aa4b782 100644 --- a/Tests/CoreKitTests/Bit+Text.swift +++ b/Tests/CoreKitTests/Bit+Text.swift @@ -23,7 +23,7 @@ import TestKit @Test( "Bit/text: description", Tag.List.tags(.documentation, .exhaustive), - arguments: Array<(Bit, String)>([ + arguments: Array<(Bit, String)>.infer([ (Bit.zero, "0"), (Bit.one, "1"), diff --git a/Tests/CoreKitTests/Bit.swift b/Tests/CoreKitTests/Bit.swift index 3866b224..2d6f0385 100644 --- a/Tests/CoreKitTests/Bit.swift +++ b/Tests/CoreKitTests/Bit.swift @@ -24,7 +24,7 @@ import TestKit "Bit: init()", Tag.List.tags(.documentation, .exhaustive), ParallelizationTrait.serialized, - arguments: [Bit.zero] + arguments: CollectionOfOne(Bit.zero) ) func unspecified(expectation: Bit) { #expect(Bit() == expectation) #expect(Bit(raw: Bit.zero) == expectation) @@ -34,7 +34,7 @@ import TestKit "Bit: as Bit", Tag.List.tags(.documentation, .exhaustive), ParallelizationTrait.serialized, - arguments: Array<(Bit, Bit)>([ + arguments: Array<(Bit, Bit)>.infer([ (Bit.zero, Bit.zero), (Bit.one, Bit.one ), @@ -52,7 +52,7 @@ import TestKit "Bit: as Bool", Tag.List.tags(.documentation, .exhaustive), ParallelizationTrait.serialized, - arguments: Array<(Bit, Bool)>([ + arguments: Array<(Bit, Bool)>.infer([ (Bit.zero, false), (Bit.one, true ), @@ -70,7 +70,7 @@ import TestKit "Bit: as Order", Tag.List.tags(.documentation, .exhaustive), ParallelizationTrait.serialized, - arguments: Array<(Bit, Order)>([ + arguments: Array<(Bit, Order)>.infer([ (Bit.zero, Order.ascending ), (Bit.one, Order.descending), @@ -88,7 +88,7 @@ import TestKit "Bit: as Sign", Tag.List.tags(.documentation, .exhaustive), ParallelizationTrait.serialized, - arguments: Array<(Bit, Sign)>([ + arguments: Array<(Bit, Sign)>.infer([ (Bit.zero, Sign.plus ), (Bit.one, Sign.minus), @@ -106,7 +106,7 @@ import TestKit "Bit: as Signedness", Tag.List.tags(.documentation, .exhaustive), ParallelizationTrait.serialized, - arguments: Array<(Bit, Signedness)>([ + arguments: Array<(Bit, Signedness)>.infer([ (Bit.zero, Signedness.unsigned), (Bit.one, Signedness .signed), diff --git a/Tests/CoreKitTests/Division+Rounding.swift b/Tests/CoreKitTests/Division+Rounding.swift index 1c44316a..c87540cc 100644 --- a/Tests/CoreKitTests/Division+Rounding.swift +++ b/Tests/CoreKitTests/Division+Rounding.swift @@ -21,52 +21,54 @@ import TestKit //=------------------------------------------------------------------------= @Test( - "Division/ceil: [I8, U8] x [I8, U8]", - Tag.List.tags(.exhaustive), + "Division/rounding: ceil()", + Tag.List.tags(.exhaustive, .generic), arguments: typesAsCoreIntegerAsByte, typesAsCoreIntegerAsByte - ) func ceil(_ quotient: any SystemsInteger.Type, _ remainder: any SystemsInteger.Type) { - whereIs(quotient, remainder) + ) func ceil( + quotient: any SystemsInteger.Type, remainder: any SystemsInteger.Type + ) throws { - func whereIs(_ quotient: Q.Type, _ remainder: R.Type) where Q: SystemsInteger, R: SystemsInteger { - var success = IX.zero - for quotient in Q.all { - for remainder in R.nonpositives { - let division = Division(quotient: quotient, remainder: remainder) - success &+= IX(Bit(division.ceil() == quotient.veto(false))) - } - - for remainder in R.positives { - let division = Division(quotient: quotient, remainder: remainder) - success &+= IX(Bit(division.ceil() == quotient.incremented())) + try whereIs(quotient, remainder) + func whereIs(_ quotient: Q.Type, _ remainder: R.Type) throws where Q: SystemsInteger, R: SystemsInteger { + try withOnlyOneCallToRequire((quotient, remainder)) { require in + for quotient in Q.all { + for remainder in R.nonpositives { + let division = Division(quotient: quotient, remainder: remainder) + require(division.ceil() == quotient.veto(false)) + } + + for remainder in R.positives { + let division = Division(quotient: quotient, remainder: remainder) + require(division.ceil() == quotient.incremented()) + } } } - - #expect(success == IX(Q.all.count) &* IX(R.all.count)) } } @Test( - "Division/ceil: [I8, U8] x [I8, U8]", - Tag.List.tags(.exhaustive), + "Division/rounding: floor()", + Tag.List.tags(.exhaustive, .generic), arguments: typesAsCoreIntegerAsByte, typesAsCoreIntegerAsByte - ) func floor(quotient: any SystemsInteger.Type, remainder: any SystemsInteger.Type) { - whereIs(quotient, remainder) + ) func floor( + quotient: any SystemsInteger.Type, remainder: any SystemsInteger.Type + ) throws { - func whereIs(_ quotient: Q.Type, _ remainder: R.Type) where Q: SystemsInteger, R: SystemsInteger { - var success = IX.zero - for quotient in Q.all { - for remainder in R.negatives { - let division = Division(quotient: quotient, remainder: remainder) - success &+= IX(Bit(division.floor() == quotient.decremented())) - } - - for remainder in R.nonnegatives { - let division = Division(quotient: quotient, remainder: remainder) - success &+= IX(Bit(division.floor() == quotient.veto(false))) + try whereIs(quotient, remainder) + func whereIs(_ quotient: Q.Type, _ remainder: R.Type) throws where Q: SystemsInteger, R: SystemsInteger { + try withOnlyOneCallToRequire((quotient, remainder)) { require in + for quotient in Q.all { + for remainder in R.negatives { + let division = Division(quotient: quotient, remainder: remainder) + require(division.floor() == quotient.decremented()) + } + + for remainder in R.nonnegatives { + let division = Division(quotient: quotient, remainder: remainder) + require(division.floor() == quotient.veto(false)) + } } } - - #expect(success == IX(Q.all.count) &* IX(R.all.count)) } } } diff --git a/Tests/CoreKitTests/Division+Validation.swift.swift b/Tests/CoreKitTests/Division+Validation.swift.swift index b71f39ca..1dbbd739 100644 --- a/Tests/CoreKitTests/Division+Validation.swift.swift +++ b/Tests/CoreKitTests/Division+Validation.swift.swift @@ -22,7 +22,8 @@ import TestKit //=------------------------------------------------------------------------= @Test( - "Division/exactly: T.init(load:)", + "Division/validation: exactly()", + Tag.List.tags(.generic), ParallelizationTrait.serialized, arguments: I8(-2)...I8(2), I8(-2)...I8(2) ) func exactly(quotient: I8, remainder: I8) throws { diff --git a/Tests/CoreKitTests/Division.swift b/Tests/CoreKitTests/Division.swift index 495d5714..313123df 100644 --- a/Tests/CoreKitTests/Division.swift +++ b/Tests/CoreKitTests/Division.swift @@ -21,36 +21,44 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("Division/init(raw:) - T.init(load:)", .serialized, arguments: I8(-2)...I8(2), I8(-2)...I8(2)) - func pattern(quotient: I8, remainder: I8) { + @Test( + "Division: init(raw:)", + Tag.List.tags(.generic), + ParallelizationTrait.serialized, + arguments: I8(-2)...I8(2), I8(-2)...I8(2) + ) func pattern(quotient: I8, remainder: I8) throws { for quotient in typesAsCoreInteger { for remainder in typesAsCoreInteger { - whereIs(quotient, remainder) + try whereIs(quotient, remainder) } } - func whereIs(_ first: Q.Type, _ second: R.Type) where Q: BinaryInteger, R: BinaryInteger { + func whereIs(_ first: Q.Type, _ second: R.Type) throws where Q: BinaryInteger, R: BinaryInteger { let normal = Division(quotient: Q (load: quotient), remainder: R (load: remainder)) let magnitude = Division(quotient: Q.Magnitude(load: quotient), remainder: R.Magnitude(load: remainder)) let signitude = Division(quotient: Q.Signitude(load: quotient), remainder: R.Signitude(load: remainder)) - #expect(normal == Division(raw: magnitude)) - #expect(normal == Division(raw: signitude)) + try #require(normal == Division(raw: magnitude)) + try #require(normal == Division(raw: signitude)) } } - @Test("Division/components() - T.init(load:)", .serialized, arguments: I8(-2)...I8(2), I8(-2)...I8(2)) - func components(quotient: I8, remainder: I8) { + @Test( + "Division: components()", + Tag.List.tags(.generic), + ParallelizationTrait.serialized, + arguments: I8(-2)...I8(2), I8(-2)...I8(2) + ) func components(quotient: I8, remainder: I8) throws { for quotient in typesAsCoreInteger { for remainder in typesAsCoreInteger { - whereIs(quotient, remainder) + try whereIs(quotient, remainder) } } - func whereIs(_ first: Q.Type, _ second: R.Type) where Q: BinaryInteger, R: BinaryInteger { + func whereIs(_ first: Q.Type, _ second: R.Type) throws where Q: BinaryInteger, R: BinaryInteger { let quotient = Q(load: quotient ) let remainder = R(load: remainder) let division = Division(quotient: quotient, remainder: remainder) - #expect(division.components() == (quotient, remainder)) + try #require(division.components() == (quotient, remainder)) } } } diff --git a/Tests/CoreKitTests/Fallible+Comparison.swift b/Tests/CoreKitTests/Fallible+Comparison.swift index d512659a..0c2cadd4 100644 --- a/Tests/CoreKitTests/Fallible+Comparison.swift +++ b/Tests/CoreKitTests/Fallible+Comparison.swift @@ -25,7 +25,7 @@ import TestKit "Fallible/comparison: Fallible vs Fallible", Tag.List.tags(.exhaustive), ParallelizationTrait.serialized, - arguments: Array<(Fallible, Fallible, Bool)>([ + arguments: Array<(Fallible, Fallible, Bool)>.infer([ (Fallible(Bit.zero, error: false), Fallible(Bit.zero, error: false), true ), (Fallible(Bit.zero, error: false), Fallible(Bit.zero, error: true ), false), diff --git a/Tests/CoreKitTests/Fallible+Sink.swift b/Tests/CoreKitTests/Fallible+Sink.swift index b13041f7..698d3178 100644 --- a/Tests/CoreKitTests/Fallible+Sink.swift +++ b/Tests/CoreKitTests/Fallible+Sink.swift @@ -15,7 +15,7 @@ import TestKit // MARK: * Fallible x Sink //*============================================================================* -@Suite struct FallibleTestsOnSink { +@Suite(.serialized) struct FallibleTestsOnSink { //=------------------------------------------------------------------------= // MARK: Tests @@ -24,7 +24,6 @@ import TestKit @Test( "Fallible/sink: from inout Bool as Bit", Tag.List.tags(.exhaustive), - ParallelizationTrait.serialized, arguments: Bit.all ) func fromInoutBoolAsBit(value: Bit) { @@ -39,7 +38,6 @@ import TestKit @Test( "Fallible/sink: from inout Bool as Fallible", Tag.List.tags(.exhaustive), - ParallelizationTrait.serialized, arguments: Fallible.all ) func fromInoutBoolAsFallibleBit(instance: Fallible) { @@ -54,7 +52,6 @@ import TestKit @Test( "Fallible/sink: into Bool", Tag.List.tags(.exhaustive), - ParallelizationTrait.serialized, arguments: Fallible.all ) func sink(instance: Fallible) { diff --git a/Tests/CoreKitTests/Fallible+Text.swift b/Tests/CoreKitTests/Fallible+Text.swift index 052b33e3..9a518d1c 100644 --- a/Tests/CoreKitTests/Fallible+Text.swift +++ b/Tests/CoreKitTests/Fallible+Text.swift @@ -23,8 +23,7 @@ import TestKit @Test( "Fallible/text: description", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Bit, Bool, String)>([ + arguments: Array<(Bit, Bool, String)>.infer([ (Bit.zero, false, "0[-]"), (Bit.zero, true, "0[x]"), diff --git a/Tests/CoreKitTests/Fallible+Validation.swift b/Tests/CoreKitTests/Fallible+Validation.swift index 7b6953fe..1e3759ad 100644 --- a/Tests/CoreKitTests/Fallible+Validation.swift +++ b/Tests/CoreKitTests/Fallible+Validation.swift @@ -40,7 +40,7 @@ import TestKit "Fallible/validation: optional()", Tag.List.tags(.documentation, .exhaustive), ParallelizationTrait.serialized, - arguments: Array<(Fallible, Optional)>([ + arguments: Array<(Fallible, Optional)>.infer([ (Fallible(Bit.zero, error: false), Optional(Bit.zero)), (Fallible(Bit.zero, error: true ), Optional(nil)), @@ -55,7 +55,7 @@ import TestKit "Fallible/validation: prune(_:) and result(_:)", Tag.List.tags(.documentation, .exhaustive), ParallelizationTrait.serialized, - arguments: Array<(Fallible, Bad, Result)>([ + arguments: Array<(Fallible, Bad, Result)>.infer([ (Fallible(Bit.zero, error: false), Bad.error, Result.success(Bit.zero )), (Fallible(Bit.zero, error: true ), Bad.error, Result.failure(Bad.error)), diff --git a/Tests/CoreKitTests/Fallible+Veto.swift b/Tests/CoreKitTests/Fallible+Veto.swift index 7cd5986b..548e381d 100644 --- a/Tests/CoreKitTests/Fallible+Veto.swift +++ b/Tests/CoreKitTests/Fallible+Veto.swift @@ -15,7 +15,7 @@ import TestKit // MARK: * Fallible x Veto //*============================================================================* -@Suite("Fallible/veto") struct FallibleTestsOnVeto { +@Suite(.serialized) struct FallibleTestsOnVeto { //=------------------------------------------------------------------------= // MARK: Tests @@ -24,7 +24,6 @@ import TestKit @Test( "Fallible/veto: for each Bit", Tag.List.tags(.exhaustive), - ParallelizationTrait.serialized, arguments: Fallible.all ) func veto(argument: Fallible) { diff --git a/Tests/CoreKitTests/Fallible.swift b/Tests/CoreKitTests/Fallible.swift index fd17a018..9b109a73 100644 --- a/Tests/CoreKitTests/Fallible.swift +++ b/Tests/CoreKitTests/Fallible.swift @@ -21,9 +21,9 @@ import TestKit //=------------------------------------------------------------------------= @Test( - "Optional> has same memory layout as Fallible", + "Fallible: Optional has same memory layout as Self", Tag.List.tags(.documentation, .important) - ) func optionalFallibleHasSameMemoryLayoutAsFallible() { + ) func optionalInstanceHasSameMemoryLayoutAsInstance() { whereIs(Bool.self) whereIs(Void.self) @@ -50,8 +50,8 @@ import TestKit Tag.List.tags(.disambiguation, .exhaustive) ) func initAsVoid() { - #expect(Fallible ().value == ()) - #expect(Fallible ().error == false) + #expect(Fallible.init ().value == ()) + #expect(Fallible.init ().error == false) #expect(Fallible().value == ()) #expect(Fallible().error == false) } diff --git a/Tests/CoreKitTests/LiteralInt+Comparison.swift b/Tests/CoreKitTests/LiteralInt+Comparison.swift index afec076d..7e14e9cf 100644 --- a/Tests/CoreKitTests/LiteralInt+Comparison.swift +++ b/Tests/CoreKitTests/LiteralInt+Comparison.swift @@ -14,7 +14,7 @@ import TestKit // MARK: * Literal Int x Comparison //*============================================================================* -@Suite struct LiteralIntTestsOnComparison { +@Suite(.serialized) struct LiteralIntTestsOnComparison { //=------------------------------------------------------------------------= // MARK: Tests @@ -23,8 +23,7 @@ import TestKit @Test( "LiteralInt/comparison: signum()", Tag.List.tags(.documentation), - ParallelizationTrait.serialized, - arguments: Array<(LiteralInt, Signum)>([ + arguments: Array<(LiteralInt, Signum)>.infer([ (LiteralInt(-8), Signum.negative), // 000....1 (LiteralInt(-7), Signum.negative), // 100....1 diff --git a/Tests/CoreKitTests/LiteralInt+Count.swift b/Tests/CoreKitTests/LiteralInt+Count.swift index 3fb28bdf..84ec2666 100644 --- a/Tests/CoreKitTests/LiteralInt+Count.swift +++ b/Tests/CoreKitTests/LiteralInt+Count.swift @@ -14,7 +14,7 @@ import TestKit // MARK: * Literal Int x Count //*============================================================================* -@Suite struct LiteralIntTestsOnCount { +@Suite(.serialized) struct LiteralIntTestsOnCount { //=------------------------------------------------------------------------= // MARK: Tests @@ -23,8 +23,7 @@ import TestKit @Test( "LiteralInt/count: entropy()", Tag.List.tags(.documentation), - ParallelizationTrait.serialized, - arguments: Array<(LiteralInt, Count)>([ + arguments: Array<(LiteralInt, Count)>.infer([ (LiteralInt(-8), Count(4)), // 000....1 (LiteralInt(-7), Count(4)), // 100....1 diff --git a/Tests/CoreKitTests/LiteralInt+Elements.swift b/Tests/CoreKitTests/LiteralInt+Elements.swift index d5f0a650..77a8abdf 100644 --- a/Tests/CoreKitTests/LiteralInt+Elements.swift +++ b/Tests/CoreKitTests/LiteralInt+Elements.swift @@ -14,7 +14,7 @@ import TestKit // MARK: * Literal Int x Elements //*============================================================================* -@Suite struct LiteralIntTestsOnElements { +@Suite(.serialized) struct LiteralIntTestsOnElements { //=------------------------------------------------------------------------= // MARK: Tests @@ -23,8 +23,7 @@ import TestKit @Test( "LiteralInt/elements: appendix", Tag.List.tags(.documentation), - ParallelizationTrait.serialized, - arguments: Array<(LiteralInt, Bit)>([ + arguments: Array<(LiteralInt, Bit)>.infer([ (LiteralInt(-8), Bit.one ), // 000....1 (LiteralInt(-7), Bit.one ), // 100....1 @@ -53,20 +52,22 @@ import TestKit @Test( "LiteralInt/elements: byte sequence prefix", Tag.List.tags(.documentation), - ParallelizationTrait.serialized, - arguments: Array<(LiteralInt, [U8])>([ + arguments: Array<(LiteralInt, [U8])>.infer([ (LiteralInt(-0000000000000000000000000000000001), [U8](repeating: U8.max, count: 32)), (LiteralInt( 0000000000000000000000000000000000), [U8](repeating: U8.min, count: 32)), (LiteralInt(-0xf0f1f2f3f4f5f6f7f8f9fafbfcfdff00), [U8](0...15) + [U8](repeating: U8.max, count: 16)), (LiteralInt( 0x0f0e0d0c0b0a09080706050403020100), [U8](0...15) + [U8](repeating: U8.min, count: 16)), - ])) func byteSequencePrefix(instance: LiteralInt, expectation: [U8]) { + ])) func byteSequencePrefix( + instance: LiteralInt, expectation: [U8] + ) throws { + let ratio: IX = IX(size: UX.self) / IX(size: U8.self) for index: IX in IX.zero ..< IX(expectation.count) { let word: UX = instance[UX(index / ratio)] let byte: U8 = U8(load: word >> (index % ratio * 8)) - #expect(byte == expectation[Swift.Int(index)]) + try #require(byte == expectation[Swift.Int(index)]) } } } diff --git a/Tests/CoreKitTests/LiteralInt+Text.swift b/Tests/CoreKitTests/LiteralInt+Text.swift index 6bb43c91..28a346ec 100644 --- a/Tests/CoreKitTests/LiteralInt+Text.swift +++ b/Tests/CoreKitTests/LiteralInt+Text.swift @@ -14,7 +14,7 @@ import TestKit // MARK: * Literal Int x Text //*============================================================================* -@Suite struct LiteralIntTestsOnText { +@Suite(.serialized) struct LiteralIntTestsOnText { //=------------------------------------------------------------------------= // MARK: Tests @@ -23,8 +23,7 @@ import TestKit @Test( "LiteralInt/text: description", Tag.List.tags(.documentation, .unofficial), - ParallelizationTrait.serialized, - arguments: Array<(LiteralInt, String)>([ + arguments: Array<(LiteralInt, String)>.infer([ (LiteralInt(-8), "-0x8"), // 000....1 (LiteralInt(-7), "-0x7"), // 100....1 diff --git a/Tests/CoreKitTests/Order+Comparison.swift b/Tests/CoreKitTests/Order+Comparison.swift index 8ba72fb2..14981306 100644 --- a/Tests/CoreKitTests/Order+Comparison.swift +++ b/Tests/CoreKitTests/Order+Comparison.swift @@ -14,17 +14,16 @@ import TestKit // MARK: * Order x Comparison //*============================================================================* -@Suite struct OrderTestsOnComparison { +@Suite(.serialized) struct OrderTestsOnComparison { //=------------------------------------------------------------------------= // MARK: Tests //=------------------------------------------------------------------------= @Test( - "Order/comparison: Order vs Order", + "Order/comparison: Self vs Self", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Order, Order, Bool)>([ + arguments: Array<(Order, Order, Bool)>.infer([ (Order.ascending, Order.ascending, true ), (Order.ascending, Order.descending, false), diff --git a/Tests/CoreKitTests/Order.swift b/Tests/CoreKitTests/Order.swift index 5203464e..6a928d62 100644 --- a/Tests/CoreKitTests/Order.swift +++ b/Tests/CoreKitTests/Order.swift @@ -14,7 +14,7 @@ import TestKit // MARK: * Order //*============================================================================* -@Suite struct OrderTests { +@Suite(.serialized) struct OrderTests { //=------------------------------------------------------------------------= // MARK: Tests @@ -23,18 +23,16 @@ import TestKit @Test( "Order: init()", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: [Order.ascending] + arguments: CollectionOfOne(Order.ascending) ) func unspecified(expectation: Order) { #expect(Order() == expectation) #expect(Order(raw: Bit.zero) == expectation) } @Test( - "Order: descending", + "Order: init(descending:)", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Order, Bool)>([ + arguments: Array<(Order, Bool)>.infer([ (Order.ascending, false), (Order.descending, true ), @@ -56,10 +54,9 @@ import TestKit } @Test( - "Order: reversed", + "Order: reversed()", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Order, Order)>([ + arguments: Array<(Order, Order)>.infer([ (Order.ascending, Order.descending), (Order.descending, Order.ascending ), diff --git a/Tests/CoreKitTests/Sign+Bitwise.swift b/Tests/CoreKitTests/Sign+Bitwise.swift index 9f3a728c..8467204d 100644 --- a/Tests/CoreKitTests/Sign+Bitwise.swift +++ b/Tests/CoreKitTests/Sign+Bitwise.swift @@ -23,8 +23,7 @@ import TestKit @Test( "Sign/bitwise: ~(_:)", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Sign, Sign)>([ + arguments: Array<(Sign, Sign)>.infer([ (Sign.plus, Sign.minus), (Sign.minus, Sign.plus ), @@ -38,8 +37,7 @@ import TestKit @Test( "Sign/bitwise: &(_:_:)", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Sign, Sign, Sign)>([ + arguments: Array<(Sign, Sign, Sign)>.infer([ (Sign.plus, Sign.plus, Sign.plus ), (Sign.plus, Sign.minus, Sign.plus ), @@ -54,8 +52,7 @@ import TestKit @Test( "Sign/bitwise: |(_:_:)", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Sign, Sign, Sign)>([ + arguments: Array<(Sign, Sign, Sign)>.infer([ (Sign.plus, Sign.plus, Sign.plus ), (Sign.plus, Sign.minus, Sign.minus), @@ -70,8 +67,7 @@ import TestKit @Test( "Sign/bitwise: ^(_:_:)", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Sign, Sign, Sign)>([ + arguments: Array<(Sign, Sign, Sign)>.infer([ (Sign.plus, Sign.plus, Sign.plus ), (Sign.plus, Sign.minus, Sign.minus), diff --git a/Tests/CoreKitTests/Sign+Comparison.swift b/Tests/CoreKitTests/Sign+Comparison.swift index cfc879c6..badaedd5 100644 --- a/Tests/CoreKitTests/Sign+Comparison.swift +++ b/Tests/CoreKitTests/Sign+Comparison.swift @@ -14,7 +14,7 @@ import TestKit // MARK: * Sign x Comparison //*============================================================================* -@Suite struct SignTestsOnComparison { +@Suite(.serialized) struct SignTestsOnComparison { //=------------------------------------------------------------------------= // MARK: Tests @@ -23,8 +23,7 @@ import TestKit @Test( "Sign/comparison: Sign vs Sign", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Sign, Sign, Bool)>([ + arguments: Array<(Sign, Sign, Bool)>.infer([ (Sign.plus, Sign.plus, true ), (Sign.plus, Sign.minus, false), diff --git a/Tests/CoreKitTests/Sign+Text.swift b/Tests/CoreKitTests/Sign+Text.swift index cce48e94..2f00ebd9 100644 --- a/Tests/CoreKitTests/Sign+Text.swift +++ b/Tests/CoreKitTests/Sign+Text.swift @@ -14,18 +14,21 @@ import TestKit // MARK: * Sign x Text //*============================================================================* -@Suite struct SignTestsOnText { +@Suite(.serialized) struct SignTestsOnText { //=------------------------------------------------------------------------= // MARK: Tests //=------------------------------------------------------------------------= - @Test("Sign/description", .serialized, arguments: [ + @Test( + "Sign/text: description", + Tag.List.tags(.documentation, .exhaustive), + arguments: Array<(Sign, String)>.infer([ - (sign: Sign.plus, description: "+"), - (sign: Sign.minus, description: "-"), + (Sign.plus, "+"), + (Sign.minus, "-"), - ]) func description(sign: Sign, description: String) { - Ɣexpect(sign, description: description) + ])) func description(instance: Sign, description: String) { + Ɣexpect(instance, description: description) } } diff --git a/Tests/CoreKitTests/Sign.swift b/Tests/CoreKitTests/Sign.swift index 06f51329..243ef374 100644 --- a/Tests/CoreKitTests/Sign.swift +++ b/Tests/CoreKitTests/Sign.swift @@ -14,7 +14,7 @@ import TestKit // MARK: * Sign //*============================================================================* -@Suite struct SignTests { +@Suite(.serialized) struct SignTests { //=------------------------------------------------------------------------= // MARK: Tests @@ -23,8 +23,7 @@ import TestKit @Test( "Sign: init()", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: [Sign.plus] + arguments: CollectionOfOne(Sign.plus) ) func unspecified(expectation: Sign) { #expect(Sign() == expectation) #expect(Sign(raw: Bit.zero) == expectation) @@ -32,47 +31,47 @@ import TestKit @Test( "Sign: as Bit", - ParallelizationTrait.serialized, - arguments: Array<(Sign, Bit)>([ + Tag.List.tags(.documentation, .exhaustive), + arguments: Array<(Sign, Bit)>.infer([ (sign: Sign.plus, bit: Bit.zero), (sign: Sign.minus, bit: Bit.one ), - ])) func bit(_ argument: (sign: Sign, bit: Bit)) { - #expect(Bit ( argument.sign) == argument.bit ) - #expect(Bit (raw: argument.sign) == argument.bit ) - #expect(Sign( argument.bit ) == argument.sign) - #expect(Sign(raw: argument.bit ) == argument.sign) + ])) func bit(source: Sign, destination: Bit) { + #expect(type(of: destination).init( source) == destination) + #expect(type(of: destination).init(raw: source) == destination) + #expect(type(of: source).init( destination) == source) + #expect(type(of: source).init(raw: destination) == source) } @Test( "Sign: as Bool", - ParallelizationTrait.serialized, - arguments: Array<(Sign, Bool)>([ + Tag.List.tags(.documentation, .exhaustive), + arguments: Array<(Sign, Bool)>.infer([ (sign: Sign.plus, bool: false), (sign: Sign.minus, bool: true ), - ])) func bool(_ argument: (sign: Sign, bool: Bool)) { - #expect(Bool( argument.sign) == argument.bool) - #expect(Bool(raw: argument.sign) == argument.bool) - #expect(Sign( argument.bool) == argument.sign) - #expect(Sign(raw: argument.bool) == argument.sign) + ])) func bool(source: Sign, destination: Bool) { + #expect(type(of: destination).init( source) == destination) + #expect(type(of: destination).init(raw: source) == destination) + #expect(type(of: source).init( destination) == source) + #expect(type(of: source).init(raw: destination) == source) } @Test( "Sign: as Stdlib", - ParallelizationTrait.serialized, - arguments: Array<(Sign, FloatingPointSign)>([ + Tag.List.tags(.documentation, .exhaustive), + arguments: Array<(Sign, FloatingPointSign)>.infer([ (sign: Sign.plus, stdlib: FloatingPointSign.plus ), (sign: Sign.minus, stdlib: FloatingPointSign.minus), - ])) func stdlib(_ argument: (sign: Sign, stdlib: FloatingPointSign)) { - #expect(argument.sign.stdlib() == argument.stdlib) - #expect(FloatingPointSign( argument.sign) == argument.stdlib) - #expect(FloatingPointSign(raw: argument.sign) == argument.stdlib) - #expect(Sign( argument.stdlib) == argument.sign) - #expect(Sign(raw: argument.stdlib) == argument.sign) + ])) func stdlib(source: Sign, destination: FloatingPointSign) { + #expect(source.stdlib() == destination) + #expect(type(of: destination).init( source) == destination) + #expect(type(of: destination).init(raw: source) == destination) + #expect(type(of: source).init( destination) == source) + #expect(type(of: source).init(raw: destination) == source) } } diff --git a/Tests/CoreKitTests/Signedness+Comparison.swift b/Tests/CoreKitTests/Signedness+Comparison.swift index 5cd4504a..541fe91e 100644 --- a/Tests/CoreKitTests/Signedness+Comparison.swift +++ b/Tests/CoreKitTests/Signedness+Comparison.swift @@ -14,7 +14,7 @@ import TestKit // MARK: * Signedness x Comparison //*============================================================================* -@Suite struct SignednessTestsOnComparison { +@Suite(.serialized) struct SignednessTestsOnComparison { //=------------------------------------------------------------------------= // MARK: Tests @@ -23,8 +23,7 @@ import TestKit @Test( "Signedness/comparison: Self vs Self", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Signedness, Signedness, Bool)>([ + arguments: Array<(Signedness, Signedness, Bool)>.infer([ (Signedness.unsigned, Signedness.unsigned, true ), (Signedness.unsigned, Signedness .signed, false), diff --git a/Tests/CoreKitTests/Signedness.swift b/Tests/CoreKitTests/Signedness.swift index e86d6cc4..df4f07bb 100644 --- a/Tests/CoreKitTests/Signedness.swift +++ b/Tests/CoreKitTests/Signedness.swift @@ -14,7 +14,7 @@ import TestKit // MARK: * Signedness //*============================================================================* -@Suite struct SignednessTests { +@Suite(.serialized) struct SignednessTests { //=------------------------------------------------------------------------= // MARK: Tests @@ -23,18 +23,16 @@ import TestKit @Test( "Signedness: init()", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: [Signedness.unsigned] + arguments: CollectionOfOne(Signedness.unsigned) ) func unspecified(expectation: Signedness) { #expect(Signedness() == expectation) #expect(Signedness(raw: Bit.zero) == expectation) } @Test( - "Signedness: signed", + "Signedness: init(signed:)", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Signedness, Bool)>([ + arguments: Array<(Signedness, Bool)>.infer([ (Signedness.unsigned, false), (Signedness .signed, true ), diff --git a/Tests/CoreKitTests/Signum+Addition.swift b/Tests/CoreKitTests/Signum+Addition.swift index 64e41ea9..cf8c1dd8 100644 --- a/Tests/CoreKitTests/Signum+Addition.swift +++ b/Tests/CoreKitTests/Signum+Addition.swift @@ -14,7 +14,7 @@ import TestKit // MARK: * Signum x Addition //*============================================================================* -@Suite struct SignumTestsOnAddition { +@Suite(.serialized) struct SignumTestsOnAddition { //=------------------------------------------------------------------------= // MARK: Tests @@ -23,8 +23,7 @@ import TestKit @Test( "Signum/addition: negated()", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Signum, Signum)>([ + arguments: Array<(Signum, Signum)>.infer([ (Signum.negative, Signum.positive), (Signum.zero, Signum.zero ), diff --git a/Tests/CoreKitTests/Signum+Comparison.swift b/Tests/CoreKitTests/Signum+Comparison.swift index fac47539..a70ef746 100644 --- a/Tests/CoreKitTests/Signum+Comparison.swift +++ b/Tests/CoreKitTests/Signum+Comparison.swift @@ -23,8 +23,7 @@ import TestKit @Test( "Signum/comparison: is negative", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Signum, Bool)>([ + arguments: Array<(Signum, Bool)>.infer([ (Signum.negative, true ), (Signum.zero, false), @@ -37,8 +36,7 @@ import TestKit @Test( "Signum/comparison: is zero", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Signum, Bool)>([ + arguments: Array<(Signum, Bool)>.infer([ (Signum.negative, false), (Signum.zero, true ), @@ -51,8 +49,7 @@ import TestKit @Test( "Signum/comparison: is positive", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Signum, Bool)>([ + arguments: Array<(Signum, Bool)>.infer([ (Signum.negative, false), (Signum.zero, false), @@ -65,8 +62,7 @@ import TestKit @Test( "Signum/comparison: Self vs Self", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Signum, Signum, Signum)>([ + arguments: Array<(Signum, Signum, Signum)>.infer([ (Signum.negative, Signum.negative, Signum.zero), (Signum.negative, Signum.zero, Signum.negative), diff --git a/Tests/CoreKitTests/Signum.swift b/Tests/CoreKitTests/Signum.swift index 6360a58c..30c276ad 100644 --- a/Tests/CoreKitTests/Signum.swift +++ b/Tests/CoreKitTests/Signum.swift @@ -23,8 +23,7 @@ import TestKit @Test( "Signum: from Bit", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Bit, Signum)>([ + arguments: Array<(Bit, Signum)>.infer([ (Bit.zero, Signum.zero ), (Bit.one, Signum.positive), @@ -36,8 +35,7 @@ import TestKit @Test( "Signum: from Sign or Sign?", Tag.List.tags(.documentation, .exhaustive), - ParallelizationTrait.serialized, - arguments: Array<(Sign?, Signum)>([ + arguments: Array<(Sign?, Signum)>.infer([ (Optional(nil ), Signum.zero), (Optional(Sign.plus ), Signum.positive), @@ -48,7 +46,7 @@ import TestKit #expect(Signum(source) == destination) } - if let source = source { + if let source { #expect(Signum(source) == destination) } } diff --git a/Tests/CoreKitTests/Stdlib/Swift+BinaryInteger.swift b/Tests/CoreKitTests/Stdlib/Swift+BinaryInteger.swift index 6b55a4d5..034ffada 100644 --- a/Tests/CoreKitTests/Stdlib/Swift+BinaryInteger.swift +++ b/Tests/CoreKitTests/Stdlib/Swift+BinaryInteger.swift @@ -21,30 +21,31 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("T.init(raw:)", arguments: typesAsCoreInteger, fuzzers) - func bitcasting(type: any CoreInteger.Type, randomness: consuming FuzzerInt) { - whereIs(type) + @Test( + "Swift/binary-integer: init(raw:)", + Tag.List.tags(.generic, .random), + arguments: typesAsCoreInteger, fuzzers + ) func bitcasting( + type: any CoreInteger.Type, randomness: consuming FuzzerInt + ) throws { - func whereIs(_ type: T.Type) where T: CoreInteger { - check(T.min ) - check(T.zero) - check(T.max ) - + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: CoreInteger { for _ in 0 ..< 32 { - check(T.random(using: &randomness)) + try whereIs(T.random(using: &randomness)) } } - func check(_ instance: T) where T: CoreInteger { + func whereIs(_ instance: T) throws where T: CoreInteger { var instance = instance let expectation = instance - #expect(expectation == T( instance.stdlib)) - #expect(expectation == T(raw: instance.stdlib)) - #expect(expectation == T( instance.stdlib())) - #expect(expectation == T(raw: instance.stdlib())) - #expect(expectation == T( T.Stdlib( instance))) - #expect(expectation == T(raw: T.Stdlib(raw: instance))) + try #require(expectation == T( instance.stdlib)) + try #require(expectation == T(raw: instance.stdlib)) + try #require(expectation == T( instance.stdlib())) + try #require(expectation == T(raw: instance.stdlib())) + try #require(expectation == T( T.Stdlib( instance))) + try #require(expectation == T(raw: T.Stdlib(raw: instance))) } } } diff --git a/Tests/CoreKitTests/Stdlib/Swift+Optional.swift b/Tests/CoreKitTests/Stdlib/Swift+Optional.swift index e9a3c0a5..0e444d66 100644 --- a/Tests/CoreKitTests/Stdlib/Swift+Optional.swift +++ b/Tests/CoreKitTests/Stdlib/Swift+Optional.swift @@ -21,32 +21,44 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("T.init(raw:)", arguments: typesAsCoreInteger, fuzzers) - func bitcasting(type: any SystemsInteger.Type, randomness: consuming FuzzerInt) { - whereIs(type) + @Test( + "Swift/optional: init(raw:)", + Tag.List.tags(.generic, .random), + arguments: typesAsCoreInteger, fuzzers + ) func bitcasting( + type: any SystemsInteger.Type, randomness: consuming FuzzerInt + ) throws { - func whereIs(_ type: T.Type) where T: SystemsInteger { - #expect(Optional(raw: Optional.none) == Optional.none) - #expect(Optional(raw: Optional.none) == Optional.none) + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: SystemsInteger { + try #require(Optional(raw: Optional.none) == Optional.none) + try #require(Optional(raw: Optional.none) == Optional.none) - for _ in 0 ..< 32 { + for _ in 0 ..< 8 { let magnitude = T.Magnitude.random(using: &randomness) let signitude = T.Signitude.random(using: &randomness) - #expect(Optional(raw: Optional(magnitude)) == T(raw: magnitude)) - #expect(Optional(raw: Optional(signitude)) == T(raw: signitude)) + try #require(Optional(raw: Optional(magnitude)) == T(raw: magnitude)) + try #require(Optional(raw: Optional(signitude)) == T(raw: signitude)) } } } - @Test("Optional/unwrap()", arguments: typesAsCoreInteger, fuzzers) - func unwrapping(type: any SystemsInteger.Type, randomness: consuming FuzzerInt) { - whereIs(type) + @Test( + "Swift/optional: unwrap()", + Tag.List.tags(.generic, .random), + arguments: typesAsCoreInteger, fuzzers + ) func unwrapping( + type: any SystemsInteger.Type, randomness: consuming FuzzerInt + ) throws { - func whereIs(_ type: T.Type) where T: SystemsInteger { - let random = T.random(using: &randomness) - #expect(Optional(random).unwrap() == random) - #expect(Optional(random).unchecked() == random) + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: SystemsInteger { + for _ in 0 ..< 8 { + let random = T.random(using: &randomness) + try #require(Optional(random).unwrap() == random) + try #require(Optional(random).unchecked() == random) + } } } } diff --git a/Tests/DoubleIntKitTests/DoubleInt+Addition.swift b/Tests/DoubleIntKitTests/DoubleInt+Addition.swift index 736f0833..904f5ed0 100644 --- a/Tests/DoubleIntKitTests/DoubleInt+Addition.swift +++ b/Tests/DoubleIntKitTests/DoubleInt+Addition.swift @@ -29,7 +29,9 @@ import TestKit "DoubleInt/addition/not-in-protocol: random 212 vs 222", Tag.List.tags(.generic, .random), arguments: DoubleIntTests.bases, fuzzers - ) func random212vs222(base: any SystemsInteger.Type, randomness: consuming FuzzerInt) throws { + ) func random212vs222( + base: any SystemsInteger.Type, randomness: consuming FuzzerInt + ) throws { try whereIs(base) func whereIs(_ base: B.Type) throws where B: SystemsInteger { diff --git a/Tests/DoubleIntKitTests/DoubleInt+Multiplication.swift b/Tests/DoubleIntKitTests/DoubleInt+Multiplication.swift index bfa1fe88..f902ac8d 100644 --- a/Tests/DoubleIntKitTests/DoubleInt+Multiplication.swift +++ b/Tests/DoubleIntKitTests/DoubleInt+Multiplication.swift @@ -28,7 +28,9 @@ import TestKit "DoubleInt/multiplication/not-in-protocol: random 213 vs 224", Tag.List.tags(.generic, .random), arguments: DoubleIntTests.bases, fuzzers - ) func random213vs224(base: any SystemsInteger.Type, randomness: consuming FuzzerInt) throws { + ) func random213vs224( + base: any SystemsInteger.Type, randomness: consuming FuzzerInt + ) throws { try whereIs(base) func whereIs(_ base: B.Type) throws where B: SystemsInteger { diff --git a/Tests/FibonacciKitTests/Indexacci+Text.swift b/Tests/FibonacciKitTests/Indexacci+Text.swift index ceb0e7a3..8104a394 100644 --- a/Tests/FibonacciKitTests/Indexacci+Text.swift +++ b/Tests/FibonacciKitTests/Indexacci+Text.swift @@ -15,7 +15,7 @@ import TestKit // MARK: * Indexacci x Text //*============================================================================* -@Suite struct IndexacciTestsOnText { +@Suite(.serialized) struct IndexacciTestsOnText { //=------------------------------------------------------------------------= // MARK: Tests @@ -24,8 +24,7 @@ import TestKit @Test( "Indexacci/text: description", Tag.List.tags(.documentation, .unofficial), - ParallelizationTrait.serialized, - arguments: Array<(I8, I8, I8, String)>([ + arguments: Array<(I8, I8, I8, String)>.infer([ (I8(0), I8(0), I8(0), "(0: 0, 0)"), (I8(3), I8(5), I8(4), "(4: 3, 5)"), diff --git a/Tests/FibonacciKitTests/Tupleacci+Text.swift b/Tests/FibonacciKitTests/Tupleacci+Text.swift index 1bdf3300..c48cfb3c 100644 --- a/Tests/FibonacciKitTests/Tupleacci+Text.swift +++ b/Tests/FibonacciKitTests/Tupleacci+Text.swift @@ -15,7 +15,7 @@ import TestKit // MARK: * Tupleacci x Text //*============================================================================* -@Suite struct TupleacciTestsOnText { +@Suite(.serialized) struct TupleacciTestsOnText { //=------------------------------------------------------------------------= // MARK: Tests @@ -24,8 +24,7 @@ import TestKit @Test( "Tupleacci/text: description", Tag.List.tags(.documentation, .unofficial), - ParallelizationTrait.serialized, - arguments: Array<(I8, I8, String)>([ + arguments: Array<(I8, I8, String)>.infer([ (I8(0), I8(0), "(0, 0)"), (I8(3), I8(5), "(3, 5)"), diff --git a/Tests/RandomIntKitTests/FuzzerInt.swift b/Tests/RandomIntKitTests/FuzzerInt.swift index 112541dc..b46d7b6e 100644 --- a/Tests/RandomIntKitTests/FuzzerInt.swift +++ b/Tests/RandomIntKitTests/FuzzerInt.swift @@ -15,7 +15,7 @@ import TestKit // MARK: * Fuzzer Int //*============================================================================* -@Suite struct FuzzerIntTests { +@Suite(.serialized) struct FuzzerIntTests { //=------------------------------------------------------------------------= // MARK: Tests @@ -29,8 +29,7 @@ import TestKit @Test( "FuzzerInt: prefix", Tag.List.tags(.documentation, .unofficial), - ParallelizationTrait.serialized, - arguments: Array<(I64, [U64])>([ + arguments: Array<(I64, [U64])>.infer([ ( 0 as I64, [0xe220a8397b1dcdaf, 0x6e789e6aa1b965f4, 0x06c45d188009454f, 0xf88bb8a8724c81ec] as [U64]), ( 1 as I64, [0x910a2dec89025cc1, 0xbeeb8da1658eec67, 0xf893a2eefb32555e, 0x71c18690ee42c90b] as [U64]), diff --git a/Tests/StdlibIntKitTests/StdlibInt+Addition.swift b/Tests/StdlibIntKitTests/StdlibInt+Addition.swift index aaf5bf92..89c0aefa 100644 --- a/Tests/StdlibIntKitTests/StdlibInt+Addition.swift +++ b/Tests/StdlibIntKitTests/StdlibInt+Addition.swift @@ -8,6 +8,8 @@ //=----------------------------------------------------------------------------= import CoreKit +import InfiniIntKit +import RandomIntKit import StdlibIntKit import TestKit @@ -31,41 +33,47 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("StdlibInt - addition [forwarding]", arguments: [ - - ( 0 as StdlibInt, 0 as StdlibInt, 0 as StdlibInt), - ( 3 as StdlibInt, 5 as StdlibInt, 8 as StdlibInt), - ( 3 as StdlibInt, -5 as StdlibInt, -2 as StdlibInt), - (-3 as StdlibInt, 5 as StdlibInt, 2 as StdlibInt), - (-3 as StdlibInt, -5 as StdlibInt, -8 as StdlibInt), - - ] as [(StdlibInt, StdlibInt, StdlibInt)]) func addition(lhs: StdlibInt, rhs: StdlibInt, expectation: StdlibInt) { - #expect(lhs + rhs == expectation) - #expect(rhs + lhs == expectation) - - #expect({ var x = lhs; x += rhs; return x }() == expectation) - #expect({ var x = rhs; x += lhs; return x }() == expectation) - - #expect(expectation - lhs == rhs) - #expect(expectation - rhs == lhs) - - #expect({ var x = expectation; x -= lhs; return x }() == rhs) - #expect({ var x = expectation; x -= rhs; return x }() == lhs) + @Test( + "StdlibInt/addition: -(_:) of Self vs Base", + Tag.List.tags(.forwarding, .random), + arguments: fuzzers + ) func negation(randomness: consuming FuzzerInt) throws { + for _ in 0 ..< conditional(debug: 64, release: 128) { + let x = IXL.entropic(through: Shift.max(or: 255), using: &randomness) + let y = x.negated() as IXL + + try #require(StdlibInt(x) == -StdlibInt(y)) + try #require(StdlibInt(y) == -StdlibInt(x)) + } } - @Test("StdlibInt - negation [forwarding]", arguments: [ - - (-2 as StdlibInt, 2 as StdlibInt), - (-1 as StdlibInt, 1 as StdlibInt), - ( 0 as StdlibInt, 0 as StdlibInt), - ( 1 as StdlibInt, -1 as StdlibInt), - ( 2 as StdlibInt, -2 as StdlibInt), - - ] as [(StdlibInt, StdlibInt)]) func negation(instance: StdlibInt, expectation: StdlibInt) { - #expect(-instance == expectation) - #expect(-expectation == instance) - - #expect({ var x = instance; x.negate(); return x }() == expectation) - #expect({ var x = expectation; x.negate(); return x }() == instance) + @Test( + "StdlibInt/addition: +(_:_:) of Self vs Base", + Tag.List.tags(.forwarding, .random), + arguments: fuzzers + ) func addition(randomness: consuming FuzzerInt) throws { + for _ in 0 ..< conditional(debug: 64, release: 128) { + let a = IXL.entropic(through: Shift.max(or: 255), using: &randomness) + let b = IXL.entropic(through: Shift.max(or: 255), using: &randomness) + let c = a.plus(b) as IXL + + try #require(StdlibInt(c) == reduce(StdlibInt(a), +, StdlibInt(b))) + try #require(StdlibInt(c) == reduce(StdlibInt(a), +=, StdlibInt(b))) + } + } + + @Test( + "StdlibInt/addition: -(_:_:) of Self vs Base", + Tag.List.tags(.forwarding, .random), + arguments: fuzzers + ) func subtraction(randomness: consuming FuzzerInt) throws { + for _ in 0 ..< conditional(debug: 64, release: 128) { + let a = IXL.entropic(through: Shift.max(or: 255), using: &randomness) + let b = IXL.entropic(through: Shift.max(or: 255), using: &randomness) + let c = a.minus(b) as IXL + + try #require(StdlibInt(c) == reduce(StdlibInt(a), -, StdlibInt(b))) + try #require(StdlibInt(c) == reduce(StdlibInt(a), -=, StdlibInt(b))) + } } } diff --git a/Tests/StdlibIntKitTests/StdlibInt+Bitwise.swift b/Tests/StdlibIntKitTests/StdlibInt+Bitwise.swift index f484160c..36a8b93a 100644 --- a/Tests/StdlibIntKitTests/StdlibInt+Bitwise.swift +++ b/Tests/StdlibIntKitTests/StdlibInt+Bitwise.swift @@ -27,14 +27,17 @@ import TestKit /// /// - TODO: Test `StdlibInt` forwarding in generic `BinaryInteger` tests. /// -@Suite(.tags(.forwarding)) struct StdlibIntTestsOnBitwise { +@Suite struct StdlibIntTestsOnBitwise { //=------------------------------------------------------------------------= // MARK: Tests //=------------------------------------------------------------------------= - @Test("StdlibInt.~(_:)", .tags(.random), arguments: fuzzers) - func not(_ randomness: consuming FuzzerInt) throws { + @Test( + "StdlibInt/bitwise: ~(_:) of Self vs Base", + Tag.List.tags(.forwarding, .random), + arguments: fuzzers + ) func not(_ randomness: consuming FuzzerInt) throws { for _ in 0 ..< 32 { let random = IXL.entropic(size: 256, using: &randomness) let expectation = random.toggled() @@ -44,8 +47,11 @@ import TestKit } } - @Test("StdlibInt.&(_:_:)", .tags(.random), arguments: fuzzers) - func and(_ randomness: consuming FuzzerInt) throws { + @Test( + "StdlibInt/bitwise: &(_:_:) of Self vs Base", + Tag.List.tags(.forwarding, .random), + arguments: fuzzers + ) func and(_ randomness: consuming FuzzerInt) throws { for _ in 0 ..< 32 { let lhs = IXL.entropic(size: 256, using: &randomness) let rhs = IXL.entropic(size: 256, using: &randomness) @@ -56,8 +62,11 @@ import TestKit } } - @Test("StdlibInt.|(_:_:)", .tags(.random), arguments: fuzzers) - func or(_ randomness: consuming FuzzerInt) throws { + @Test( + "StdlibInt/bitwise: |(_:_:) of Self vs Base", + Tag.List.tags(.forwarding, .random), + arguments: fuzzers + ) func or(_ randomness: consuming FuzzerInt) throws { for _ in 0 ..< 32 { let lhs = IXL.entropic(size: 256, using: &randomness) let rhs = IXL.entropic(size: 256, using: &randomness) @@ -68,8 +77,11 @@ import TestKit } } - @Test("StdlibInt.^(_:_:)", .tags(.random), arguments: fuzzers) - func xor(_ randomness: consuming FuzzerInt) throws { + @Test( + "StdlibInt/bitwise: ^(_:_:) of Self vs Base", + Tag.List.tags(.forwarding, .random), + arguments: fuzzers + ) func xor(_ randomness: consuming FuzzerInt) throws { for _ in 0 ..< 32 { let lhs = IXL.entropic(size: 256, using: &randomness) let rhs = IXL.entropic(size: 256, using: &randomness) diff --git a/Tests/StdlibIntKitTests/StdlibInt+Comparison.swift b/Tests/StdlibIntKitTests/StdlibInt+Comparison.swift index d4e9fe23..f1758d0e 100644 --- a/Tests/StdlibIntKitTests/StdlibInt+Comparison.swift +++ b/Tests/StdlibIntKitTests/StdlibInt+Comparison.swift @@ -33,8 +33,11 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("StdlibInt/comparison: vs StdlibInt.Base", .tags(.forwarding, .random), arguments: fuzzers) - func forwarding(_ randomness: consuming FuzzerInt) throws { + @Test( + "StdlibInt/comparison: Self vs Base", + Tag.List.tags(.forwarding, .random), + arguments: fuzzers + ) func forwarding(_ randomness: consuming FuzzerInt) throws { for _ in 0 ..< conditional(debug: 64, release: 128) { let lhs = IXL.entropic(through: Shift.max(or: 255), using: &randomness) let rhs = IXL.entropic(through: Shift.max(or: 255), using: &randomness) diff --git a/Tests/StdlibIntKitTests/StdlibInt+Count.swift b/Tests/StdlibIntKitTests/StdlibInt+Count.swift index 32ee88cf..6f7d843d 100644 --- a/Tests/StdlibIntKitTests/StdlibInt+Count.swift +++ b/Tests/StdlibIntKitTests/StdlibInt+Count.swift @@ -33,8 +33,11 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("StdlibInt/count: vs StdlibInt.Base", .tags(.forwarding, .random), arguments: fuzzers) - func forwarding(_ randomness: consuming FuzzerInt) throws { + @Test( + "StdlibInt/count: Self vs Base", + Tag.List.tags(.forwarding, .random), + arguments: fuzzers + ) func forwarding(_ randomness: consuming FuzzerInt) throws { for _ in 0 ..< 1024 { let random = IXL.entropic(through: Shift.max(or: 255), using: &randomness) @@ -63,8 +66,10 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("StdlibInt/count/edge-cases: 0.trailingZeroBitCount", .tags(.exhaustive)) - func trailingZeroBitCountOfZero() { + @Test( + "StdlibInt/count/edge-cases: 0.trailingZeroBitCount", + Tag.List.tags(.exhaustive, .important) + ) func trailingZeroBitCountOfZero() { #expect(IXL.zero.ascending(Bit.zero) == Count.infinity) #expect(StdlibInt(IXL.zero).trailingZeroBitCount == 1) #expect(StdlibInt(IXL.zero).trailingZeroBitCount == StdlibInt.zero.bitWidth) diff --git a/Tests/StdlibIntKitTests/StdlibInt+Division.swift b/Tests/StdlibIntKitTests/StdlibInt+Division.swift index e0326102..14c0b4b2 100644 --- a/Tests/StdlibIntKitTests/StdlibInt+Division.swift +++ b/Tests/StdlibIntKitTests/StdlibInt+Division.swift @@ -34,7 +34,7 @@ import TestKit //=------------------------------------------------------------------------= @Test( - "StdlibInt/division: vs StdlibInt.Base", + "StdlibInt/division: Self vs Base", Tag.List.tags(.forwarding, .random), arguments: fuzzers ) func forwarding(_ randomness: consuming FuzzerInt) throws { @@ -44,7 +44,6 @@ import TestKit if !b.isZero { let (q, r) = try #require(a.division(b)).components() - try #require(StdlibInt(q) == reduce(StdlibInt(a), /, StdlibInt(b))) try #require(StdlibInt(q) == reduce(StdlibInt(a), /=, StdlibInt(b))) try #require(StdlibInt(q) == StdlibInt(a).quotientAndRemainder(dividingBy: StdlibInt(b)).quotient) diff --git a/Tests/StdlibIntKitTests/StdlibInt+Floats.swift b/Tests/StdlibIntKitTests/StdlibInt+Floats.swift index 5fbe8f60..abb44436 100644 --- a/Tests/StdlibIntKitTests/StdlibInt+Floats.swift +++ b/Tests/StdlibIntKitTests/StdlibInt+Floats.swift @@ -34,7 +34,7 @@ import TestKit //=------------------------------------------------------------------------= @Test( - "StdlibInt/floats: from SwiftIEEE754 vs StdlibInt.Base", + "StdlibInt/floats: from SwiftIEEE754 of Self vs Base", Tag.List.tags(.forwarding, .generic, .random), arguments: fuzzers ) func forwarding(randomness: consuming FuzzerInt) throws { diff --git a/Tests/StdlibIntKitTests/StdlibInt+Integers.swift b/Tests/StdlibIntKitTests/StdlibInt+Integers.swift index ffcbc322..c6862039 100644 --- a/Tests/StdlibIntKitTests/StdlibInt+Integers.swift +++ b/Tests/StdlibIntKitTests/StdlibInt+Integers.swift @@ -34,36 +34,36 @@ import TestKit //=------------------------------------------------------------------------= @Test( - "StdlibInt/integers: init(some Swift.BinaryInteger)", + "StdlibInt/integers: init(_:)", Tag.List.tags(.forwarding), ParallelizationTrait.serialized, - arguments: Array<(any Swift.BinaryInteger & Sendable, StdlibInt)>([ + arguments: Array<(any Swift.BinaryInteger & Sendable, StdlibInt)>.infer([ - ( Int8.min as any (Swift.BinaryInteger & Sendable), -0x80 as StdlibInt), - ( Int8.max as any (Swift.BinaryInteger & Sendable), 0x7f as StdlibInt), - ( UInt8.min as any (Swift.BinaryInteger & Sendable), 0x00 as StdlibInt), - ( UInt8.max as any (Swift.BinaryInteger & Sendable), 0xff as StdlibInt), - ( Int16.min as any (Swift.BinaryInteger & Sendable), -0x8000 as StdlibInt), - ( Int16.max as any (Swift.BinaryInteger & Sendable), 0x7fff as StdlibInt), - (UInt16.min as any (Swift.BinaryInteger & Sendable), 0x0000 as StdlibInt), - (UInt16.max as any (Swift.BinaryInteger & Sendable), 0xffff as StdlibInt), - ( Int32.min as any (Swift.BinaryInteger & Sendable), -0x80000000 as StdlibInt), - ( Int32.max as any (Swift.BinaryInteger & Sendable), 0x7fffffff as StdlibInt), - (UInt32.min as any (Swift.BinaryInteger & Sendable), 0x00000000 as StdlibInt), - (UInt32.max as any (Swift.BinaryInteger & Sendable), 0xffffffff as StdlibInt), - ( Int64.min as any (Swift.BinaryInteger & Sendable), -0x8000000000000000 as StdlibInt), - ( Int64.max as any (Swift.BinaryInteger & Sendable), 0x7fffffffffffffff as StdlibInt), - (UInt64.min as any (Swift.BinaryInteger & Sendable), 0x0000000000000000 as StdlibInt), - (UInt64.max as any (Swift.BinaryInteger & Sendable), 0xffffffffffffffff as StdlibInt), + ( Int8.min, StdlibInt( -0x80)), + ( Int8.max, StdlibInt( 0x7f)), + ( UInt8.min, StdlibInt( 0x00)), + ( UInt8.max, StdlibInt( 0xff)), + ( Int16.min, StdlibInt( -0x8000)), + ( Int16.max, StdlibInt( 0x7fff)), + (UInt16.min, StdlibInt( 0x0000)), + (UInt16.max, StdlibInt( 0xffff)), + ( Int32.min, StdlibInt( -0x80000000)), + ( Int32.max, StdlibInt( 0x7fffffff)), + (UInt32.min, StdlibInt( 0x00000000)), + (UInt32.max, StdlibInt( 0xffffffff)), + ( Int64.min, StdlibInt(-0x8000000000000000)), + ( Int64.max, StdlibInt( 0x7fffffffffffffff)), + (UInt64.min, StdlibInt( 0x0000000000000000)), + (UInt64.max, StdlibInt( 0xffffffffffffffff)), - ])) func initSwiftBinaryInteger( + ])) func initSwiftBinaryIntegerSamples( source: any Swift.BinaryInteger & Sendable, destination: StdlibInt ) throws { try Ɣrequire(source, is: destination) } @Test( - "StdlibInt/integes: init(some Swift.BinaryInteger)", + "StdlibInt/integers: init(_:)", Tag.List.tags(.forwarding, .random), arguments: fuzzers ) func initSwiftBinaryInteger( diff --git a/Tests/StdlibIntKitTests/StdlibInt+Literals.swift b/Tests/StdlibIntKitTests/StdlibInt+Literals.swift index c959cb60..4bddfd75 100644 --- a/Tests/StdlibIntKitTests/StdlibInt+Literals.swift +++ b/Tests/StdlibIntKitTests/StdlibInt+Literals.swift @@ -33,9 +33,9 @@ import TestKit //=------------------------------------------------------------------------= @Test( - "StdlibInt/literals: vs StdlibInt.Base", + "StdlibInt/literals: Self vs Base", Tag.List.tags(.forwarding), - arguments: [ + arguments: Array.infer([ StaticBigInt(-129), StaticBigInt(-128), @@ -79,8 +79,7 @@ import TestKit StaticBigInt( 57896044618658097711785492504343953926634992332820282019728792003956564819967), StaticBigInt( 57896044618658097711785492504343953926634992332820282019728792003956564819968), - ] as [StaticBigInt]) - func forwarding(_ literal: StaticBigInt) throws { + ])) func forwarding(literal: StaticBigInt) throws { typealias Base = IXL let base = Base.init(integerLiteral: literal) diff --git a/Tests/StdlibIntKitTests/StdlibInt+Multiplication.swift b/Tests/StdlibIntKitTests/StdlibInt+Multiplication.swift index e7997eaf..233c55e4 100644 --- a/Tests/StdlibIntKitTests/StdlibInt+Multiplication.swift +++ b/Tests/StdlibIntKitTests/StdlibInt+Multiplication.swift @@ -34,7 +34,7 @@ import TestKit //=------------------------------------------------------------------------= @Test( - "StdlibInt/multiplication: vs StdlibInt.Base", + "StdlibInt/multiplication: Self vs Base", Tag.List.tags(.forwarding, .random), arguments: fuzzers ) func forwarding(_ randomness: consuming FuzzerInt) throws { diff --git a/Tests/StdlibIntKitTests/StdlibInt+Shift.swift b/Tests/StdlibIntKitTests/StdlibInt+Shift.swift index df664282..c81a4969 100644 --- a/Tests/StdlibIntKitTests/StdlibInt+Shift.swift +++ b/Tests/StdlibIntKitTests/StdlibInt+Shift.swift @@ -33,8 +33,11 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("StdlibInt.<<(_:_:)", .tags(.forwarding, .random), arguments: fuzzers) - func shift(_ randomness: consuming FuzzerInt) throws { + @Test( + "StdlibInt/shift: bidirectional <<(_:_:) of Self vs Base", + Tag.List.tags(.forwarding, .random), + arguments: fuzzers + ) func shift(randomness: consuming FuzzerInt) throws { for _ in 0 ..< 128 { let random = IXL.entropic(size: 000256, using: &randomness) let distance = IXL.random(in: -128...127, using: &randomness) @@ -43,8 +46,10 @@ import TestKit } } - @Test("StdlibInt.<<(_:_:) - Int.max", .tags(.forwarding)) - func shiftByDistancesNearMaxInt() throws { + @Test( + "StdlibInt/shift: bidirectional <<(_:_:) near Int.max of Self vs Base", + Tag.List.tags(.forwarding) + ) func shiftByDistancesNearMaxInt() throws { try Ɣrequire(StdlibInt.zero, up: StdlibInt(Int.max) + 2, is: StdlibInt.zero) try Ɣrequire(StdlibInt.zero, up: StdlibInt(Int.max) + 1, is: StdlibInt.zero) try Ɣrequire(StdlibInt.zero, up: StdlibInt(Int.max), is: StdlibInt.zero) @@ -52,8 +57,11 @@ import TestKit try Ɣrequire(StdlibInt.zero, up: StdlibInt(Int.max) - 2, is: StdlibInt.zero) } - @Test("StdlibInt.<<(_:_:) - Int.min", .tags(.forwarding, .random), arguments: fuzzers) - func shiftByDistancesNearMinInt(_ randomness: consuming FuzzerInt) throws { + @Test( + "StdlibInt/shift: bidirectional <<(_:_:) near Int.min of Self vs Base", + Tag.List.tags(.forwarding, .random), + arguments: fuzzers + ) func shiftByDistancesNearMinInt(randomness: consuming FuzzerInt) throws { for _ in 0 ..< 32 { let random = StdlibInt(IXL.entropic(size: 256, using: &randomness)) let expectation = StdlibInt(IXL(repeating: Bit(random < 0))) @@ -65,10 +73,17 @@ import TestKit } } - func Ɣrequire(_ instance: StdlibInt, up distance: StdlibInt, is expectation: StdlibInt, at location: SourceLocation = #_sourceLocation) throws { - //=--------------------------------------= + //=------------------------------------------------------------------------= + // MARK: Utilities + //=------------------------------------------------------------------------= + + func Ɣrequire( + _ instance: StdlibInt, up distance: StdlibInt, is expectation: StdlibInt, + at location: SourceLocation = #_sourceLocation + ) throws { + let opposite: StdlibInt = -distance - //=--------------------------------------= + if instance != 0, distance >= 0 { try #require((instance.bitWidth + Int(distance)) == expectation.bitWidth, sourceLocation: location) } diff --git a/Tests/StdlibIntKitTests/StdlibInt+Stride.swift b/Tests/StdlibIntKitTests/StdlibInt+Stride.swift index ae2b0ceb..44a44fdd 100644 --- a/Tests/StdlibIntKitTests/StdlibInt+Stride.swift +++ b/Tests/StdlibIntKitTests/StdlibInt+Stride.swift @@ -33,8 +33,11 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("StdlibInt/stride: vs StdlibInt.Base", .tags(.forwarding, .random), arguments: fuzzers) - func forwarding(randomness: consuming FuzzerInt) throws { + @Test( + "StdlibInt/stride: Self vs Base", + Tag.List.tags(.forwarding, .random), + arguments: fuzzers + ) func forwarding(randomness: consuming FuzzerInt) throws { for _ in 0 ..< 256 { let start = IXL.entropic(through: Shift.max(or: 255), using: &randomness) let distance = IX .entropic(through: Shift.max(or: 255), using: &randomness) diff --git a/Tests/StdlibIntKitTests/StdlibInt+Words.swift b/Tests/StdlibIntKitTests/StdlibInt+Words.swift index 22fcb194..bb48f53b 100644 --- a/Tests/StdlibIntKitTests/StdlibInt+Words.swift +++ b/Tests/StdlibIntKitTests/StdlibInt+Words.swift @@ -8,6 +8,8 @@ //=----------------------------------------------------------------------------= import CoreKit +import InfiniIntKit +import RandomIntKit import StdlibIntKit import TestKit @@ -31,33 +33,37 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("StdlibInt.Words/subscript - is lenient") - func wordsSubscriptIsLenient() { - let x0 = StdlibInt( 1).words - let x1 = StdlibInt(-2).words + @Test( + "StdlibInt/words: subscript is lenient", + Tag.List.tags(.documentation, .random), + arguments: fuzzers + ) func subscriptIsLenient( + randomness: consuming FuzzerInt + ) throws { - always: do { - #expect(x0[0] == 1 as UInt) - #expect(x1[0] == ~1 as UInt) - } - - for i: Swift.Int in 1 ... 12 { - #expect(x0[i] == 0 as UInt) - #expect(x1[i] == ~0 as UInt) - } - - always: do { - #expect(x0[Int.max] == 0 as UInt) - #expect(x1[Int.max] == ~0 as UInt) + for _ in 0 ..< 8 { + let value = IXL.random(through: Shift.max(or: 255), using: &randomness) + let words = StdlibInt(((value))).words + let range = IX(words.count+1)...IX.max + + for _ in 0 ..< 8 { + let index = Swift.Int(IX.random(in: range, using: &randomness)) + let element = UX(repeating: value.appendix) + try #require(words[index] == UInt(element)) + } } } - @Test("StdlibInt.Words/subscript - traps negative indices", .disabled("req. exit tests")) - func wordsSubscriptTrapsNegativeIndices() { + @Test( + "StdlibInt/words: subscript traps negative indices", + ConditionTrait.disabled("req. exit tests") + ) func wordsSubscriptTrapsNegativeIndices() { } - @Test("StdlibInt.Words/description", arguments: [ + @Test( + "StdlibInt.words: description is an array", + arguments: Array<(words: [UInt], description: String)>.infer([ ([1 ] as [UInt], "[1]" ), ([1, 3 ] as [UInt], "[1, 3]" ), @@ -65,7 +71,7 @@ import TestKit ([1, 3, 5, 7 ] as [UInt], "[1, 3, 5, 7]" ), ([1, 3, 5, 7, 9] as [UInt], "[1, 3, 5, 7, 9]"), - ] as [(words: [UInt], description: String)]) func wordsTextIsArray(words: [UInt], description: String) { + ])) func descriptionIsAnArray(words: [UInt], description: String) { let instance: StdlibInt = words.reversed().reduce(into: 0) { $0 <<= UInt.bitWidth $0 |= StdlibInt($1) @@ -79,25 +85,28 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("StdlibInt/words [64-bit]", .disabled(if: UInt.bitWidth != 64), arguments: [ + @Test( + "StdlibInt/words: 64-bit", + ConditionTrait.disabled(if: UInt.bitWidth != 64), + arguments: Array<(StdlibInt, [UInt])>.infer([ - ( 0x00000000000000000000000000000000 as StdlibInt, [0x0000000000000000] as [UInt]), - ( 0x00000000000000000000000000000001 as StdlibInt, [0x0000000000000001] as [UInt]), - ( 0x00000000000000000706050403020100 as StdlibInt, [0x0706050403020100] as [UInt]), - ( 0x0f0e0d0c0b0a09080706050403020100 as StdlibInt, [0x0706050403020100, 0x0f0e0d0c0b0a0908] as [UInt]), - ( 0x7fffffffffffffffffffffffffffffff as StdlibInt, [0xffffffffffffffff, 0x7fffffffffffffff] as [UInt]), - ( 0x80000000000000000000000000000000 as StdlibInt, [0x0000000000000000, 0x8000000000000000, 0x0000000000000000] as [UInt]), - ( 0x80000000000000000000000000000001 as StdlibInt, [0x0000000000000001, 0x8000000000000000, 0x0000000000000000] as [UInt]), + (StdlibInt( 0x00000000000000000000000000000000), [0x0000000000000000] as [UInt]), + (StdlibInt( 0x00000000000000000000000000000001), [0x0000000000000001] as [UInt]), + (StdlibInt( 0x00000000000000000706050403020100), [0x0706050403020100] as [UInt]), + (StdlibInt( 0x0f0e0d0c0b0a09080706050403020100), [0x0706050403020100, 0x0f0e0d0c0b0a0908] as [UInt]), + (StdlibInt( 0x7fffffffffffffffffffffffffffffff), [0xffffffffffffffff, 0x7fffffffffffffff] as [UInt]), + (StdlibInt( 0x80000000000000000000000000000000), [0x0000000000000000, 0x8000000000000000, 0x0000000000000000] as [UInt]), + (StdlibInt( 0x80000000000000000000000000000001), [0x0000000000000001, 0x8000000000000000, 0x0000000000000000] as [UInt]), - (-0x00000000000000000000000000000000 as StdlibInt, [0x0000000000000000] as [UInt]), - (-0x00000000000000000000000000000001 as StdlibInt, [0xffffffffffffffff] as [UInt]), - (-0x00000000000000000706050403020100 as StdlibInt, [0xf8f9fafbfcfdff00] as [UInt]), - (-0x0f0e0d0c0b0a09080706050403020100 as StdlibInt, [0xf8f9fafbfcfdff00, 0xf0f1f2f3f4f5f6f7] as [UInt]), - (-0x7fffffffffffffffffffffffffffffff as StdlibInt, [0x0000000000000001, 0x8000000000000000] as [UInt]), - (-0x80000000000000000000000000000000 as StdlibInt, [0x0000000000000000, 0x8000000000000000] as [UInt]), - (-0x80000000000000000000000000000001 as StdlibInt, [0xffffffffffffffff, 0x7fffffffffffffff, 0xffffffffffffffff] as [UInt]), + (StdlibInt(-0x00000000000000000000000000000000), [0x0000000000000000] as [UInt]), + (StdlibInt(-0x00000000000000000000000000000001), [0xffffffffffffffff] as [UInt]), + (StdlibInt(-0x00000000000000000706050403020100), [0xf8f9fafbfcfdff00] as [UInt]), + (StdlibInt(-0x0f0e0d0c0b0a09080706050403020100), [0xf8f9fafbfcfdff00, 0xf0f1f2f3f4f5f6f7] as [UInt]), + (StdlibInt(-0x7fffffffffffffffffffffffffffffff), [0x0000000000000001, 0x8000000000000000] as [UInt]), + (StdlibInt(-0x80000000000000000000000000000000), [0x0000000000000000, 0x8000000000000000] as [UInt]), + (StdlibInt(-0x80000000000000000000000000000001), [0xffffffffffffffff, 0x7fffffffffffffff, 0xffffffffffffffff] as [UInt]), - ] as [(StdlibInt, [UInt])]) func words64(instance: StdlibInt, words: [UInt]) { + ])) func words64(instance: StdlibInt, words: [UInt]) { #expect(Array(instance.words) == words) } } diff --git a/Tests/StdlibIntKitTests/StdlibInt.swift b/Tests/StdlibIntKitTests/StdlibInt.swift index ea5a1db1..aac43c8b 100644 --- a/Tests/StdlibIntKitTests/StdlibInt.swift +++ b/Tests/StdlibIntKitTests/StdlibInt.swift @@ -33,15 +33,15 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("StdlibInt - metadata") + @Test("StdlibInt: metadata") func metadata() { #expect(StdlibInt.isSigned) #expect(StdlibInt.Magnitude.isSigned) } - @Test("StdlibInt.init(raw:) - [entropic]", arguments: fuzzers) + @Test("StdlibInt: init(raw:)", .tags(.random), arguments: fuzzers) func bitcasting(randomness: consuming FuzzerInt) { - for _ in 0 ..< 32 { + for _ in 0 ..< 8 { let random = StdlibInt(IXL.entropic(size: 256, using: &randomness)) #expect(StdlibInt(raw: IXL(raw: random)) == random) #expect(StdlibInt(raw: UXL(raw: random)) == random) diff --git a/Tests/UltimathnumTests/BinaryInteger+Addition.swift b/Tests/UltimathnumTests/BinaryInteger+Addition.swift index 66cff351..cab4a729 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Addition.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Addition.swift @@ -183,10 +183,12 @@ import TestKit "BinaryInteger/addition/edge-cases: additive inverse of T.min as signed is error", Tag.List.tags(.generic, .exhaustive), arguments: typesAsSystemsIntegerAsSigned - ) func additiveInverseOfMinValueAsSignedIsError(type: any SystemsIntegerAsSigned.Type) { - whereIs(type) + ) func additiveInverseOfMinValueAsSignedIsError( + type: any SystemsIntegerAsSigned.Type + ) throws { - func whereIs(_ type: T.Type) where T: SystemsIntegerAsSigned { + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: SystemsIntegerAsSigned { #expect(T.min.negated() == T.min.veto()) #expect(T.min.complement(true) == T.min.veto()) } @@ -196,10 +198,12 @@ import TestKit "BinaryInteger/addition/edge-cases: additive inverse of T.min as unsigned is not error", Tag.List.tags(.generic, .exhaustive), arguments: typesAsBinaryIntegerAsUnsigned - ) func additiveInverseOfMinValueAsUnsignedIsNotError(type: any UnsignedInteger.Type) { - whereIs(type) + ) func additiveInverseOfMinValueAsUnsignedIsNotError( + type: any UnsignedInteger.Type + ) throws { - func whereIs(_ type: T.Type) where T: UnsignedInteger { + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: UnsignedInteger { #expect(T.min.negated() == T.min.veto(false)) #expect(T.min.complement(true) == T.min.veto()) } @@ -223,7 +227,7 @@ import TestKit ) func additionOfZeroByRandom( type: any BinaryInteger.Type, randomness: consuming FuzzerInt ) throws { - + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 32 { diff --git a/Tests/UltimathnumTests/BinaryInteger+Bitwise.swift b/Tests/UltimathnumTests/BinaryInteger+Bitwise.swift index 0f8f3dae..086ed306 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Bitwise.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Bitwise.swift @@ -25,10 +25,10 @@ import TestKit "BinaryInteger/bitwise: from bit", Tag.List.tags(.generic, .exhaustive), arguments: typesAsBinaryInteger - ) func fromBit(type: any BinaryInteger.Type) { - whereIs(type) + ) func fromBit(type: any BinaryInteger.Type) throws { - func whereIs(_ type: T.Type) where T: BinaryInteger { + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: BinaryInteger { #expect(T(Bit.zero) == (0 as T)) #expect(T(Bit.one ) == (1 as T)) } @@ -38,10 +38,10 @@ import TestKit "BinaryInteger/bitwise: from repeating bit", Tag.List.tags(.generic, .exhaustive), arguments: typesAsBinaryInteger - ) func fromRepeatingBit(type: any BinaryInteger.Type) { - whereIs(type) + ) func fromRepeatingBit(type: any BinaryInteger.Type) throws { - func whereIs(_ type: T.Type) where T: BinaryInteger { + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: BinaryInteger { #expect(T(repeating: Bit.zero) == ( 0 as T)) #expect(T(repeating: Bit.one ) == (~0 as T)) } @@ -55,9 +55,11 @@ import TestKit "BinaryInteger/bitwise: least significant bit", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func lsb(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func lsb( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 4 { var value = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -79,9 +81,11 @@ import TestKit "BinaryInteger/bitwise: most significant bit", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func msb(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func msb( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 32 { let value = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -100,9 +104,11 @@ import TestKit "BinaryInteger/bitwise: NOT(x)", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func not(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func not( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< conditional(debug: 64,release: 256) { let a = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -118,9 +124,11 @@ import TestKit "BinaryInteger/bitwise: x AND y", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func and(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func and( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< conditional(debug: 64,release: 256) { let a = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -134,9 +142,11 @@ import TestKit "BinaryInteger/bitwise: x OR y", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func or(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func or( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< conditional(debug: 64,release: 256) { let a = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -150,9 +160,11 @@ import TestKit "BinaryInteger/bitwise: x XOR y", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func xor(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func xor( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< conditional(debug: 64,release: 256) { let a = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -193,9 +205,11 @@ import TestKit "BinaryInteger/bitwise: byte swapped", Tag.List.tags(.generic, .random), arguments: typesAsSystemsInteger, fuzzers - ) func byteSwapped(type: any SystemsInteger.Type, randomness: consuming FuzzerInt) throws { + ) func byteSwapped( + type: any SystemsInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: SystemsInteger { for _ in 0 ..< conditional(debug: 64,release: 256) { let a = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -219,9 +233,11 @@ import TestKit "BinaryInteger/bitwise: get/set bit at index", Tag.List.tags(.generic), arguments: typesAsSystemsInteger - ) func getSetBitAtIndex(type: any SystemsInteger.Type) throws { + ) func getSetBitAtIndex( + type: any SystemsInteger.Type + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: SystemsInteger { var result: T = T.zero var expectation = T.Magnitude.zero @@ -280,9 +296,11 @@ import TestKit "BinaryInteger/bitwise/conveniences: NOT(x)", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func not(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func not( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 64 { let a = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -300,9 +318,11 @@ import TestKit "BinaryInteger/bitwise/conveniences: x AND y", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func and(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func and( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 64 { let a = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -318,9 +338,11 @@ import TestKit "BinaryInteger/bitwise/conveniences: x OR y", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func or(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func or( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 64 { let a = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -336,9 +358,11 @@ import TestKit "BinaryInteger/bitwise/conveniences: x XOR y", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func xor(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func xor( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 64 { let a = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -358,9 +382,11 @@ import TestKit "BinaryInteger/bitwise: x.reversed(U8.self)", Tag.List.tags(.generic, .random), arguments: typesAsSystemsInteger, fuzzers - ) func reversed(type: any SystemsInteger.Type, randomness: consuming FuzzerInt) throws { + ) func reversed( + type: any SystemsInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: SystemsInteger { for _ in 0 ..< 64 { let a = T.entropic(through: Shift.max(or: 255), using: &randomness) diff --git a/Tests/UltimathnumTests/BinaryInteger+Clamping.swift b/Tests/UltimathnumTests/BinaryInteger+Clamping.swift index ca60e994..fbd620d0 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Clamping.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Clamping.swift @@ -25,16 +25,18 @@ import TestKit "BinaryInteger/clamping: comparisons as EdgyInteger", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func comparisonsAsEdgyInteger(randomness: consuming FuzzerInt) throws { - + ) func comparisonsAsEdgyInteger( + randomness: consuming FuzzerInt + ) throws { + for source in typesAsBinaryInteger { for destination in typesAsEdgyInteger { try whereIs(source: source, destination: destination) } } - func whereIs(source: A.Type, destination: B.Type) throws - where A: BinaryInteger, B: EdgyInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: BinaryInteger, B: EdgyInteger { try withOnlyOneCallToRequire((source, destination)) { require in for _ in 0 ..< 32 { let random = A.entropic(through: Shift.max(or: 255), using: &randomness) @@ -65,7 +67,9 @@ import TestKit "BinaryInteger/clamping/edge-cases: finite value as LenientInteger is argument", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func finiteValueAsLenientIntegerIsArgument(randomness: consuming FuzzerInt) throws { + ) func finiteValueAsLenientIntegerIsArgument( + randomness: consuming FuzzerInt + ) throws { for source in typesAsBinaryInteger { for destination in typesAsArbitraryIntegerAsSigned { @@ -73,8 +77,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws - where A: BinaryInteger, B: ArbitraryIntegerAsSigned { + func whereIs(source: A.Type, destination: B.Type) + throws where A: BinaryInteger, B: ArbitraryIntegerAsSigned { for _ in 0 ..< 32 { let random = A.entropic(through: Shift.max(or: 255), as: Domain.finite, using: &randomness) try #require(!random.isInfinite) @@ -92,7 +96,9 @@ import TestKit "BinaryInteger/clamping/edge-cases: negative value as UnsignedInteger is zero", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func negativeValueAsUnsignedIntegerIsZero(randomness: consuming FuzzerInt) throws { + ) func negativeValueAsUnsignedIntegerIsZero( + randomness: consuming FuzzerInt + ) throws { for source in typesAsBinaryIntegerAsSigned { for destination in typesAsBinaryIntegerAsUnsigned { @@ -100,8 +106,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws - where A: SignedInteger, B: UnsignedInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: SignedInteger, B: UnsignedInteger { for _ in 0 ..< 32 { let random = A.entropic(through: Shift.max(or: 255), as: Domain.natural, using: &randomness).toggled() try #require(random.isNegative) @@ -118,7 +124,9 @@ import TestKit "BinaryInteger/clamping/edge-cases: infinite value as SystemsInteger is max", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func infiniteValueAsSystemsIntegerIsMaxValue(randomness: consuming FuzzerInt) throws { + ) func infiniteValueAsSystemsIntegerIsMaxValue( + randomness: consuming FuzzerInt + ) throws { for source in typesAsArbitraryIntegerAsUnsigned { for destination in typesAsSystemsInteger { @@ -126,8 +134,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws - where A: ArbitraryIntegerAsUnsigned, B: SystemsInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: ArbitraryIntegerAsUnsigned, B: SystemsInteger { for _ in 0 ..< 32 { let random = A.entropic(size: 256, as: Domain.natural, using: &randomness).toggled() try #require(random.isInfinite) @@ -140,7 +148,9 @@ import TestKit "BinaryInteger/clamping/edge-cases: infinite value as LenientInteger is nil", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func infiniteValueAsLenientIntegerIsNil(randomness: consuming FuzzerInt) throws { + ) func infiniteValueAsLenientIntegerIsNil( + randomness: consuming FuzzerInt + ) throws { for source in typesAsArbitraryIntegerAsUnsigned { for destination in typesAsArbitraryIntegerAsSigned { @@ -148,8 +158,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws - where A: ArbitraryIntegerAsUnsigned, B: ArbitraryIntegerAsSigned { + func whereIs(source: A.Type, destination: B.Type) + throws where A: ArbitraryIntegerAsUnsigned, B: ArbitraryIntegerAsSigned { for _ in 0 ..< 32 { let random = A.entropic(size: 256, as: Domain.natural, using: &randomness).toggled() try #require(random.isInfinite) @@ -162,7 +172,9 @@ import TestKit "BinaryInteger/clamping/edge-cases: infinite value as MaximumInteger is argument", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func infiniteValueAsMaximumIntegerIsArgument(randomness: consuming FuzzerInt) throws { + ) func infiniteValueAsMaximumIntegerIsArgument( + randomness: consuming FuzzerInt + ) throws { for source in typesAsArbitraryIntegerAsUnsigned { for destination in typesAsArbitraryIntegerAsUnsigned { @@ -170,8 +182,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws - where A: ArbitraryIntegerAsUnsigned, B: ArbitraryIntegerAsUnsigned { + func whereIs(source: A.Type, destination: B.Type) + throws where A: ArbitraryIntegerAsUnsigned, B: ArbitraryIntegerAsUnsigned { for _ in 0 ..< 32 { let random = A.entropic(size: 256, as: Domain.natural, using: &randomness).toggled() try #require(random.isInfinite) @@ -195,7 +207,9 @@ import TestKit "BinaryInteger/clamping/conveniences: random FiniteInteger as BinaryInteger", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func randomFiniteIntegerAsBinaryInteger(randomness: consuming FuzzerInt) throws { + ) func randomFiniteIntegerAsBinaryInteger( + randomness: consuming FuzzerInt + ) throws { for source in typesAsFiniteInteger { for destination in typesAsBinaryInteger { @@ -203,7 +217,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws where A: FiniteInteger, B: BinaryInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: FiniteInteger, B: BinaryInteger { try withOnlyOneCallToRequire((source, destination)) { require in for _ in 0 ..< 32 { let finite = A.entropic(through: Shift.max(or: 255), using: &randomness) @@ -226,7 +241,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws where A: BinaryInteger, B: EdgyInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: BinaryInteger, B: EdgyInteger { try withOnlyOneCallToRequire((source, destination)) { require in for _ in 0 ..< 32 { let binary = A.entropic(through: Shift.max(or: 255), using: &randomness) diff --git a/Tests/UltimathnumTests/BinaryInteger+Comparison.swift b/Tests/UltimathnumTests/BinaryInteger+Comparison.swift index 8d3ec8c8..9c7e0140 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Comparison.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Comparison.swift @@ -22,18 +22,15 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - /// Here we check that the following invariants hold for all values: - /// - /// integer.hashValue == IXL(load: integer).hashValue - /// integer.hashValue == UXL(load: integer).hashValue - /// @Test( "BinaryInteger/comparison: hash value is type agnostic", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func hashValueIsTypeAgnostic(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func hashValueIsTypeAgnostic( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { try withOnlyOneCallToRequire(type) { require in for _ in 0 ..< conditional(debug: 64, release: 256) { @@ -54,14 +51,18 @@ import TestKit "BinaryInteger/comparison: x vs 0", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func comparisonVersusGenericZero(randomness: consuming FuzzerInt) throws { + ) func comparisonVersusGenericZero( + randomness: consuming FuzzerInt + ) throws { + for lhs in typesAsBinaryInteger { for rhs in typesAsBinaryInteger { try whereIs(lhs, rhs) } } - func whereIs(_ lhs: T.Type, _ rhs: U.Type) throws where T: BinaryInteger, U: BinaryInteger { + func whereIs(_ lhs: T.Type, _ rhs: U.Type) + throws where T: BinaryInteger, U: BinaryInteger { try withOnlyOneCallToRequire((lhs, rhs)) { require in for _ in 0 ..< conditional(debug: 16, release: 256) { let lhs = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -89,14 +90,18 @@ import TestKit "BinaryInteger/comparison: x vs x.elements", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func comparisonIsLikeDataIntegerComparison(randomness: consuming FuzzerInt) throws { + ) func comparisonIsLikeDataIntegerComparison( + randomness: consuming FuzzerInt + ) throws { + for lhs in typesAsBinaryInteger { for rhs in typesAsBinaryInteger { try whereIs(lhs, rhs) } } - func whereIs(_ lhs: T.Type, _ rhs: U.Type) throws where T: BinaryInteger, U: BinaryInteger { + func whereIs(_ lhs: T.Type, _ rhs: U.Type) + throws where T: BinaryInteger, U: BinaryInteger { try withOnlyOneCallToRequire((lhs, rhs)) { require in for _ in 0 ..< conditional(debug: 16, release: 256) { let lhs = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -120,8 +125,7 @@ import TestKit // MARK: * Binary Integer x Comparison x Edge Cases //*============================================================================* -@Suite(.tags(.documentation, .important), .serialized) -struct BinaryIntegerTestsOnComparisonEdgeCases { +@Suite(.serialized) struct BinaryIntegerTestsOnComparisonEdgeCases { //=------------------------------------------------------------------------= // MARK: Tests @@ -130,37 +134,40 @@ struct BinaryIntegerTestsOnComparisonEdgeCases { @Test( "BinaryInteger/comparison/edge-cases: ℕ vs ℕ", Tag.List.tags(.generic), - arguments: [ + arguments: Array<(I8, I8, Signum)>.infer([ - (lhs: 0 as I8, rhs: 0 as I8, expectation: Signum.zero), - (lhs: 0 as I8, rhs: 1 as I8, expectation: Signum.negative), - (lhs: 0 as I8, rhs: 2 as I8, expectation: Signum.negative), - (lhs: 0 as I8, rhs: 3 as I8, expectation: Signum.negative), + (0 as I8, 0 as I8, Signum.zero), + (0 as I8, 1 as I8, Signum.negative), + (0 as I8, 2 as I8, Signum.negative), + (0 as I8, 3 as I8, Signum.negative), - (lhs: 1 as I8, rhs: 0 as I8, expectation: Signum.positive), - (lhs: 1 as I8, rhs: 1 as I8, expectation: Signum.zero), - (lhs: 1 as I8, rhs: 2 as I8, expectation: Signum.negative), - (lhs: 1 as I8, rhs: 3 as I8, expectation: Signum.negative), + (1 as I8, 0 as I8, Signum.positive), + (1 as I8, 1 as I8, Signum.zero), + (1 as I8, 2 as I8, Signum.negative), + (1 as I8, 3 as I8, Signum.negative), - (lhs: 2 as I8, rhs: 0 as I8, expectation: Signum.positive), - (lhs: 2 as I8, rhs: 1 as I8, expectation: Signum.positive), - (lhs: 2 as I8, rhs: 2 as I8, expectation: Signum.zero), - (lhs: 2 as I8, rhs: 3 as I8, expectation: Signum.negative), + (2 as I8, 0 as I8, Signum.positive), + (2 as I8, 1 as I8, Signum.positive), + (2 as I8, 2 as I8, Signum.zero), + (2 as I8, 3 as I8, Signum.negative), - (lhs: 3 as I8, rhs: 0 as I8, expectation: Signum.positive), - (lhs: 3 as I8, rhs: 1 as I8, expectation: Signum.positive), - (lhs: 3 as I8, rhs: 2 as I8, expectation: Signum.positive), - (lhs: 3 as I8, rhs: 3 as I8, expectation: Signum.zero), + (3 as I8, 0 as I8, Signum.positive), + (3 as I8, 1 as I8, Signum.positive), + (3 as I8, 2 as I8, Signum.positive), + (3 as I8, 3 as I8, Signum.zero), - ] as [(lhs: I8, rhs: I8, expectation: Signum)]) - func comparisonOfNaturalVersusNatural(lhs: I8, rhs: I8, expectation: Signum) throws { + ])) func comparisonOfNaturalVersusNatural( + lhs: I8, rhs: I8, expectation: Signum + ) throws { + for lhs in typesAsBinaryInteger { for rhs in typesAsBinaryInteger { - whereIs(lhs, rhs) + try whereIs(lhs, rhs) } } - func whereIs(_ first: T.Type, _ second: U.Type) where T: BinaryInteger, U: BinaryInteger { + func whereIs(_ first: T.Type, _ second: U.Type) + throws where T: BinaryInteger, U: BinaryInteger { let lhs = T(load: lhs) let rhs = U(load: rhs) @@ -175,11 +182,12 @@ struct BinaryIntegerTestsOnComparisonEdgeCases { ) func comparisonOfNaturalVersusNegative(lhs: I8, rhs: I8) throws { for lhs in typesAsBinaryInteger { for rhs in typesAsBinaryIntegerAsSigned { - whereIs(lhs, rhs) + try whereIs(lhs, rhs) } } - func whereIs(_ first: T.Type, _ second: U.Type) where T: BinaryInteger, U: SignedInteger { + func whereIs(_ first: T.Type, _ second: U.Type) + throws where T: BinaryInteger, U: SignedInteger { let lhs = T(load: lhs) let rhs = U(load: rhs) @@ -195,11 +203,12 @@ struct BinaryIntegerTestsOnComparisonEdgeCases { ) func comparisonOfNaturalVersusInfinite(lhs: I8, rhs: I8) throws { for lhs in typesAsBinaryInteger { for rhs in typesAsArbitraryIntegerAsUnsigned { - whereIs(lhs, rhs) + try whereIs(lhs, rhs) } } - func whereIs(_ first: T.Type, _ second: U.Type) where T: BinaryInteger, U: UnsignedInteger { + func whereIs(_ first: T.Type, _ second: U.Type) + throws where T: BinaryInteger, U: UnsignedInteger { let lhs = T(load: lhs) let rhs = U(load: rhs) @@ -215,11 +224,12 @@ struct BinaryIntegerTestsOnComparisonEdgeCases { ) func comparisonOfNegativeVersusNegative(lhs: I8, rhs: I8) throws { for lhs in typesAsBinaryIntegerAsSigned { for rhs in typesAsBinaryIntegerAsSigned { - whereIs(lhs, rhs) + try whereIs(lhs, rhs) } } - func whereIs(_ first: T.Type, _ second: U.Type) where T: SignedInteger, U: SignedInteger { + func whereIs(_ first: T.Type, _ second: U.Type) + throws where T: SignedInteger, U: SignedInteger { let expectation = lhs.compared(to: rhs) let lhs = T(load: lhs) @@ -237,11 +247,12 @@ struct BinaryIntegerTestsOnComparisonEdgeCases { ) func comparisonOfNegativeVersusInfinite(lhs: I8, rhs: I8) throws { for lhs in typesAsBinaryIntegerAsSigned { for rhs in typesAsArbitraryIntegerAsUnsigned { - whereIs(lhs, rhs) + try whereIs(lhs, rhs) } } - func whereIs(_ first: T.Type, _ second: U.Type) where T: SignedInteger, U: UnsignedInteger { + func whereIs(_ first: T.Type, _ second: U.Type) + throws where T: SignedInteger, U: UnsignedInteger { let lhs = T(load: lhs) let rhs = U(load: rhs) @@ -257,11 +268,12 @@ struct BinaryIntegerTestsOnComparisonEdgeCases { ) func comparisonOfInfiniteVersusInfinite(lhs: I8, rhs: I8) throws { for lhs in typesAsArbitraryIntegerAsUnsigned { for rhs in typesAsArbitraryIntegerAsUnsigned { - whereIs(lhs, rhs) + try whereIs(lhs, rhs) } } - func whereIs(_ first: T.Type, _ second: U.Type) where T: UnsignedInteger, U: UnsignedInteger { + func whereIs(_ first: T.Type, _ second: U.Type) + throws where T: UnsignedInteger, U: UnsignedInteger { let expectation = lhs.compared(to: rhs) let lhs = T(load: lhs) @@ -280,14 +292,18 @@ struct BinaryIntegerTestsOnComparisonEdgeCases { "BinaryInteger/comparison/edge-cases: x vs x with one bit changed", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func comparisonOfRandomVersusSelfWithOneBitChanged(randomness: consuming FuzzerInt) throws { + ) func comparisonOfRandomVersusSelfWithOneBitChanged( + randomness: consuming FuzzerInt + ) throws { + for lhs in typesAsBinaryInteger { for rhs in typesAsBinaryInteger where lhs.mode == rhs.mode && lhs.size <= rhs.size { try whereIs(lhs, rhs) } } - func whereIs(_ first: T.Type, _ second: U.Type) throws where T: BinaryInteger, U: BinaryInteger { + func whereIs(_ first: T.Type, _ second: U.Type) + throws where T: BinaryInteger, U: BinaryInteger { for _ in 0 ..< conditional(debug: 16, release: 64) { let lhs = T.entropic(through: Shift.max(or: 255), using: &randomness) var expectation = Signum.zero @@ -314,14 +330,18 @@ struct BinaryIntegerTestsOnComparisonEdgeCases { "BinaryInteger/comparison/edge-cases: x vs y, different appendix", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func comparisonOfRandomVersusRandomWithDifferentAppendix(randomness: consuming FuzzerInt) throws { + ) func comparisonOfRandomVersusRandomWithDifferentAppendix( + randomness: consuming FuzzerInt + ) throws { + for lhs in typesAsBinaryInteger { for rhs in typesAsBinaryIntegerAsAppendix { try whereIs(lhs, rhs) } } - func whereIs(_ first: T.Type, _ second: U.Type) throws where T: BinaryInteger, U: BinaryInteger { + func whereIs(_ first: T.Type, _ second: U.Type) + throws where T: BinaryInteger, U: BinaryInteger { for _ in 0 ..< conditional(debug: 16, release: 64) { let lhs = T.entropic(through: Shift.max(or: 255), using: &randomness) var rhs = U.entropic(through: Shift.max(or: 255), using: &randomness) @@ -347,14 +367,18 @@ struct BinaryIntegerTestsOnComparisonEdgeCases { "BinaryInteger/comparison/edge-cases: x vs y, same signedness, same appendix, different normal byte count", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func comparisonOfRandomVersusRandomWithSameSignednessSameAppendixButDifferentNormalByteCount(randomness: consuming FuzzerInt) throws { + ) func comparisonOfRandomVersusRandomWithSameSignednessSameAppendixButDifferentNormalByteCount( + randomness: consuming FuzzerInt + ) throws { + for lhs in typesAsBinaryInteger { for rhs in typesAsBinaryInteger where lhs.mode == rhs.mode { try whereIs(lhs, rhs) } } - func whereIs(_ first: T.Type, _ second: U.Type) throws where T: BinaryInteger, U: BinaryInteger { + func whereIs(_ first: T.Type, _ second: U.Type) + throws where T: BinaryInteger, U: BinaryInteger { for _ in 0 ..< conditional(debug: 16, release: 64) { var lhs = T.entropic(through: Shift.max(or: 255), using: &randomness) var rhs = U.entropic(through: Shift.max(or: 255), using: &randomness) diff --git a/Tests/UltimathnumTests/BinaryInteger+Complement.swift b/Tests/UltimathnumTests/BinaryInteger+Complement.swift index c394c533..76e9453f 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Complement.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Complement.swift @@ -25,9 +25,11 @@ import TestKit "BinaryInteger/complement: magnitude", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func magnitude(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func magnitude( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< conditional(debug: 256, release: 1024) { let value = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -123,7 +125,7 @@ import TestKit // MARK: * Binary Integer x Complement x Edge Cases //*============================================================================* -@Suite(.tags(.documentation)) struct BinaryIntegerTestsOnComplementEdgeCases { +@Suite struct BinaryIntegerTestsOnComplementEdgeCases { //=------------------------------------------------------------------------= // MARK: Tests diff --git a/Tests/UltimathnumTests/BinaryInteger+Count.swift b/Tests/UltimathnumTests/BinaryInteger+Count.swift index 9dee1651..cf51ec0b 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Count.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Count.swift @@ -25,9 +25,11 @@ import TestKit "BinaryInteger/count: size", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func size(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func size( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< conditional(debug: 64, release: 256) { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -40,9 +42,11 @@ import TestKit "BinaryInteger/count: count", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func count(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func count( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< conditional(debug: 64, release: 256) { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -67,9 +71,11 @@ import TestKit "BinaryInteger/count: ascending", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func ascending(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func ascending( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< conditional(debug: 64, release: 256) { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -96,9 +102,11 @@ import TestKit "BinaryInteger/count: descending", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func descending(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func descending( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< conditional(debug: 64, release: 256) { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -143,9 +151,11 @@ import TestKit "BinaryInteger/count/conveniences: entropy", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func entropy(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func entropy( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 64 { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -161,9 +171,11 @@ import TestKit "BinaryInteger/count/conveniences: nonascending", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func nonascending(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func nonascending( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 64 { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -181,9 +193,11 @@ import TestKit "BinaryInteger/count/conveniences: nondescending", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func nondescending(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func nondescending( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 64 { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -212,9 +226,11 @@ import TestKit "BinaryInteger/count/edge-cases: systems integer is like data integer body", Tag.List.tags(.generic, .random), arguments: typesAsSystemsInteger, fuzzers - ) func systemsIntegerIsLikeDataIntegerBody(type: any SystemsInteger.Type, randomness: consuming FuzzerInt) throws { + ) func systemsIntegerIsLikeDataIntegerBody( + type: any SystemsInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: SystemsInteger { for _ in 0 ..< 64 { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -289,9 +305,11 @@ import TestKit "BinaryInteger/count/edge-cases: arbitrary integer is like data integer elements", Tag.List.tags(.generic, .random), arguments: typesAsArbitraryInteger, fuzzers - ) func arbitraryIntegerIsLikeDataIntegerElements(type: any ArbitraryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func arbitraryIntegerIsLikeDataIntegerElements( + type: any ArbitraryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: ArbitraryInteger { for _ in 0 ..< 64 { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) diff --git a/Tests/UltimathnumTests/BinaryInteger+Division.swift.swift b/Tests/UltimathnumTests/BinaryInteger+Division.swift.swift index e4046bb2..6ee085f3 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Division.swift.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Division.swift.swift @@ -27,7 +27,7 @@ import TestKit "BinaryInteger/division: signs", Tag.List.tags(.documentation, .generic), ParallelizationTrait.serialized, - arguments: Array<(I8, I8, I8, I8)>([ + arguments: Array<(I8, I8, I8, I8)>.infer([ ( 7 as I8, 3 as I8, 2 as I8, 1 as I8), ( 7 as I8, -3 as I8, -2 as I8, 1 as I8), @@ -941,10 +941,10 @@ import TestKit //=------------------------------------------------------------------------= @Test( - "BinaryInteger/division/open-source: issues", + "BinaryInteger/division/open-source: non-issues", Tag.List.tags(.generic, .opensource), ParallelizationTrait.serialized, - arguments: Array<(IXL, IXL, IXL, IXL, String)>([ + arguments: Array<(IXL, IXL, IXL, IXL, String)>.infer([ ( dividend: IXL(3) << 96, divisor: IXL(2) << 96, @@ -982,7 +982,7 @@ import TestKit remainder: IXL("000000000000000000000000000000000000000016136758413064865246015978698186666775")!, source: "https://github.com/oscbyspro/Numberick/issues/101" ), - ])) func issues( + ])) func nonissues( dividend: IXL, divisor: IXL, quotient: IXL, remainder: IXL, source: String ) throws { diff --git a/Tests/UltimathnumTests/BinaryInteger+Elements.swift b/Tests/UltimathnumTests/BinaryInteger+Elements.swift index 0f42560b..2e03a207 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Elements.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Elements.swift @@ -28,8 +28,7 @@ import TestKit Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers ) func systemsIsLikeInitLoadOrNil( - type: any BinaryInteger.Type, - randomness: consuming FuzzerInt + type: any BinaryInteger.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) @@ -60,8 +59,7 @@ import TestKit Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers ) func arbitraryIsLikeInitLoadOrNil( - type: any BinaryInteger.Type, - randomness: consuming FuzzerInt + type: any BinaryInteger.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) @@ -132,8 +130,7 @@ import TestKit Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers ) func arbitraryWhereCountIsInvalidIsNil( - type: any BinaryInteger.Type, - randomness: consuming FuzzerInt + type: any BinaryInteger.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) diff --git a/Tests/UltimathnumTests/BinaryInteger+Exponentiation.swift b/Tests/UltimathnumTests/BinaryInteger+Exponentiation.swift index 1daa1e7a..36dff1ee 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Exponentiation.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Exponentiation.swift @@ -27,7 +27,7 @@ import TestKit @Test( "BinaryInteger/exponentiation: examples", Tag.List.tags(.generic), - arguments: [ + arguments: Array<(IXL, UXL, IXL)>.infer([ (base: 2 as IXL, exponent: 1399 as UXL, power: IXL(""" 0000000000000000000000000013834514851379060073245971093437442064\ @@ -59,8 +59,7 @@ import TestKit 6036250169540192297202679456092601217013126286587177412655204267 """)!), - ] as [(base: IXL, exponent: UXL, power: IXL)]) - func examples(base: IXL, exponent: UXL, power: IXL) throws { + ])) func examples(base: IXL, exponent: UXL, power: IXL) throws { for type in typesAsBinaryInteger { try whereIs(type) } @@ -76,9 +75,11 @@ import TestKit "BinaryInteger/exponentiation: vs multiplication loop for small exponents", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func exponentiationVersusMultiplicationLoopForSmallExponents(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func exponentiationVersusMultiplicationLoopForSmallExponents( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { let size = IX(size: T.self) ?? conditional(debug: 32, release: 256) @@ -123,8 +124,8 @@ import TestKit Tag.List.tags(.generic), arguments: typesAsBinaryInteger ) func coefficientIsOneByDefault(type: any BinaryInteger.Type) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { try #require(I8(2).power(U8(3)) == Fallible(I8(8))) try #require(U8(2).power(U8(3)) == Fallible(U8(8))) @@ -137,9 +138,11 @@ import TestKit "BinaryInteger/exponentiation/conveniences: exponent as SystemsInteger.Magnitude vs UXL", Tag.List.tags(.generic, .random), arguments: typesAsSystemsInteger, fuzzers - ) func exponentAsSystemsIntegerMagnitudeVersusUXL(type: any SystemsInteger.Type, randomness: consuming FuzzerInt) throws { + ) func exponentAsSystemsIntegerMagnitudeVersusUXL( + type: any SystemsInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: SystemsInteger { typealias M = T.Magnitude @@ -169,9 +172,11 @@ import TestKit "BinaryInteger/exponentiation/edge-cases: base is 1 → coefficient", Tag.List.tags(.documentation, .generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func baseIsOneYieldsCoefficient(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func baseIsOneYieldsCoefficient( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { typealias M = T.Magnitude @@ -187,9 +192,11 @@ import TestKit "BinaryInteger/exponentiation/edge-cases: base is 0 → 0 or coefficient", Tag.List.tags(.documentation, .generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func baseIsZeroYieldsZeroOrCoefficient(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func baseIsZeroYieldsZeroOrCoefficient( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { typealias M = T.Magnitude @@ -207,9 +214,11 @@ import TestKit "BinaryInteger/exponentiation/edge-cases: base is NOT(0) → coefficient * (1 or ~0)", Tag.List.tags(.documentation, .generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func baseIsRepeatingOnesYieldsCoefficietExpression(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func baseIsRepeatingOnesYieldsCoefficietExpression( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { typealias M = T.Magnitude @@ -227,9 +236,11 @@ import TestKit "BinaryInteger/exponentiation/edge-cases: exponent is 0 → coefficient", Tag.List.tags(.documentation, .generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func exponentIsZeroYieldsCoefficientNoError(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func exponentIsZeroYieldsCoefficientNoError( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 32 { let a = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -243,9 +254,11 @@ import TestKit "BinaryInteger/exponentiation/edge-cases: coefficient is 0 → 0", Tag.List.tags(.documentation, .generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func coefficientIsZeroYieldsZeroNoError(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func coefficientIsZeroYieldsZeroNoError( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 32 { let a = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -263,14 +276,18 @@ import TestKit "BinaryInteger/exponentiation/edge-cases: exponent > Magnitude.max", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func exponentsThatDontFitInMagnitude(randomness: consuming FuzzerInt) throws { + ) func exponentsThatDontFitInMagnitude( + randomness: consuming FuzzerInt + ) throws { + for small in typesAsSystemsInteger { for large in typesAsSystemsInteger { try whereIs(small: small, large: large) } } - func whereIs(small: A.Type, large: B.Type) throws where A: SystemsInteger, B: SystemsInteger { + func whereIs(small: A.Type, large: B.Type) + throws where A: SystemsInteger, B: SystemsInteger { guard A.size < B.size, A.isSigned == B.isSigned else { return } let min = B.Magnitude(A.Magnitude.max) + 1 diff --git a/Tests/UltimathnumTests/BinaryInteger+Factorial.swift b/Tests/UltimathnumTests/BinaryInteger+Factorial.swift index 37ddc1a0..91966f84 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Factorial.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Factorial.swift @@ -23,44 +23,45 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("BinaryInteger/factorial: element at small natural index", arguments: [ + @Test( + "BinaryInteger/factorial: element at small natural index", + arguments: Array<(U8, IXL)>.infer([ - (index: 0 as U8, element: 1 as IXL), - (index: 1 as U8, element: 1 as IXL), - (index: 2 as U8, element: 2 as IXL), - (index: 3 as U8, element: 6 as IXL), - (index: 4 as U8, element: 24 as IXL), - (index: 5 as U8, element: 120 as IXL), - (index: 6 as U8, element: 720 as IXL), - (index: 7 as U8, element: 5040 as IXL), - (index: 8 as U8, element: 40320 as IXL), - (index: 9 as U8, element: 362880 as IXL), - (index: 10 as U8, element: 3628800 as IXL), - (index: 11 as U8, element: 39916800 as IXL), - (index: 12 as U8, element: 479001600 as IXL), - (index: 13 as U8, element: 6227020800 as IXL), - (index: 14 as U8, element: 87178291200 as IXL), - (index: 15 as U8, element: 1307674368000 as IXL), - (index: 16 as U8, element: 20922789888000 as IXL), - (index: 17 as U8, element: 355687428096000 as IXL), - (index: 18 as U8, element: 6402373705728000 as IXL), - (index: 19 as U8, element: 121645100408832000 as IXL), - (index: 20 as U8, element: 2432902008176640000 as IXL), - (index: 21 as U8, element: 51090942171709440000 as IXL), - (index: 22 as U8, element: 1124000727777607680000 as IXL), - (index: 23 as U8, element: 25852016738884976640000 as IXL), - (index: 24 as U8, element: 620448401733239439360000 as IXL), - (index: 25 as U8, element: 15511210043330985984000000 as IXL), - (index: 26 as U8, element: 403291461126605635584000000 as IXL), - (index: 27 as U8, element: 10888869450418352160768000000 as IXL), - (index: 28 as U8, element: 304888344611713860501504000000 as IXL), - (index: 29 as U8, element: 8841761993739701954543616000000 as IXL), - (index: 30 as U8, element: 265252859812191058636308480000000 as IXL), - (index: 31 as U8, element: 8222838654177922817725562880000000 as IXL), - (index: 32 as U8, element: 263130836933693530167218012160000000 as IXL), + (U8( 0), IXL( 1)), + (U8( 1), IXL( 1)), + (U8( 2), IXL( 2)), + (U8( 3), IXL( 6)), + (U8( 4), IXL( 24)), + (U8( 5), IXL( 120)), + (U8( 6), IXL( 720)), + (U8( 7), IXL( 5040)), + (U8( 8), IXL( 40320)), + (U8( 9), IXL( 362880)), + (U8(10), IXL( 3628800)), + (U8(11), IXL( 39916800)), + (U8(12), IXL( 479001600)), + (U8(13), IXL( 6227020800)), + (U8(14), IXL( 87178291200)), + (U8(15), IXL( 1307674368000)), + (U8(16), IXL( 20922789888000)), + (U8(17), IXL( 355687428096000)), + (U8(18), IXL( 6402373705728000)), + (U8(19), IXL( 121645100408832000)), + (U8(20), IXL( 2432902008176640000)), + (U8(21), IXL( 51090942171709440000)), + (U8(22), IXL( 1124000727777607680000)), + (U8(23), IXL( 25852016738884976640000)), + (U8(24), IXL( 620448401733239439360000)), + (U8(25), IXL( 15511210043330985984000000)), + (U8(26), IXL( 403291461126605635584000000)), + (U8(27), IXL( 10888869450418352160768000000)), + (U8(28), IXL( 304888344611713860501504000000)), + (U8(29), IXL( 8841761993739701954543616000000)), + (U8(30), IXL( 265252859812191058636308480000000)), + (U8(31), IXL( 8222838654177922817725562880000000)), + (U8(32), IXL(263130836933693530167218012160000000)), - ] as [(index: U8, element: IXL)]) - func elementAtSmallNaturalIndex(index: U8, element: IXL) throws { + ])) func elementAtSmallNaturalIndex(index: U8, element: IXL) throws { for type in typesAsBinaryInteger { whereIs(type) } @@ -80,9 +81,11 @@ import TestKit /// - Seealso: https://www.wolframalpha.com/input?i=1000%21 /// - Seealso: https://www.wolframalpha.com/input?i=1024%21 - @Test("BinaryInteger/factorial: element at large natural index", arguments: [ + @Test( + "BinaryInteger/factorial: element at large natural index", + arguments: Array<(IXL, IXL)>.infer([ - (index: IXL(1000), element: IXL(""" + (IXL(1000), IXL(""" 0000000000000000000000000000000000000000000000000000000040238726\ 0077093773543702433923003985719374864210714632543799910429938512\ 3986290205920442084869694048004799886101971960586316668729948085\ @@ -126,7 +129,7 @@ import TestKit 0000000000000000000000000000000000000000000000000000000000000000 """)!), - (index: IXL(1024), element: IXL(""" + (IXL(1024), IXL(""" 0000000000000000000000000000000000000000000000005418528796058857\ 2830769219446838547380015539635380134444828702706832106120733766\ 0373314098413621458671907918845708980753931994165770187368260454\ @@ -171,26 +174,25 @@ import TestKit 0000000000000000000000000000000000000000000000000000000000000000 """)!), - ] as [(index: IXL, element: IXL)]) - func elementAtLargeNaturalIndex(index: IXL, element: IXL) { + ])) func elementAtLargeNaturalIndex(index: IXL, element: IXL) throws { for type in typesAsSystemsInteger { - whereIs(type) + try whereIs(type) } for type in typesAsSystemsIntegerAsUnsigned { - whereIsUnsigned(type) + try whereIsUnsigned(type) } - whereIs(IXL.self) - whereIs(UXL.self) - whereIsUnsigned(UXL.self) + try whereIs(IXL.self) + try whereIs(UXL.self) + try whereIsUnsigned(UXL.self) - func whereIs(_ type: T.Type) where T: BinaryInteger { - #expect(T(clamping: index).factorial() as Optional == T.exactly(element)) + func whereIs(_ type: T.Type) throws where T: BinaryInteger { + try #require(T(clamping: index).factorial() as Optional == T.exactly(element)) } - func whereIsUnsigned(_ type: T.Type) where T: UnsignedInteger { - #expect(T(clamping: index).factorial() as Fallible == T.exactly(element)) + func whereIsUnsigned(_ type: T.Type) throws where T: UnsignedInteger { + try #require(T(clamping: index).factorial() as Fallible == T.exactly(element)) } } } @@ -199,7 +201,7 @@ import TestKit // MARK: * Binary Integer x Factorial x Edge Cases //*============================================================================* -@Suite(.tags(.documentation)) struct BinaryIntegerTestsOnFactorialEdgeCases { +@Suite struct BinaryIntegerTestsOnFactorialEdgeCases { //=------------------------------------------------------------------------= // MARK: Tests @@ -210,8 +212,7 @@ import TestKit Tag.List.tags(.random), arguments: typesAsBinaryIntegerAsSigned, fuzzers ) func elementAtNegativeIndexIsNil( - type: any SignedInteger.Type, - randomness: consuming FuzzerInt + type: any SignedInteger.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) @@ -236,8 +237,7 @@ import TestKit Tag.List.tags(.random), arguments: typesAsArbitraryIntegerAsUnsigned, fuzzers ) func elementAtInfiniteIndexIsZeroWithError( - type: any ArbitraryIntegerAsUnsigned.Type, - randomness: consuming FuzzerInt + type: any ArbitraryIntegerAsUnsigned.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) @@ -273,8 +273,7 @@ import TestKit Tag.List.tags(.generic, .random), arguments: typesAsBinaryIntegerAsUnsigned, fuzzers ) func elementIsNeverNilAsUnsignedInteger( - type: any UnsignedInteger.Type, - randomness: consuming FuzzerInt + type: any UnsignedInteger.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) @@ -295,8 +294,7 @@ import TestKit Tag.List.tags(.generic, .random), arguments: typesAsArbitraryIntegerAsSigned, fuzzers ) func elementIsNeverLossyAsLenientInteger( - type: any ArbitraryIntegerAsSigned.Type, - randomness: consuming FuzzerInt + type: any ArbitraryIntegerAsSigned.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) diff --git a/Tests/UltimathnumTests/BinaryInteger+Factorization.swift b/Tests/UltimathnumTests/BinaryInteger+Factorization.swift index 843bd15c..9929fd6b 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Factorization.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Factorization.swift @@ -87,9 +87,11 @@ import TestKit "BinaryInteger/factorization: GCD(a, b) vs prime multiplication", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func greatestCommonDivisorVersusPrimeMultiplication(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func greatestCommonDivisorVersusPrimeMultiplication( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { let primes = primes54.compactMap{T.exactly($0).optional()} for _ in 0 ..< conditional(debug: 16, release: 64) { @@ -151,9 +153,11 @@ import TestKit "BinaryInteger/factorization/edge-cases: GCD(x, ∞) == nil", Tag.List.tags(.generic, .random), arguments: typesAsArbitraryIntegerAsUnsigned, fuzzers - ) func greatestCommonDivisorOfInfiniteIsNil(type: any ArbitraryIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws { + ) func greatestCommonDivisorOfInfiniteIsNil( + type: any ArbitraryIntegerAsUnsigned.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: ArbitraryIntegerAsUnsigned { for _ in 0 ..< 32 { let a = T.entropic(through: Shift.max(or: 127), as: Domain.finite, using: &randomness) @@ -176,9 +180,11 @@ import TestKit "BinaryInteger/factorization/edge-cases: GCD(x, x) == |x|", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func greatestCommonDivisorOfDuplicateIsMagnitude(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func greatestCommonDivisorOfDuplicateIsMagnitude( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 32 { let random = T.entropic(through: Shift.max(or: 127), as: Domain.finite, using: &randomness) @@ -194,9 +200,11 @@ import TestKit "BinaryInteger/factorization/edge-cases: GCD(x, 0) == |x|", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func greatestCommonDivisorOfZeroAndOtherIsMagnitudeOfOther(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func greatestCommonDivisorOfZeroAndOtherIsMagnitudeOfOther( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 32 { let random = T.entropic(through: Shift.max(or: 127), as: Domain.finite, using: &randomness) @@ -215,9 +223,11 @@ import TestKit "BinaryInteger/factorization/edge-cases: GCD(x, 1) == 1", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func greatestCommonDivisorOfOneAndOtherIsOne(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func greatestCommonDivisorOfOneAndOtherIsOne( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 32 { let random = T.entropic(through: Shift.max(or: 127), as: Domain.finite, using: &randomness) @@ -236,9 +246,11 @@ import TestKit "BinaryInteger/factorization/edge-cases: GCD(a, b) == GCD(b, a)", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func greatestCommonDivisorIsCommutative(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func greatestCommonDivisorIsCommutative( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 32 { let lhs = T.entropic(through: Shift.max(or: 127), as: Domain.finite, using: &randomness) @@ -254,9 +266,11 @@ import TestKit "BinaryInteger/factorization/edge-cases: GCD(a, b) == GCD(±a, ±b)", Tag.List.tags(.generic, .random), arguments: typesAsBinaryIntegerAsSigned, fuzzers - ) func greatestCommonDivisorIsSignAgnostic(type: any SignedInteger.Type, randomness: consuming FuzzerInt) throws { + ) func greatestCommonDivisorIsSignAgnostic( + type: any SignedInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: SignedInteger { for _ in 0 ..< 32 { let lhs = T.entropic(through: Shift.max(or: 127), using: &randomness) @@ -272,9 +286,11 @@ import TestKit "BinaryInteger/factorization/edge-cases: GCD(a, b) == GCD(a, b % a)", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func greatestCommonDivisorRemainderInvariant(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func greatestCommonDivisorRemainderInvariant( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 8 { let lhs = T.entropic(through: Shift.max(or: 127), as: Domain.finite, using: &randomness) @@ -304,9 +320,11 @@ import TestKit "BinaryInteger/factorization/edge-cases: bezout(_:) as Finite", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func bezoutAsFinite(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func bezoutAsFinite( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 4 { let lhs = T.entropic(through: Shift.max(or: 127), as: Domain.finite, using: &randomness) @@ -321,9 +339,11 @@ import TestKit "BinaryInteger/factorization/edge-cases: bezout(_:) as FiniteInteger", Tag.List.tags(.generic, .random), arguments: typesAsFiniteInteger, fuzzers - ) func bezoutAsFiniteInteger(type: any FiniteInteger.Type, randomness: consuming FuzzerInt) throws { + ) func bezoutAsFiniteInteger( + type: any FiniteInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: FiniteInteger { for _ in 0 ..< 4 { let lhs = T.entropic(through: Shift.max(or: 127), using: &randomness) @@ -338,9 +358,11 @@ import TestKit "BinaryInteger/factorization/edge-cases: euclidean(_:) as Finite", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func greatestCommonDivisorAsFinite(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func greatestCommonDivisorAsFinite( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 4 { let lhs = T.entropic(through: Shift.max(or: 127), as: Domain.finite, using: &randomness) @@ -355,9 +377,11 @@ import TestKit "BinaryInteger/factorization/edge-cases: euclidean(_:) as FiniteInteger", Tag.List.tags(.generic, .random), arguments: typesAsFiniteInteger, fuzzers - ) func greatestCommonDivisorAsFiniteInteger(type: any FiniteInteger.Type, randomness: consuming FuzzerInt) throws { + ) func greatestCommonDivisorAsFiniteInteger( + type: any FiniteInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: FiniteInteger { for _ in 0 ..< 4 { let lhs = T.entropic(through: Shift.max(or: 127), using: &randomness) diff --git a/Tests/UltimathnumTests/BinaryInteger+Fibonacci.swift b/Tests/UltimathnumTests/BinaryInteger+Fibonacci.swift index 7f218329..f38d201a 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Fibonacci.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Fibonacci.swift @@ -25,24 +25,25 @@ import TestKit /// - Seealso: https://www.wolframalpha.com/input?i=fibonacci%281000%29 /// - Seealso: https://www.wolframalpha.com/input?i=fibonacci%281024%29 - @Test("BinaryInteger/fibonacci: element at large natural index", arguments: [ + @Test( + "BinaryInteger/fibonacci: element at large natural index", + arguments: Array<(IXL, IXL)>.infer([ - (index: IXL(1000), element: IXL(""" + (IXL(1000), IXL(""" 0000000000000000000000000000000000000000000000043466557686937456\ 4356885276750406258025646605173717804024817290895365554179490518\ 9040387984007925516929592259308032263477520968962323987332247116\ 1642996440906533187938298969649928516003704476137795166849228875 """)!), - (index: IXL(1024), element: IXL(""" + (IXL(1024), IXL(""" 0000000000000000000000000000000000000000004506699633677819813104\ 3832357288860493678605962186048308030231496000306457087213962487\ 9260914103039624487326658034501121953020936742558101987106764609\ 4200262285202346655868899711089246778413354004103631553925405243 """)!), - ] as [(index: IXL, element: IXL)]) - func elementAtLargeNaturalIndex(index: IXL, element: IXL) throws { + ])) func elementAtLargeNaturalIndex(index: IXL, element: IXL) throws { for type in typesAsBinaryInteger { try whereIs(type) } diff --git a/Tests/UltimathnumTests/BinaryInteger+Floats.swift b/Tests/UltimathnumTests/BinaryInteger+Floats.swift index 15575a05..1e8361da 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Floats.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Floats.swift @@ -16,7 +16,7 @@ import TestKit // MARK: * Binary Integer x Floats x Samples //*============================================================================* -@Suite(.serialized, .tags(.generic)) struct BinaryIntegerTestsOnFloatsSamples { +@Suite(.serialized) struct BinaryIntegerTestsOnFloatsSamples { //=------------------------------------------------------------------------= // MARK: Metadata @@ -119,16 +119,20 @@ import TestKit @Test( "BinaryInteger/floats/samples: none", + Tag.List.tags(.generic), arguments: Self.nonresults - ) func nonresults(float: Float64) throws { + ) func nonresults( + float: Float64 + ) throws { + for source in typesAsSwiftBinaryFloatingPoint { for destination in typesAsBinaryInteger { try whereIs(source: source, destination: destination) } } - func whereIs(source: A.Type, destination: B.Type) throws - where A: Swift.BinaryFloatingPoint, B: BinaryInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: Swift.BinaryFloatingPoint, B: BinaryInteger { if let source = A(exactly: float) { try Ɣrequire(source,is: Optional>.none) } @@ -137,16 +141,20 @@ import TestKit @Test( "BinaryInteger/floats/samples: integers", + Tag.List.tags(.generic), arguments: Self.integers - ) func integers(float: Float64, integer: IXL) throws { + ) func integers( + float: Float64, integer: IXL + ) throws { + for source in typesAsSwiftBinaryFloatingPoint { for destination in typesAsBinaryInteger { try whereIs(source: source, destination: destination) } } - func whereIs(source: A.Type, destination: B.Type) throws - where A: Swift.BinaryFloatingPoint, B: BinaryInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: Swift.BinaryFloatingPoint, B: BinaryInteger { if let source = A(exactly: float) { try Ɣrequire(source,is: integer.veto(false), as: B.self) } @@ -155,16 +163,20 @@ import TestKit @Test( "BinaryInteger/floats/samples: integers but one fractional step away from zero", + Tag.List.tags(.generic), arguments: Self.integersButOneFractionalStepAwayFromZero - ) func integersButOneFractionalStepAwayFromZero(float: Float64, integer: Fallible) throws { + ) func integersButOneFractionalStepAwayFromZero( + float: Float64, integer: Fallible + ) throws { + for source in typesAsSwiftBinaryFloatingPoint { for destination in typesAsBinaryInteger { try whereIs(source: source, destination: destination) } } - func whereIs(source: A.Type, destination: B.Type) throws - where A: Swift.BinaryFloatingPoint, B: BinaryInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: Swift.BinaryFloatingPoint, B: BinaryInteger { if let source = A(exactly: float) { try Ɣrequire(source,is: integer, as: B.self) } @@ -174,15 +186,18 @@ import TestKit @Test( "BinaryInteger/floats/samples: integers but one fractional step towards zero", arguments: Self.integersButOneFractionalStepTowardsZero - ) func integersButOneFractionalStepTowardsZero(float: Float64, integer: Fallible) throws { + ) func integersButOneFractionalStepTowardsZero( + float: Float64, integer: Fallible + ) throws { + for source in typesAsSwiftBinaryFloatingPoint { for destination in typesAsBinaryInteger { try whereIs(source: source, destination: destination) } } - func whereIs(source: A.Type, destination: B.Type) throws - where A: Swift.BinaryFloatingPoint, B: BinaryInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: Swift.BinaryFloatingPoint, B: BinaryInteger { if let source = A(exactly: float) { try Ɣrequire(source,is: integer, as: B.self) } @@ -231,7 +246,9 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test func fromPureExponentFloats() throws { + @Test( + "BinaryInteger/floats/generators: from pure exponent floats" + ) func fromPureExponentFloats() throws { for source in typesAsSwiftBinaryFloatingPoint { for destination in typesAsBinaryInteger { try whereIs(source: source, destination: destination) @@ -281,7 +298,9 @@ import TestKit /// 1111111111111111111111111111111111111111111111111110110011000011 → /// 1111111111111111111111111111111111111111111111111111110011000011 → /// - @Test func fromLargeNegativeFloats() throws { + @Test( + "BinaryInteger/floats/generators: from large negative floats" + ) func fromLargeNegativeFloats() throws { for source in typesAsSwiftBinaryFloatingPoint { try whereIs(source: source, destination: InfiniInt.self) try whereIs(source: source, destination: InfiniInt.self) @@ -330,7 +349,12 @@ import TestKit /// 0110000000000000000000000000000000000000000000000000110011000011 → /// 1110000000000000000000000000000000000000000000000000110011000011 → /// - @Test func fromLargeNegativeFloatsNearMinSignificandBitPattern() throws { + @Test( + """ + BinaryInteger/floats/generators: \ + from large negative floats near min significand bit pattern" + """ + ) func fromLargeNegativeFloatsNearMinSignificandBitPattern() throws { for source in typesAsSwiftBinaryFloatingPoint { try whereIs(source: source, destination: InfiniInt.self) try whereIs(source: source, destination: InfiniInt.self) @@ -378,7 +402,12 @@ import TestKit /// 1001111111111111111111111111111111111111111111111111110011000011 → /// 0001111111111111111111111111111111111111111111111111110011000011 → /// - @Test func fromLargeNegativeFloatsNearMaxSignificandBitPattern() throws { + @Test( + """ + BinaryInteger/floats/generators: \ + from large negative floats near max significand bit pattern" + """ + ) func fromLargeNegativeFloatsNearMaxSignificandBitPattern() throws { for source in typesAsSwiftBinaryFloatingPoint { try whereIs(source: source, destination: InfiniInt.self) try whereIs(source: source, destination: InfiniInt.self) @@ -427,7 +456,9 @@ import TestKit /// 1111111111111111111111111111111111111111111111111110110011000010 → /// 1111111111111111111111111111111111111111111111111111110011000010 → /// - @Test func fromLargePositiveFloats() throws { + @Test( + "BinaryInteger/floats/generators: from large positive floats" + ) func fromLargePositiveFloats() throws { for source in typesAsSwiftBinaryFloatingPoint { try whereIs(source: source, destination: InfiniInt.self) try whereIs(source: source, destination: InfiniInt.self) @@ -476,7 +507,12 @@ import TestKit /// 0110000000000000000000000000000000000000000000000000110011000010 → /// 1110000000000000000000000000000000000000000000000000110011000010 → /// - @Test func fromLargePositiveFloatsNearMinSignificandBitPattern() throws { + @Test( + """ + BinaryInteger/floats/generators: \ + from large positive floats near min significand bit pattern" + """ + ) func fromLargePositiveFloatsNearMinSignificandBitPattern() throws { for source in typesAsSwiftBinaryFloatingPoint { try whereIs(source: source, destination: InfiniInt.self) try whereIs(source: source, destination: InfiniInt.self) @@ -524,7 +560,12 @@ import TestKit /// 1001111111111111111111111111111111111111111111111111110011000010 → /// 0001111111111111111111111111111111111111111111111111110011000010 → /// - @Test func fromLargePositiveFloatsNearMaxSignificandBitPattern() throws { + @Test( + """ + BinaryInteger/floats/generators: \ + from large positive floats near max significand bit pattern" + """ + ) func fromLargePositiveFloatsNearMaxSignificandBitPattern() throws { for source in typesAsSwiftBinaryFloatingPoint { try whereIs(source: source, destination: InfiniInt.self) try whereIs(source: source, destination: InfiniInt.self) diff --git a/Tests/UltimathnumTests/BinaryInteger+Geometry.swift b/Tests/UltimathnumTests/BinaryInteger+Geometry.swift index fe9590f5..88eb1c43 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Geometry.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Geometry.swift @@ -25,26 +25,26 @@ import TestKit "BinaryInteger/geometry: √(x) of examples", Tag.List.tags(.documentation, .generic), ParallelizationTrait.serialized, - arguments: Array<(I8, I8?)>([ + arguments: Array<(I8, I8?)>.infer([ - (value: I8(-1), isqrt: I8?(nil)), - (value: I8( 0), isqrt: I8?( 0)), - (value: I8( 1), isqrt: I8?( 1)), - (value: I8( 2), isqrt: I8?( 1)), - (value: I8( 3), isqrt: I8?( 1)), - (value: I8( 4), isqrt: I8?( 2)), - (value: I8( 5), isqrt: I8?( 2)), - (value: I8( 6), isqrt: I8?( 2)), - (value: I8( 7), isqrt: I8?( 2)), - (value: I8( 8), isqrt: I8?( 2)), - (value: I8( 9), isqrt: I8?( 3)), - (value: I8(10), isqrt: I8?( 3)), - (value: I8(11), isqrt: I8?( 3)), - (value: I8(12), isqrt: I8?( 3)), - (value: I8(13), isqrt: I8?( 3)), - (value: I8(14), isqrt: I8?( 3)), - (value: I8(15), isqrt: I8?( 3)), - (value: I8(16), isqrt: I8?( 4)), + (I8(-1), I8?(nil)), + (I8( 0), I8?( 0)), + (I8( 1), I8?( 1)), + (I8( 2), I8?( 1)), + (I8( 3), I8?( 1)), + (I8( 4), I8?( 2)), + (I8( 5), I8?( 2)), + (I8( 6), I8?( 2)), + (I8( 7), I8?( 2)), + (I8( 8), I8?( 2)), + (I8( 9), I8?( 3)), + (I8(10), I8?( 3)), + (I8(11), I8?( 3)), + (I8(12), I8?( 3)), + (I8(13), I8?( 3)), + (I8(14), I8?( 3)), + (I8(15), I8?( 3)), + (I8(16), I8?( 4)), ])) func integerSquareRootOfExampels(value: I8, isqrt: I8?) throws { for type in typesAsBinaryInteger { diff --git a/Tests/UltimathnumTests/BinaryInteger+Integers.swift b/Tests/UltimathnumTests/BinaryInteger+Integers.swift index 732e1914..8e58bbb9 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Integers.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Integers.swift @@ -32,7 +32,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws where A: BinaryInteger, B: BinaryInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: BinaryInteger, B: BinaryInteger { try withOnlyOneCallToRequire((source, destination)) { require in for _ in 0 ..< conditional(debug: 32, release: 256) { let source: A = A.entropic(in: B.self,or: 255, using: &randomness) @@ -80,7 +81,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws where A: BinaryInteger, B: BinaryInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: BinaryInteger, B: BinaryInteger { try withOnlyOneCallToRequire((source, destination)) { require in let size = IX(size: B.self) ?? (1 + 256) let min: B = B(repeating: Bit(B.isSigned)).up(Count(size - 1)) @@ -160,7 +162,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws where A: UnsignedInteger, B: BinaryInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: UnsignedInteger, B: BinaryInteger { for sign in Sign.all { try #require(B(sign: sign, magnitude: A.Magnitude.zero).isZero) } @@ -296,7 +299,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws where A: UnsignedInteger, B: BinaryInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: UnsignedInteger, B: BinaryInteger { for _ in 0 ..< 8 { let value = A.entropic(in: B.self, or: 256, using: &randomness) try #require( value == A(magnitude: value)) @@ -423,7 +427,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws where A: BinaryInteger, B: BinaryInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: BinaryInteger, B: BinaryInteger { try withOnlyOneCallToRequire((source, destination)) { require in var a = A.zero, x = A.lsb var b = B.zero, y = B.lsb @@ -467,7 +472,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws where A: BinaryInteger, B: BinaryInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: BinaryInteger, B: BinaryInteger { try withOnlyOneCallToRequire((source, destination)) { require in var mask = B(repeating: Bit.one) @@ -524,7 +530,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws where A: BinaryInteger, B: BinaryInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: BinaryInteger, B: BinaryInteger { try withOnlyOneCallToRequire((source, destination)) { require in var mask = B(repeating: Bit.one) @@ -592,7 +599,8 @@ import TestKit } } - func whereIs(source: A.Type, destination: B.Type) throws where A: BinaryInteger, B: BinaryInteger { + func whereIs(source: A.Type, destination: B.Type) + throws where A: BinaryInteger, B: BinaryInteger { try withOnlyOneCallToRequire((source, destination)) { require in let mask = B(load: A.Magnitude(repeating: Bit.one)) diff --git a/Tests/UltimathnumTests/BinaryInteger+Literals.swift b/Tests/UltimathnumTests/BinaryInteger+Literals.swift index 996df808..240460ea 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Literals.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Literals.swift @@ -36,7 +36,7 @@ import TestKit @Test( "BinaryInteger/literals: from LiteralInt near zero", Tag.List.tags(.generic), - arguments: [ + arguments: Array<(LiteralInt, IXL)>.infer([ (LiteralInt(-4), IXL.zero - 4), (LiteralInt(-3), IXL.zero - 3), @@ -47,8 +47,10 @@ import TestKit (LiteralInt( 2), IXL.zero + 2), (LiteralInt( 3), IXL.zero + 3), - ] as [(LiteralInt, IXL)]) - func fromLiteralIntNearZero(literal: LiteralInt, expectation: IXL) throws { + ])) func fromLiteralIntNearZero( + literal: LiteralInt, expectation: IXL + ) throws { + for type in typesAsBinaryInteger { try whereIs(type) } @@ -61,7 +63,7 @@ import TestKit @Test( "BinaryInteger/literals: from LiteralInt near edges of signed", Tag.List.tags(.generic), - arguments: [ + arguments: Array<(LiteralInt, IXL)>.infer([ (LiteralInt(-129), IXL(I8.min) - 1), (LiteralInt(-128), IXL(I8.min) ), @@ -91,22 +93,24 @@ import TestKit (LiteralInt( 9223372036854775807), IXL(I64.max) ), (LiteralInt( 9223372036854775808), IXL(I64.max) + 1), - (LiteralInt(-170141183460469231731687303715884105729), BinaryIntegerTestsOnLiterals.minI128 - 1), - (LiteralInt(-170141183460469231731687303715884105728), BinaryIntegerTestsOnLiterals.minI128 ), - (LiteralInt(-170141183460469231731687303715884105727), BinaryIntegerTestsOnLiterals.minI128 + 1), - (LiteralInt( 170141183460469231731687303715884105726), BinaryIntegerTestsOnLiterals.maxI128 - 1), - (LiteralInt( 170141183460469231731687303715884105727), BinaryIntegerTestsOnLiterals.maxI128 ), - (LiteralInt( 170141183460469231731687303715884105728), BinaryIntegerTestsOnLiterals.maxI128 + 1), + (LiteralInt(-170141183460469231731687303715884105729), Self.minI128 - 1), + (LiteralInt(-170141183460469231731687303715884105728), Self.minI128 ), + (LiteralInt(-170141183460469231731687303715884105727), Self.minI128 + 1), + (LiteralInt( 170141183460469231731687303715884105726), Self.maxI128 - 1), + (LiteralInt( 170141183460469231731687303715884105727), Self.maxI128 ), + (LiteralInt( 170141183460469231731687303715884105728), Self.maxI128 + 1), - (LiteralInt(-57896044618658097711785492504343953926634992332820282019728792003956564819969), BinaryIntegerTestsOnLiterals.minI256 - 1), - (LiteralInt(-57896044618658097711785492504343953926634992332820282019728792003956564819968), BinaryIntegerTestsOnLiterals.minI256 ), - (LiteralInt(-57896044618658097711785492504343953926634992332820282019728792003956564819967), BinaryIntegerTestsOnLiterals.minI256 + 1), - (LiteralInt( 57896044618658097711785492504343953926634992332820282019728792003956564819966), BinaryIntegerTestsOnLiterals.maxI256 - 1), - (LiteralInt( 57896044618658097711785492504343953926634992332820282019728792003956564819967), BinaryIntegerTestsOnLiterals.maxI256 ), - (LiteralInt( 57896044618658097711785492504343953926634992332820282019728792003956564819968), BinaryIntegerTestsOnLiterals.maxI256 + 1), + (LiteralInt(-57896044618658097711785492504343953926634992332820282019728792003956564819969), Self.minI256 - 1), + (LiteralInt(-57896044618658097711785492504343953926634992332820282019728792003956564819968), Self.minI256 ), + (LiteralInt(-57896044618658097711785492504343953926634992332820282019728792003956564819967), Self.minI256 + 1), + (LiteralInt( 57896044618658097711785492504343953926634992332820282019728792003956564819966), Self.maxI256 - 1), + (LiteralInt( 57896044618658097711785492504343953926634992332820282019728792003956564819967), Self.maxI256 ), + (LiteralInt( 57896044618658097711785492504343953926634992332820282019728792003956564819968), Self.maxI256 + 1), - ] as [(LiteralInt, IXL)]) - func fromLiteralIntNearEdgesOfSignedIntegers(literal: LiteralInt, expectation: IXL) throws { + ])) func fromLiteralIntNearEdgesOfSignedIntegers( + literal: LiteralInt, expectation: IXL + ) throws { + for type in typesAsBinaryInteger { try whereIs(type) } @@ -119,7 +123,7 @@ import TestKit @Test( "BinaryInteger/literals: from LiteralInt near size edges of unsigned", Tag.List.tags(.generic), - arguments: [ + arguments: Array<(LiteralInt, IXL)>.infer([ (LiteralInt( 254), IXL(U8.max) - 1), (LiteralInt( 255), IXL(U8.max) ), @@ -137,16 +141,18 @@ import TestKit (LiteralInt( 18446744073709551615), IXL(U64.max) ), (LiteralInt( 18446744073709551616), IXL(U64.max) + 1), - (LiteralInt( 340282366920938463463374607431768211454), BinaryIntegerTestsOnLiterals.maxU128 - 1), - (LiteralInt( 340282366920938463463374607431768211455), BinaryIntegerTestsOnLiterals.maxU128 ), - (LiteralInt( 340282366920938463463374607431768211456), BinaryIntegerTestsOnLiterals.maxU128 + 1), + (LiteralInt( 340282366920938463463374607431768211454), Self.maxU128 - 1), + (LiteralInt( 340282366920938463463374607431768211455), Self.maxU128 ), + (LiteralInt( 340282366920938463463374607431768211456), Self.maxU128 + 1), - (LiteralInt( 115792089237316195423570985008687907853269984665640564039457584007913129639934), BinaryIntegerTestsOnLiterals.maxU256 - 1), - (LiteralInt( 115792089237316195423570985008687907853269984665640564039457584007913129639935), BinaryIntegerTestsOnLiterals.maxU256 ), - (LiteralInt( 115792089237316195423570985008687907853269984665640564039457584007913129639936), BinaryIntegerTestsOnLiterals.maxU256 + 1), + (LiteralInt( 115792089237316195423570985008687907853269984665640564039457584007913129639934), Self.maxU256 - 1), + (LiteralInt( 115792089237316195423570985008687907853269984665640564039457584007913129639935), Self.maxU256 ), + (LiteralInt( 115792089237316195423570985008687907853269984665640564039457584007913129639936), Self.maxU256 + 1), - ] as [(LiteralInt, IXL)]) - func fromLiteralIntNearSizeEdgesOfUnsigned(literal: LiteralInt, expectation: IXL) throws { + ])) func fromLiteralIntNearSizeEdgesOfUnsigned( + literal: LiteralInt, expectation: IXL + ) throws { + for type in typesAsBinaryInteger { try whereIs(type) } @@ -179,10 +185,10 @@ import TestKit "BinaryInteger/literals/edge-cases: generic type inference", Tag.List.tags(.generic, .important), arguments: typesAsArbitraryInteger - ) func genericTypeInference(type: any ArbitraryInteger.Type) { - whereIs(type) + ) func genericTypeInference(type: any ArbitraryInteger.Type) throws { - func whereIs(_ type: T.Type) where T: BinaryInteger { + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: BinaryInteger { let expectation = T.init(BinaryIntegerTestsOnLiterals.maxI256) let a: T = (57896044618658097711785492504343953926634992332820282019728792003956564819967) diff --git a/Tests/UltimathnumTests/BinaryInteger+Loading.swift b/Tests/UltimathnumTests/BinaryInteger+Loading.swift index 6e431591..5e9a8d38 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Loading.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Loading.swift @@ -36,8 +36,7 @@ import TestKit Tag.List.tags(.forwarding, .generic, .random), arguments: typesAsBinaryInteger, fuzzers ) func randomPayloadExtensionJunk( - type: any BinaryInteger.Type, - randomness: consuming FuzzerInt + type: any BinaryInteger.Type, randomness: consuming FuzzerInt ) throws { for element in typesAsSystemsIntegerAsUnsigned { @@ -123,11 +122,9 @@ import TestKit } } - func Ɣrequire( - _ integer: Integer, - matches body: Body, - repeating appendix: Bit - ) throws where Integer: BinaryInteger, Body: Contiguous, Body.Element: SystemsIntegerAsUnsigned { + func Ɣrequire( + _ integer: Integer, matches body: Body, repeating appendix: Bit + ) throws where Body.Element: SystemsIntegerAsUnsigned { try withOnlyOneCallToRequire((integer, body)) { require in integer.withUnsafeBinaryIntegerElements(as: U8.self) { integer in require(integer.appendix == appendix) @@ -153,8 +150,9 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("BinaryInteger/loading/conveniences: default appendix is zero") - func defaultAppendixIsZero() { + @Test( + "BinaryInteger/loading/conveniences: default appendix is zero" + ) func defaultAppendixIsZero() { #expect(IX(load: [] as [U8]) == IX.zero) #expect(UX(load: [] as [U8]) == UX.zero) } @@ -171,7 +169,7 @@ import TestKit //=------------------------------------------------------------------------= @Test( - "BinaryInteger/loading/disambiguation: { IX, UX } from T where T.Element is { IX, UX }" + "BinaryInteger/loading/disambiguation: ?X from T where T.Element is ?X" ) func tokenFromBinaryIntegerWhereElementIsToken() { let ix = IX.random() diff --git a/Tests/UltimathnumTests/BinaryInteger+Logarithm.swift b/Tests/UltimathnumTests/BinaryInteger+Logarithm.swift index 254e0449..a24f86b7 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Logarithm.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Logarithm.swift @@ -25,7 +25,7 @@ import TestKit "BinaryInteger/logarithm: ilog2() of examples", Tag.List.tags(.documentation, .generic), ParallelizationTrait.serialized, - arguments: Array<(I8, Count?)>([ + arguments: Array<(I8, Count?)>.infer([ (value: -1 as I8, ilog2: nil), (value: 0 as I8, ilog2: nil), diff --git a/Tests/UltimathnumTests/BinaryInteger+Metadata.swift b/Tests/UltimathnumTests/BinaryInteger+Metadata.swift index ff9e171c..c66e90ee 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Metadata.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Metadata.swift @@ -22,21 +22,27 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("BinaryInteger - mode", arguments: typesAsBinaryInteger) - func modes(type: any BinaryInteger.Type) { - whereIs(type) + @Test( + "BinaryInteger/metadata: mode", + Tag.List.tags(.generic), + arguments: typesAsBinaryInteger + ) func modes(type: any BinaryInteger.Type) throws { - func whereIs(_ type: T.Type) where T: BinaryInteger { + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: BinaryInteger { #expect( T.isSigned == (T.mode == Signedness .signed)) #expect(!T.isSigned == (T.mode == Signedness.unsigned)) } } - @Test("BinaryInteger - size", arguments: typesAsBinaryInteger) - func sizes(type: any BinaryInteger.Type) { - whereIs(type) + @Test( + "BinaryInteger/metadata: size", + Tag.List.tags(.generic), + arguments: typesAsBinaryInteger + ) func sizes(type: any BinaryInteger.Type) throws { - func whereIs(_ type: T.Type) where T: BinaryInteger { + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: BinaryInteger { #expect(T.size.isPowerOf2) #expect(T.size >= T.Element .size) #expect(T.size == T.Magnitude.size) @@ -58,11 +64,14 @@ import TestKit } } - @Test("BinaryInteger - quadrants", arguments: typesAsBinaryInteger) - func quadrants(type: any BinaryInteger.Type) { - whereIs(type) + @Test( + "BinaryInteger/metadata: quadrants", + Tag.List.tags(.generic), + arguments: typesAsBinaryInteger + ) func quadrants(type: any BinaryInteger.Type) throws { - func whereIs(_ type: T.Type) where T: BinaryInteger { + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: BinaryInteger { #expect( T.isArbitrary == (T.self is any ArbitraryInteger.Type)) #expect(!T.isArbitrary == (T.self is any SystemsInteger.Type)) #expect( T.isEdgy == (T.self is any EdgyInteger.Type)) diff --git a/Tests/UltimathnumTests/BinaryInteger+Multiplication.swift b/Tests/UltimathnumTests/BinaryInteger+Multiplication.swift index 38a24d04..6834f667 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Multiplication.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Multiplication.swift @@ -26,53 +26,51 @@ import TestKit "BinaryInteger/multiplication: 1-by-1-as-2 for low entropies as signed", Tag.List.tags(.generic), ParallelizationTrait.serialized, - arguments: [ + arguments: Array<(I8, I8, I8, I8)>.infer([ - (lhs: ~2 as I8, rhs: ~2 as I8, low: 9 as I8, high: 0 as I8), - (lhs: ~2 as I8, rhs: ~1 as I8, low: 6 as I8, high: 0 as I8), - (lhs: ~2 as I8, rhs: ~0 as I8, low: 3 as I8, high: 0 as I8), - (lhs: ~2 as I8, rhs: 0 as I8, low: 0 as I8, high: 0 as I8), - (lhs: ~2 as I8, rhs: 1 as I8, low: ~2 as I8, high: ~0 as I8), - (lhs: ~2 as I8, rhs: 2 as I8, low: ~5 as I8, high: ~0 as I8), - - (lhs: ~1 as I8, rhs: ~2 as I8, low: 6 as I8, high: 0 as I8), - (lhs: ~1 as I8, rhs: ~1 as I8, low: 4 as I8, high: 0 as I8), - (lhs: ~1 as I8, rhs: ~0 as I8, low: 2 as I8, high: 0 as I8), - (lhs: ~1 as I8, rhs: 0 as I8, low: 0 as I8, high: 0 as I8), - (lhs: ~1 as I8, rhs: 1 as I8, low: ~1 as I8, high: ~0 as I8), - (lhs: ~1 as I8, rhs: 2 as I8, low: ~3 as I8, high: ~0 as I8), - - (lhs: ~0 as I8, rhs: ~2 as I8, low: 3 as I8, high: 0 as I8), - (lhs: ~0 as I8, rhs: ~1 as I8, low: 2 as I8, high: 0 as I8), - (lhs: ~0 as I8, rhs: ~0 as I8, low: 1 as I8, high: 0 as I8), - (lhs: ~0 as I8, rhs: 0 as I8, low: 0 as I8, high: 0 as I8), - (lhs: ~0 as I8, rhs: 1 as I8, low: ~0 as I8, high: ~0 as I8), - (lhs: ~0 as I8, rhs: 2 as I8, low: ~1 as I8, high: ~0 as I8), - - (lhs: 0 as I8, rhs: ~2 as I8, low: 0 as I8, high: 0 as I8), - (lhs: 0 as I8, rhs: ~1 as I8, low: 0 as I8, high: 0 as I8), - (lhs: 0 as I8, rhs: ~0 as I8, low: 0 as I8, high: 0 as I8), - (lhs: 0 as I8, rhs: 0 as I8, low: 0 as I8, high: 0 as I8), - (lhs: 0 as I8, rhs: 1 as I8, low: 0 as I8, high: 0 as I8), - (lhs: 0 as I8, rhs: 2 as I8, low: 0 as I8, high: 0 as I8), - - (lhs: 1 as I8, rhs: ~2 as I8, low: ~2 as I8, high: ~0 as I8), - (lhs: 1 as I8, rhs: ~1 as I8, low: ~1 as I8, high: ~0 as I8), - (lhs: 1 as I8, rhs: ~0 as I8, low: ~0 as I8, high: ~0 as I8), - (lhs: 1 as I8, rhs: 0 as I8, low: 0 as I8, high: 0 as I8), - (lhs: 1 as I8, rhs: 1 as I8, low: 1 as I8, high: 0 as I8), - (lhs: 1 as I8, rhs: 2 as I8, low: 2 as I8, high: 0 as I8), - - (lhs: 2 as I8, rhs: ~2 as I8, low: ~5 as I8, high: ~0 as I8), - (lhs: 2 as I8, rhs: ~1 as I8, low: ~3 as I8, high: ~0 as I8), - (lhs: 2 as I8, rhs: ~0 as I8, low: ~1 as I8, high: ~0 as I8), - (lhs: 2 as I8, rhs: 0 as I8, low: 0 as I8, high: 0 as I8), - (lhs: 2 as I8, rhs: 1 as I8, low: 2 as I8, high: 0 as I8), - (lhs: 2 as I8, rhs: 2 as I8, low: 4 as I8, high: 0 as I8), + (I8(~2), I8(~2), I8( 9), I8( 0)), + (I8(~2), I8(~1), I8( 6), I8( 0)), + (I8(~2), I8(~0), I8( 3), I8( 0)), + (I8(~2), I8( 0), I8( 0), I8( 0)), + (I8(~2), I8( 1), I8(~2), I8(~0)), + (I8(~2), I8( 2), I8(~5), I8(~0)), - ] as [( - lhs: I8, rhs: I8, low: I8, high: I8 - )]) func someLowEntropiesAsFullWidthAsSigned( + (I8(~1), I8(~2), I8( 6), I8( 0)), + (I8(~1), I8(~1), I8( 4), I8( 0)), + (I8(~1), I8(~0), I8( 2), I8( 0)), + (I8(~1), I8( 0), I8( 0), I8( 0)), + (I8(~1), I8( 1), I8(~1), I8(~0)), + (I8(~1), I8( 2), I8(~3), I8(~0)), + + (I8(~0), I8(~2), I8( 3), I8( 0)), + (I8(~0), I8(~1), I8( 2), I8( 0)), + (I8(~0), I8(~0), I8( 1), I8( 0)), + (I8(~0), I8( 0), I8( 0), I8( 0)), + (I8(~0), I8( 1), I8(~0), I8(~0)), + (I8(~0), I8( 2), I8(~1), I8(~0)), + + (I8( 0), I8(~2), I8( 0), I8( 0)), + (I8( 0), I8(~1), I8( 0), I8( 0)), + (I8( 0), I8(~0), I8( 0), I8( 0)), + (I8( 0), I8( 0), I8( 0), I8( 0)), + (I8( 0), I8( 1), I8( 0), I8( 0)), + (I8( 0), I8( 2), I8( 0), I8( 0)), + + (I8( 1), I8(~2), I8(~2), I8(~0)), + (I8( 1), I8(~1), I8(~1), I8(~0)), + (I8( 1), I8(~0), I8(~0), I8(~0)), + (I8( 1), I8( 0), I8( 0), I8( 0)), + (I8( 1), I8( 1), I8( 1), I8( 0)), + (I8( 1), I8( 2), I8( 2), I8( 0)), + + (I8( 2), I8(~2), I8(~5), I8(~0)), + (I8( 2), I8(~1), I8(~3), I8(~0)), + (I8( 2), I8(~0), I8(~1), I8(~0)), + (I8( 2), I8( 0), I8( 0), I8( 0)), + (I8( 2), I8( 1), I8( 2), I8( 0)), + (I8( 2), I8( 2), I8( 4), I8( 0)), + + ])) func someLowEntropiesAsFullWidthAsSigned( lhs: I8, rhs: I8, low: I8, high: I8 ) throws { @@ -95,48 +93,46 @@ import TestKit "BinaryInteger/multiplication: 1-by-1-as-2 for low entropies as unsigned", Tag.List.tags(.generic), ParallelizationTrait.serialized, - arguments: [ - - (lhs: ~5 as I8, rhs: ~5 as I8, low: 36 as I8, high: ~11 as I8, error: true ), - (lhs: ~5 as I8, rhs: ~4 as I8, low: 30 as I8, high: ~10 as I8, error: true ), - (lhs: ~5 as I8, rhs: ~3 as I8, low: 24 as I8, high: ~9 as I8, error: true ), - (lhs: ~5 as I8, rhs: ~2 as I8, low: 18 as I8, high: ~8 as I8, error: true ), - (lhs: ~5 as I8, rhs: ~1 as I8, low: 12 as I8, high: ~7 as I8, error: true ), - (lhs: ~5 as I8, rhs: ~0 as I8, low: 6 as I8, high: ~6 as I8, error: true ), - (lhs: ~5 as I8, rhs: 0 as I8, low: 0 as I8, high: 0 as I8, error: false), - (lhs: ~5 as I8, rhs: 1 as I8, low: ~5 as I8, high: 0 as I8, error: false), - (lhs: ~5 as I8, rhs: 2 as I8, low: ~11 as I8, high: 1 as I8, error: true ), - (lhs: ~5 as I8, rhs: 3 as I8, low: ~17 as I8, high: 2 as I8, error: true ), - (lhs: ~5 as I8, rhs: 4 as I8, low: ~23 as I8, high: 3 as I8, error: true ), - (lhs: ~5 as I8, rhs: 5 as I8, low: ~29 as I8, high: 4 as I8, error: true ), + arguments: Array<(I8, I8, I8, I8, Bool)>.infer([ - (lhs: 0 as I8, rhs: ~5 as I8, low: 0 as I8, high: 0 as I8, error: false), - (lhs: 0 as I8, rhs: ~3 as I8, low: 0 as I8, high: 0 as I8, error: false), - (lhs: 0 as I8, rhs: ~2 as I8, low: 0 as I8, high: 0 as I8, error: false), - (lhs: 0 as I8, rhs: ~1 as I8, low: 0 as I8, high: 0 as I8, error: false), - (lhs: 0 as I8, rhs: ~0 as I8, low: 0 as I8, high: 0 as I8, error: false), - (lhs: 0 as I8, rhs: 0 as I8, low: 0 as I8, high: 0 as I8, error: false), - (lhs: 0 as I8, rhs: 1 as I8, low: 0 as I8, high: 0 as I8, error: false), - (lhs: 0 as I8, rhs: 2 as I8, low: 0 as I8, high: 0 as I8, error: false), - (lhs: 0 as I8, rhs: 4 as I8, low: 0 as I8, high: 0 as I8, error: false), - (lhs: 0 as I8, rhs: 5 as I8, low: 0 as I8, high: 0 as I8, error: false), - - (lhs: 5 as I8, rhs: ~5 as I8, low: ~29 as I8, high: 4 as I8, error: true ), - (lhs: 5 as I8, rhs: ~4 as I8, low: ~24 as I8, high: 4 as I8, error: true ), - (lhs: 5 as I8, rhs: ~3 as I8, low: ~19 as I8, high: 4 as I8, error: true ), - (lhs: 5 as I8, rhs: ~2 as I8, low: ~14 as I8, high: 4 as I8, error: true ), - (lhs: 5 as I8, rhs: ~1 as I8, low: ~9 as I8, high: 4 as I8, error: true ), - (lhs: 5 as I8, rhs: ~0 as I8, low: ~4 as I8, high: 4 as I8, error: true ), - (lhs: 5 as I8, rhs: 0 as I8, low: 0 as I8, high: 0 as I8, error: false), - (lhs: 5 as I8, rhs: 1 as I8, low: 5 as I8, high: 0 as I8, error: false), - (lhs: 5 as I8, rhs: 2 as I8, low: 10 as I8, high: 0 as I8, error: false), - (lhs: 5 as I8, rhs: 3 as I8, low: 15 as I8, high: 0 as I8, error: false), - (lhs: 5 as I8, rhs: 4 as I8, low: 20 as I8, high: 0 as I8, error: false), - (lhs: 5 as I8, rhs: 5 as I8, low: 25 as I8, high: 0 as I8, error: false), + (I8(~5), I8(~5), I8( 36), I8(~11), true ), + (I8(~5), I8(~4), I8( 30), I8(~10), true ), + (I8(~5), I8(~3), I8( 24), I8( ~9), true ), + (I8(~5), I8(~2), I8( 18), I8( ~8), true ), + (I8(~5), I8(~1), I8( 12), I8( ~7), true ), + (I8(~5), I8(~0), I8( 6), I8( ~6), true ), + (I8(~5), I8( 0), I8( 0), I8( 0), false), + (I8(~5), I8( 1), I8( ~5), I8( 0), false), + (I8(~5), I8( 2), I8(~11), I8( 1), true ), + (I8(~5), I8( 3), I8(~17), I8( 2), true ), + (I8(~5), I8( 4), I8(~23), I8( 3), true ), + (I8(~5), I8( 5), I8(~29), I8( 4), true ), - ] as [( - lhs: I8, rhs: I8, low: I8, high: I8, error: Bool - )]) func someLowEntropiesAsFullWidthAsUnsigned( + (I8( 0), I8(~5), I8( 0), I8( 0), false), + (I8( 0), I8(~3), I8( 0), I8( 0), false), + (I8( 0), I8(~2), I8( 0), I8( 0), false), + (I8( 0), I8(~1), I8( 0), I8( 0), false), + (I8( 0), I8(~0), I8( 0), I8( 0), false), + (I8( 0), I8( 0), I8( 0), I8( 0), false), + (I8( 0), I8( 1), I8( 0), I8( 0), false), + (I8( 0), I8( 2), I8( 0), I8( 0), false), + (I8( 0), I8( 4), I8( 0), I8( 0), false), + (I8( 0), I8( 5), I8( 0), I8( 0), false), + + (I8( 5), I8(~5), I8(~29), I8( 4), true ), + (I8( 5), I8(~4), I8(~24), I8( 4), true ), + (I8( 5), I8(~3), I8(~19), I8( 4), true ), + (I8( 5), I8(~2), I8(~14), I8( 4), true ), + (I8( 5), I8(~1), I8( ~9), I8( 4), true ), + (I8( 5), I8(~0), I8( ~4), I8( 4), true ), + (I8( 5), I8( 0), I8( 0), I8( 0), false), + (I8( 5), I8( 1), I8( 5), I8( 0), false), + (I8( 5), I8( 2), I8( 10), I8( 0), false), + (I8( 5), I8( 3), I8( 15), I8( 0), false), + (I8( 5), I8( 4), I8( 20), I8( 0), false), + (I8( 5), I8( 5), I8( 25), I8( 0), false), + + ])) func someLowEntropiesAsFullWidthAsUnsigned( lhs: I8, rhs: I8, low: I8, high: I8, error: Bool ) throws { @@ -338,7 +334,9 @@ import TestKit "BinaryInteger/multiplication: (0s, 1s) * (0s, 1s)", Tag.List.tags(.generic, .important), arguments: typesAsArbitraryIntegerAsByte - ) func for0s1sBy0s1s(type: any ArbitraryInteger.Type) throws { + ) func for0s1sBy0s1s( + type: any ArbitraryInteger.Type + ) throws { try whereIs(type) func whereIs(_ type: T.Type) throws where T: ArbitraryInteger { @@ -372,25 +370,24 @@ import TestKit "BinaryInteger/multiplication: full 8-bit is half 16-bit", Tag.List.tags(.exhaustive, .generic), ConditionTrait.disabled(if: isDebug), - arguments: [ + arguments: Array<(any SystemsInteger.Type, any SystemsInteger.Type)>.infer([ - (x08: I8.self, x16: I16.self), - (x08: I8.self, x16: DoubleInt.self), - (x08: U8.self, x16: U16.self), - (x08: U8.self, x16: DoubleInt.self), + (I8.self, I16.self), + (I8.self, DoubleInt.self), + (U8.self, U16.self), + (U8.self, DoubleInt.self), - ] as [( - x08: any SystemsInteger.Type, x16: any SystemsInteger.Type - )]) func full8BitIsHalf16Bit( + ])) func full8BitIsHalf16Bit( x08: any SystemsInteger.Type, x16: any SystemsInteger.Type ) throws { - try whereIs(x08, x16) - func whereIs(_ x08: A.Type, _ x16: B.Type) throws where A: SystemsInteger, B: SystemsInteger { + try whereIs(x08: x08, x16: x16) + func whereIs(x08: A.Type, x16: B.Type) + throws where A: SystemsInteger, B: SystemsInteger { try #require(A.size == Count(08)) try #require(B.size == Count(16)) - try #require(A.isSigned == B.isSigned) - try withOnlyOneCallToRequire((x08,x16)) { require in + try #require(A.isSigned == (B.isSigned)) + try withOnlyOneCallToRequire((x08, x16)) { require in for lhs in A.all { for rhs in A.all { let result = lhs.multiplication((rhs)) @@ -454,8 +451,7 @@ import TestKit Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers ) func randomByZeroIsZero( - type: any BinaryInteger.Type, - randomness: consuming FuzzerInt + type: any BinaryInteger.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) @@ -546,7 +542,7 @@ import TestKit // MARK: * Binary Integer x Multiplication x Conveniences //*============================================================================* -@Suite(.tags(.forwarding)) struct BinaryIntegerTestsOnMultiplicationConveniences { +@Suite struct BinaryIntegerTestsOnMultiplicationConveniences { //=------------------------------------------------------------------------= // MARK: Tests @@ -554,7 +550,7 @@ import TestKit @Test( "BinaryInteger/multiplication/conveniences: x * y as BinaryInteger", - Tag.List.tags(.generic, .random), + Tag.List.tags(.forwarding, .generic, .random), arguments: typesAsBinaryInteger, fuzzers ) func randomByRandomAsBinaryInteger( type: any BinaryInteger.Type, randomness: consuming FuzzerInt @@ -577,7 +573,7 @@ import TestKit @Test( "BinaryInteger/multiplication/conveniences: x * x as BinaryInteger", - Tag.List.tags(.generic, .random), + Tag.List.tags(.forwarding, .generic, .random), arguments: typesAsBinaryInteger, fuzzers ) func randomByItselfAsBinaryInteger( type: any BinaryInteger.Type, randomness: consuming FuzzerInt @@ -603,11 +599,10 @@ import TestKit @Test( "BinaryInteger/multiplication/conveniences: x * y as LenientInteger", - Tag.List.tags(.generic, .random), + Tag.List.tags(.forwarding, .generic, .random), arguments: typesAsArbitraryIntegerAsSigned, fuzzers ) func randomByRandomAsLenientInteger( - type: any ArbitraryIntegerAsSigned.Type, - randomness: consuming FuzzerInt + type: any ArbitraryIntegerAsSigned.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) @@ -629,7 +624,7 @@ import TestKit @Test( "BinaryInteger/multiplication/conveniences: x * x as LenientInteger", - Tag.List.tags(.generic, .random), + Tag.List.tags(.forwarding, .generic, .random), arguments: typesAsArbitraryIntegerAsSigned, fuzzers ) func randomByItselfAsLenientInteger( type: any ArbitraryIntegerAsSigned.Type, randomness: consuming FuzzerInt diff --git a/Tests/UltimathnumTests/BinaryInteger+Random.swift b/Tests/UltimathnumTests/BinaryInteger+Random.swift index 46e1bea4..afc00495 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Random.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Random.swift @@ -275,7 +275,8 @@ import TestKit ) throws { try whereIs(type, randomness) - func whereIs(_ type: T.Type, _ randomness: consuming some Randomness) throws where T: SystemsInteger { + func whereIs(_ type: T.Type, _ randomness: consuming some Randomness) + throws where T: SystemsInteger { var matches: Set = [] matches.reserveCapacity(T.all.count) @@ -297,7 +298,8 @@ import TestKit ) throws { try whereIs(type, randomness) - func whereIs(_ type: T.Type, _ randomness: consuming some Randomness) throws where T: SystemsInteger { + func whereIs(_ type: T.Type, _ randomness: consuming some Randomness) + throws where T: SystemsInteger { var matches: Set = [] matches.reserveCapacity(T.all.count) @@ -326,7 +328,8 @@ import TestKit ) throws { try whereIs(type, randomness) - func whereIs(_ type: T.Type, _ randomness: consuming some Randomness) throws where T: SystemsInteger { + func whereIs(_ type: T.Type, _ randomness: consuming some Randomness) + throws where T: SystemsInteger { var matches: Set = [] matches.reserveCapacity(T.all.count) diff --git a/Tests/UltimathnumTests/BinaryInteger+Shift.swift b/Tests/UltimathnumTests/BinaryInteger+Shift.swift index 63f3286c..aee6beef 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Shift.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Shift.swift @@ -26,9 +26,11 @@ import TestKit "BinaryInteger/shift: down(Shift)", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func down(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func down( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { let size = IX(size: T.self) ?? 256 @@ -56,9 +58,11 @@ import TestKit "BinaryInteger/shift: up(Shift)", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func up(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func up( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { let size = IX(size: T.self) ?? 256 @@ -98,7 +102,7 @@ import TestKit // MARK: * Binary Integer x Shift x Conveniences //*============================================================================* -@Suite(.tags(.forwarding)) struct BinaryIntegerTestsOnShiftConveniences { +@Suite struct BinaryIntegerTestsOnShiftConveniences { //=------------------------------------------------------------------------= // MARK: Tests @@ -106,9 +110,12 @@ import TestKit @Test( "BinaryInteger/shift/conveniences: masking", - Tag.List.tags(.generic, .random), + Tag.List.tags(.forwarding, .generic, .random), arguments: typesAsSystemsInteger, fuzzers - ) func masking(type: any SystemsInteger.Type, randomness: consuming FuzzerInt) throws { + ) func masking( + type: any SystemsInteger.Type, randomness: consuming FuzzerInt + ) throws { + for distance in typesAsBinaryInteger { try whereIs(type, distance) } @@ -135,14 +142,17 @@ import TestKit @Test( "BinaryInteger/shift/conveniences: down(Shift) vs positive distance in ±[0, size)", - Tag.List.tags(.generic, .random), + Tag.List.tags(.forwarding, .generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func downVersusPositiveDistanceFromZeroUpToSize(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func downVersusPositiveDistanceFromZeroUpToSize( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { for distance in typesAsBinaryInteger { try whereIs(type, distance) } - func whereIs(_ type: T.Type, _ other: U.Type) throws where T: BinaryInteger, U: BinaryInteger { + func whereIs(_ type: T.Type, _ other: U.Type) + throws where T: BinaryInteger, U: BinaryInteger { let size = IX(size: T.self) ?? 256 let clamped = IX(U(clamping: size - 1)) @@ -158,14 +168,18 @@ import TestKit @Test( "BinaryInteger/shift/conveniences: down(Shift) vs negative distance in ±[0, size)", - Tag.List.tags(.generic, .random), + Tag.List.tags(.forwarding, .generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func downVersusNegativeDistanceFromZeroUpToSize(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func downVersusNegativeDistanceFromZeroUpToSize( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + for distance in typesAsBinaryIntegerAsSigned { try whereIs(type, distance) } - func whereIs(_ type: T.Type, _ other: U.Type) throws where T: BinaryInteger, U: SignedInteger { + func whereIs(_ type: T.Type, _ other: U.Type) + throws where T: BinaryInteger, U: SignedInteger { let size = IX(size: T.self) ?? 256 let clamped = IX(U(clamping: size - 1)) @@ -181,9 +195,12 @@ import TestKit @Test( "BinaryInteger/shift/conveniences: up(Shift) vs positive distance in ±[0, size)", - Tag.List.tags(.generic, .random), + Tag.List.tags(.forwarding, .generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func upVersusPositiveDistanceFromZeroUpToSize(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func upVersusPositiveDistanceFromZeroUpToSize( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + for distance in typesAsBinaryInteger { try whereIs(type, distance) } @@ -205,14 +222,18 @@ import TestKit @Test( "BinaryInteger/shift/conveniences: up(Shift) vs negative distance in ±[0, size)", - Tag.List.tags(.generic, .random), + Tag.List.tags(.forwarding, .generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func upVersusNegativeDistanceFromZeroUpToSize(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func upVersusNegativeDistanceFromZeroUpToSize( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + for distance in typesAsBinaryIntegerAsSigned { try whereIs(type, distance) } - func whereIs(_ type: T.Type, _ other: U.Type) throws where T: BinaryInteger, U: SignedInteger { + func whereIs(_ type: T.Type, _ other: U.Type) + throws where T: BinaryInteger, U: SignedInteger { let size = IX(size: T.self) ?? 256 let clamped = IX(U(clamping: size - 1)) let arbitrary = IX(Bit(T.isArbitrary)) @@ -242,9 +263,11 @@ import TestKit "BinaryInteger/shift/edge-cases: distance of zero yields input", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func distanceOfZeroYieldsInput(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func distanceOfZeroYieldsInput( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 32 { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -260,9 +283,11 @@ import TestKit "BinaryInteger/shift/edge-cases: down by distance near nonappendix count", Tag.List.tags(.generic, .important, .random), arguments: typesAsBinaryInteger, fuzzers - ) func downByDistanceNearNonappendixCount(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func downByDistanceNearNonappendixCount( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 256 { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -283,9 +308,11 @@ import TestKit "BinaryInteger/shift/edge-cases: up by distance to start of next element", Tag.List.tags(.generic, .important, .random), arguments: typesAsBinaryInteger, fuzzers - ) func upByDistanceToStartOfNextElement(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func upByDistanceToStartOfNextElement( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< conditional(debug: 8, release: 32) { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -307,9 +334,11 @@ import TestKit "BinaryInteger/shift/edge-cases: overshift by Count or Shift in ±[size, IX.max]", Tag.List.tags(.generic, .random), arguments: typesAsSystemsInteger, fuzzers - ) func overshiftByCountOrShiftFromSizeThroughLimit(type: any SystemsInteger.Type, randomness: consuming FuzzerInt) throws { + ) func overshiftByCountOrShiftFromSizeThroughLimit( + type: any SystemsInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: SystemsInteger { let size = IX(size: T.self) @@ -332,12 +361,16 @@ import TestKit "BinaryInteger/shift/edge-cases: overshift by positive distance in ±[size, IX.max]", Tag.List.tags(.generic, .random), arguments: typesAsSystemsInteger, fuzzers - ) func overshiftByPositiveDistanceFromSizeThroughLimit(type: any SystemsInteger.Type, randomness: consuming FuzzerInt) throws { + ) func overshiftByPositiveDistanceFromSizeThroughLimit( + type: any SystemsInteger.Type, randomness: consuming FuzzerInt + ) throws { + for distance in typesAsBinaryInteger { try whereIs(type, distance) } - func whereIs(_ type: T.Type, _ other: U.Type) throws where T: SystemsInteger, U: BinaryInteger { + func whereIs(_ type: T.Type, _ other: U.Type) + throws where T: SystemsInteger, U: BinaryInteger { guard let min = U.exactly(IX(size: T.self)).optional() else { return } let max = U(clamping: IX.max) @@ -358,12 +391,16 @@ import TestKit "BinaryInteger/shift/edge-cases: overshift by negative distance in ±[size, IX.max]", Tag.List.tags(.generic, .random), arguments: typesAsSystemsInteger, fuzzers - ) func overshiftByNegativeDistanceFromSizeThroughLimit(type: any SystemsInteger.Type, randomness: consuming FuzzerInt) throws { + ) func overshiftByNegativeDistanceFromSizeThroughLimit( + type: any SystemsInteger.Type, randomness: consuming FuzzerInt + ) throws { + for distance in typesAsBinaryInteger { try whereIs(type, distance) } - func whereIs(_ type: T.Type, _ other: U.Type) throws where T: SystemsInteger, U: BinaryInteger { + func whereIs(_ type: T.Type, _ other: U.Type) + throws where T: SystemsInteger, U: BinaryInteger { guard let max = U.exactly(-IX(size: T.self)).optional() else { return } let min = U(clamping: -IX.max) @@ -388,12 +425,16 @@ import TestKit "BinaryInteger/shift/edge-cases: overshift by positive distance in ±(IX.max, ∞)", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func overshiftByPositiveDistanceGreaterThanLimit(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func overshiftByPositiveDistanceGreaterThanLimit( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + for distance in typesAsBinaryInteger { try whereIs(type, distance) } - func whereIs(_ type: T.Type, _ other: U.Type) throws where T: BinaryInteger, U: BinaryInteger { + func whereIs(_ type: T.Type, _ other: U.Type) + throws where T: BinaryInteger, U: BinaryInteger { guard let min = U.exactly(UX.msb).optional() else { return } let max = U(clamping: IXL(Array(repeating: U64.max, count: 4))) @@ -413,7 +454,10 @@ import TestKit "BinaryInteger/shift/edge-cases: overshift by negative distance in ±(IX.max, ∞)", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func overshiftByNegativeDistanceGreaterThanLimit(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func overshiftByNegativeDistanceGreaterThanLimit( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + for distance in typesAsBinaryInteger { try whereIs(type, distance) } @@ -442,9 +486,11 @@ import TestKit "BinaryInteger/shift/edge-cases: overshift by infinite Count or Shift", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func overshiftByInfiniteCountOrShift(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func overshiftByInfiniteCountOrShift( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 32 { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -468,12 +514,16 @@ import TestKit "BinaryInteger/shift/edge-cases: overshift by infinite ArbitraryInteger", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func overshiftByInfiniteArbitraryInteger(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func overshiftByInfiniteArbitraryInteger( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + for distance in typesAsArbitraryIntegerAsUnsigned { try whereIs(type, distance) } - func whereIs(_ type: T.Type, _ other: U.Type) throws where T: BinaryInteger, U: ArbitraryIntegerAsUnsigned { + func whereIs(_ type: T.Type, _ other: U.Type) + throws where T: BinaryInteger, U: ArbitraryIntegerAsUnsigned { for _ in 0 ..< 32 { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) let distance = U.entropic(through: Shift.max(or: 255), as: Domain.natural, using: &randomness).toggled() @@ -490,7 +540,7 @@ import TestKit // MARK: * Binary Integer x Shift x Disambiguation //*============================================================================* -@Suite(.tags(.disambiguation)) struct BinaryIntegerTestsOnShiftDisambiguation { +@Suite struct BinaryIntegerTestsOnShiftDisambiguation { //=------------------------------------------------------------------------= // MARK: Tests @@ -498,7 +548,7 @@ import TestKit @Test( "BinaryInteger/exponentiation/disambiguation: literals", - Tag.List.tags(.generic) + Tag.List.tags(.disambiguation, .generic) ) func literals() { func build(_ x: inout T) where T: BinaryInteger { x <<= 0 @@ -523,11 +573,13 @@ import TestKit @Test( "BinaryInteger/exponentiation/disambiguation: smart shift by IX vs Swift.Int", - Tag.List.tags(.generic, .random), + Tag.List.tags(.disambiguation, .generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func smartByTokenVersusSwiftToken(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func smartByTokenVersusSwiftToken( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 32 { var distance = IX.entropic(using: &randomness) @@ -547,11 +599,13 @@ import TestKit @Test( "BinaryInteger/exponentiation/disambiguation: masking swift as IX vs Swift.Int", - Tag.List.tags(.generic, .random), + Tag.List.tags(.disambiguation, .generic, .random), arguments: typesAsSystemsInteger, fuzzers - ) func maskingByTokenVersusSwiftToken(type: any SystemsInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func maskingByTokenVersusSwiftToken( + type: any SystemsInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: SystemsInteger { for _ in 0 ..< 32 { let distance = IX.entropic(using: &randomness) diff --git a/Tests/UltimathnumTests/BinaryInteger+Stdlib.swift b/Tests/UltimathnumTests/BinaryInteger+Stdlib.swift index 8dd50813..736c3e59 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Stdlib.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Stdlib.swift @@ -25,9 +25,11 @@ import TestKit "BinaryInteger/stdlib: conversions", Tag.List.tags(.generic, .random), arguments: typesAsCoreInteger, fuzzers - ) func conversions(type: any CoreInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func conversions( + type: any CoreInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: CoreInteger { for _ in 0 ..< 16 { var a = T.random(using: &randomness) diff --git a/Tests/UltimathnumTests/BinaryInteger+Stride.swift b/Tests/UltimathnumTests/BinaryInteger+Stride.swift index 102649b4..e7fcf1ad 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Stride.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Stride.swift @@ -26,14 +26,18 @@ import TestKit "BinaryInteger/stride: advanced(by:) vs ArbitraryInteger.±(_:_:)", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func advancedByVersusArbitraryInteger(randomness: consuming FuzzerInt) throws { + ) func advancedByVersusArbitraryInteger( + randomness: consuming FuzzerInt + ) throws { + for type in typesAsBinaryInteger { for distance in typesAsBinaryIntegerAsSigned { try whereIs(type: type, distance: distance) } } - func whereIs(type: A.Type, distance: B.Type) throws where A: BinaryInteger, B: SignedInteger { + func whereIs(type: A.Type, distance: B.Type) + throws where A: BinaryInteger, B: SignedInteger { for _ in 0 ..< conditional(debug: 32, release: 256) { let start = A.entropic(through: Shift.max(or: 255), using: &randomness) let distance = B.entropic(through: Shift.max(or: 255), using: &randomness) @@ -57,14 +61,18 @@ import TestKit "BinaryInteger/stride: distance(to:) vs ArbitraryInteger.±(_:_:)", Tag.List.tags(.generic, .random), arguments: fuzzers - ) func distanceToVersusArbitraryInteger(randomness: consuming FuzzerInt) throws { + ) func distanceToVersusArbitraryInteger( + randomness: consuming FuzzerInt + ) throws { + for type in typesAsBinaryInteger { for distance in typesAsBinaryIntegerAsSigned { try whereIs(type: type, distance: distance) } } - func whereIs(type: A.Type, distance: B.Type) throws where A: BinaryInteger, B: SignedInteger { + func whereIs(type: A.Type, distance: B.Type) + throws where A: BinaryInteger, B: SignedInteger { for _ in 0 ..< conditional(debug: 32, release: 256) { let start = A.entropic(through: Shift.max(or: 255), using: &randomness) let end = A.entropic(through: Shift.max(or: 255), using: &randomness) diff --git a/Tests/UltimathnumTests/BinaryInteger+Text.swift b/Tests/UltimathnumTests/BinaryInteger+Text.swift index 321cb873..13c1cc79 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Text.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Text.swift @@ -260,8 +260,8 @@ import TestKit try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { - let signs = ["", "+", "-"] - let masks = ["", "&"] + let signs: [String] = ["", "+", "-"] + let masks: [String] = ["", "&"] for coder in BinaryIntegerTestsOnText.coders { for sign in signs { @@ -381,7 +381,7 @@ import TestKit // MARK: * Binary Integer x Text x Edge Cases //*============================================================================* -@Suite(.tags(.important)) struct BinaryIntegerTestsOnTextEdgeCases { +@Suite struct BinaryIntegerTestsOnTextEdgeCases { //=------------------------------------------------------------------------= // MARK: Tests @@ -389,7 +389,7 @@ import TestKit @Test( "BinaryInteger/text/validation: decoding edges works", - Tag.List.tags(.generic), + Tag.List.tags(.generic, .important), arguments: typesAsEdgyInteger ) func decodingEdgesWorks( type: any EdgyInteger.Type @@ -408,7 +408,7 @@ import TestKit @Test( "BinaryInteger/text/validation: decoding one past min is error", - Tag.List.tags(.generic), + Tag.List.tags(.generic, .important), arguments: typesAsEdgyInteger ) func decodingOnePastMinIsError( type: any EdgyInteger.Type @@ -429,7 +429,7 @@ import TestKit @Test( "BinaryInteger/text/validation: decoding one past max is error", - Tag.List.tags(.generic), + Tag.List.tags(.generic, .important), arguments: typesAsSystemsInteger ) func decodingOnePastMaxIsError( type: any SystemsInteger.Type @@ -450,7 +450,7 @@ import TestKit @Test( "BinaryInteger/text/validation: decoding random past min is error", - Tag.List.tags(.generic, .random), + Tag.List.tags(.generic, .random, .important), arguments: typesAsEdgyInteger, fuzzers ) func decodingOnePastMinIsError( type: any EdgyInteger.Type, randomness: consuming FuzzerInt @@ -474,7 +474,7 @@ import TestKit @Test( "BinaryInteger/text/validation: decoding random past max is error", - Tag.List.tags(.generic, .random), + Tag.List.tags(.generic, .random, .important), arguments: typesAsSystemsInteger, fuzzers ) func decodingOnePastMaxIsError( type: any SystemsInteger.Type, randomness: consuming FuzzerInt @@ -498,7 +498,7 @@ import TestKit @Test( "BinaryInteger/text/validation: decoding infinite as finite is error", - Tag.List.tags(.generic, .random), + Tag.List.tags(.generic, .random, .important), arguments: typesAsFiniteInteger, fuzzers ) func decodingInfiniteAsFiniteIsError( type: any FiniteInteger.Type, randomness: consuming FuzzerInt @@ -525,7 +525,7 @@ import TestKit // MARK: * Binary Integer x Text x Pyramids //*============================================================================* -@Suite(.tags(.important)) struct BinaryIntegerTestsOnTextPyramids { +@Suite struct BinaryIntegerTestsOnTextPyramids { //=------------------------------------------------------------------------= // MARK: Metadata @@ -549,11 +549,13 @@ import TestKit /// @Test( "BinaryInteger/text/pyramids: one followed by zeros", - Tag.List.tags(.generic), + Tag.List.tags(.generic, .important), arguments: typesAsBinaryInteger - ) func pyramidOfOneFollowedByZeros(type: any BinaryInteger.Type) throws { - try whereIs(type) + ) func pyramidOfOneFollowedByZeros( + type: any BinaryInteger.Type + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { for coder: TextInt in Self.coders { var encoded = String("1") @@ -582,11 +584,13 @@ import TestKit /// @Test( "BinaryInteger/text/pyramids: ascending numeral cycle", - Tag.List.tags(.generic), + Tag.List.tags(.generic, .important), arguments: typesAsBinaryInteger - ) func pyramidOfAscendingNumeralCycle(type: any BinaryInteger.Type) throws { + ) func pyramidOfAscendingNumeralCycle( + type: any BinaryInteger.Type + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { for coder: TextInt in Self.coders { var encoded = String() @@ -620,11 +624,13 @@ import TestKit /// @Test( "BinaryInteger/text/pyramids: repeating highest numeral", - Tag.List.tags(.generic), + Tag.List.tags(.generic, .important), arguments: typesAsBinaryInteger - ) func pyramidOfRepeatingHighestNumeral(type: any BinaryInteger.Type) throws { - try whereIs(type) + ) func pyramidOfRepeatingHighestNumeral( + type: any BinaryInteger.Type + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { for coder: TextInt in Self.coders { var encoded = String() @@ -651,7 +657,7 @@ import TestKit // MARK: * Binary Integer x Text x Conveniences //*============================================================================* -@Suite(.tags(.forwarding)) struct BinaryIntegerTestsOnTextConveniences { +@Suite struct BinaryIntegerTestsOnTextConveniences { //=------------------------------------------------------------------------= // MARK: Tests @@ -659,11 +665,13 @@ import TestKit @Test( "BinaryInteger/text/conveniences: decimal", - Tag.List.tags(.generic, .random), + Tag.List.tags(.forwarding, .generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func decimal(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func decimal( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) - func whereIs(_ type: T.Type) throws where T: BinaryInteger { try #require(T(String()) == nil) diff --git a/Tests/UltimathnumTests/BinaryInteger+Values.swift b/Tests/UltimathnumTests/BinaryInteger+Values.swift index fed918f0..ffe40b2b 100644 --- a/Tests/UltimathnumTests/BinaryInteger+Values.swift +++ b/Tests/UltimathnumTests/BinaryInteger+Values.swift @@ -85,7 +85,8 @@ import TestKit try whereIs(source: type, destination: IX.self) try whereIs(source: type, destination: UX.self) - func whereIs(source: T.Type, destination: U.Type) throws where T: BinaryInteger, U: SystemsInteger { + func whereIs(source: T.Type, destination: U.Type) + throws where T: BinaryInteger, U: SystemsInteger { if T.isArbitrary { try #require(U(size: T.self) == nil) } else { @@ -103,7 +104,8 @@ import TestKit try whereIs(source: type, destination: IX.self) try whereIs(source: type, destination: UX.self) - func whereIs(source: T.Type, destination: U.Type) throws where T: SystemsInteger, U: SystemsInteger { + func whereIs(source: T.Type, destination: U.Type) + throws where T: SystemsInteger, U: SystemsInteger { try #require(Count(raw: U(size: T.self)) == T.size) } } diff --git a/Tests/UltimathnumTests/Count+Comparison.swift b/Tests/UltimathnumTests/Count+Comparison.swift index 0c1bd61d..396c5c70 100644 --- a/Tests/UltimathnumTests/Count+Comparison.swift +++ b/Tests/UltimathnumTests/Count+Comparison.swift @@ -21,8 +21,13 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test(arguments: fuzzers) - func comparisonIsLikeUnsignedIntegerComparison(_ randomness: consuming FuzzerInt) { + @Test( + "Count/comparison: compared(to:) is UnsignedInteger/compared(to:)", + Tag.List.tags(.random), + arguments: fuzzers + ) func comparisonIsLikeUnsignedIntegerComparison( + randomness: consuming FuzzerInt + ) throws { for _ in 0 ..< 256 { let lhs = UX.entropic(using: &randomness) let rhs = UX.entropic(using: &randomness) @@ -30,24 +35,37 @@ import TestKit } } - @Test(arguments: fuzzers) - func isZeroIsLikeBinaryIntegerIsZero(_ randomness: consuming FuzzerInt) { + @Test( + "Count/comparison: isZero is BinaryInteger/isZero", + Tag.List.tags(.random), + arguments: fuzzers + ) func isZeroIsLikeBinaryIntegerIsZero( + randomness: consuming FuzzerInt + ) throws { for _ in 0 ..< 256 { let random = IX.entropic(using: &randomness) - #expect(Count(raw: random).isZero == random.isZero) + try #require(Count(raw: random).isZero == random.isZero) } } - @Test(arguments: fuzzers) - func isInfiniteIsLikeSignedIntegerIsNegative(_ randomness: consuming FuzzerInt) { + @Test( + "Count/comparison: isInfinite is BinaryInteger/isNegative", + Tag.List.tags(.random), + arguments: fuzzers + ) func isInfiniteIsLikeSignedIntegerIsNegative( + randomness: consuming FuzzerInt + ) throws { for _ in 0 ..< 256 { let random = IX.entropic(using: &randomness) - #expect(Count(raw: random).isInfinite == random.isNegative) + try #require(Count(raw: random).isInfinite == random.isNegative) } } - @Test(arguments: fuzzers) - func isPowerOf2IsNormalExceptMaxIsPowerOf2(_ randomness: consuming FuzzerInt) { + @Test( + "Count/comparison: isPowerOf2 is BinaryInteger/isPowerOf2 or log2(&0+1)", + Tag.List.tags(.random), + arguments: fuzzers + ) func isPowerOf2IsNormalExceptMaxIsPowerOf2(randomness: consuming FuzzerInt) { #expect( Count(raw: UX.max).isPowerOf2) #expect(!Count(raw: IX.min).isPowerOf2) #expect(!Count(raw: IX.max).isPowerOf2) diff --git a/Tests/UltimathnumTests/Count+Integers.swift b/Tests/UltimathnumTests/Count+Integers.swift index f8655e7e..f6576b3b 100644 --- a/Tests/UltimathnumTests/Count+Integers.swift +++ b/Tests/UltimathnumTests/Count+Integers.swift @@ -22,84 +22,46 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("Count ← some BinaryInteger - disambiguation", .tags(.disambiguation)) - func disambiguation() { - func build() { - _ = Count.init(0) - _ = Count.init(load: 0) - _ = Count.exactly(0) - } - } - - @Test("Count ← some BinaryInteger - documentation", .serialized, .tags(.documentation), arguments: [ + @Test( + "Count/integers: init(_:) - examples", + Tag.List.tags(.documentation), + ParallelizationTrait.serialized, + arguments: Array<(IXL, Optional>)>.infer([ - (source: IXL(IX.max ) + 2, expectation: nil), - (source: IXL(IX.max ) + 1, expectation: nil), - (source: IXL(IX.max ), expectation: Fallible("\(IX.max )")), - (source: IXL(IX.max ) - 1, expectation: Fallible("\(IX.max - 1)")), - (source: IXL(IX.max ) - 2, expectation: Fallible("\(IX.max - 2)")), + (IXL(IX.max ) + 2, nil), + (IXL(IX.max ) + 1, nil), + (IXL(IX.max ), Fallible("\(IX.max )")), + (IXL(IX.max ) - 1, Fallible("\(IX.max - 1)")), + (IXL(IX.max ) - 2, Fallible("\(IX.max - 2)")), - (source: IXL(IX.zero) + 2, expectation: Fallible("\(IX.zero + 2)")), - (source: IXL(IX.zero) + 1, expectation: Fallible("\(IX.zero + 1)")), - (source: IXL(IX.zero), expectation: Fallible("\(IX.zero )")), - (source: IXL(IX.zero) - 1, expectation: Fallible("log2(&0+1)\(IX.zero - 1)").veto()), - (source: IXL(IX.zero) - 2, expectation: Fallible("log2(&0+1)\(IX.zero - 2)").veto()), + (IXL(IX.zero) + 2, Fallible("\(IX.zero + 2)")), + (IXL(IX.zero) + 1, Fallible("\(IX.zero + 1)")), + (IXL(IX.zero), Fallible("\(IX.zero )")), + (IXL(IX.zero) - 1, Fallible("log2(&0+1)\(IX.zero - 1)").veto()), + (IXL(IX.zero) - 2, Fallible("log2(&0+1)\(IX.zero - 2)").veto()), - (source: IXL(IX.min ) + 2, expectation: Fallible("log2(&0+1)\(IX.min + 2)").veto()), - (source: IXL(IX.min ) + 1, expectation: Fallible("log2(&0+1)\(IX.min + 1)").veto()), - (source: IXL(IX.min ), expectation: nil), - (source: IXL(IX.min ) - 1, expectation: nil), - (source: IXL(IX.min ) - 2, expectation: nil), + (IXL(IX.min ) + 2, Fallible("log2(&0+1)\(IX.min + 2)").veto()), + (IXL(IX.min ) + 1, Fallible("log2(&0+1)\(IX.min + 1)").veto()), + (IXL(IX.min ), nil), + (IXL(IX.min ) - 1, nil), + (IXL(IX.min ) - 2, nil), - ] as [(source: IXL, expectation: Optional>)]) - func initSomeBinaryIntegerExamples(source: IXL, expectation: Fallible?) { + ])) func initSomeBinaryIntegerExamples( + source: IXL, expectation: Optional> + ) throws { #expect(Count.exactly(source)?.map(\.description) == expectation) } - //=------------------------------------------------------------------------= - // MARK: Tests x Edges - //=------------------------------------------------------------------------= - - @Test("Count ← IX.min == nil") - func initSameSizeSignedIntegerMinValueIsNil() { - #expect(Count(load: (IX.min)) == nil) - #expect(Count(load: IXL(IX.min)) == nil) - #expect(Count.exactly( (IX.min)) == nil) - #expect(Count.exactly(IXL(IX.min)) == nil) - } - - //=------------------------------------------------------------------------= - // MARK: Tests x Random - //=------------------------------------------------------------------------= - - @Test("Count ← IX - entropic", arguments: fuzzers) - func initSameSizeSignedIntegerByFuzzing(randomness: consuming FuzzerInt) { - for _ in 0 ..< 1024 { - let random = IX.entropic(using: &randomness) - - if IX.zero <= random, random <= IX.max { - let expectation = Fallible(Count(raw: IX(random))) - #expect(Count.exactly(random) == expectation) - #expect(Count(load: random) == expectation.value) - #expect(Count( random) == expectation.value) - - } else if IX.min < random, random < IX.zero { - let expectation = Count(raw: IX(random).decremented().value).veto() - #expect(Count.exactly(random) == expectation) - #expect(Count(load: random) == expectation.value) - - } else { - #expect(Count.exactly(random) == nil) - #expect(Count(load: random) == nil) - } - } - } - - @Test("Count ← some BinaryInteger - entropic", arguments: typesAsBinaryInteger, fuzzers) - func initSomeBinaryIntegerByFuzzing(source: any BinaryInteger.Type, randomness: consuming FuzzerInt) { - whereIs(source) + @Test( + "Count/integers: init(_:) - some BinaryInteger", + Tag.List.tags(.generic, .random), + arguments: typesAsBinaryInteger, fuzzers + ) func initSomeBinaryIntegerByFuzzing( + source: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { - func whereIs(_ source: T.Type) where T: BinaryInteger { + try whereIs(source) + func whereIs(_ source: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 128 { let random = T.entropic(through: Shift.max(or: 255), using: &randomness) @@ -108,7 +70,7 @@ import TestKit #expect(Count.exactly(random) == expectation) #expect(Count(load: random) == expectation.value) #expect(Count( random) == expectation.value) - + } else if IX.min < random, random < IX.zero { let expectation = Count(raw: IX(random).decremented().value).veto() #expect(Count.exactly(random) == expectation) @@ -121,4 +83,64 @@ import TestKit } } } + + @Test( + "Count/integers: init(_:) - IX", + Tag.List.tags(.random), + arguments: fuzzers + ) func initSameSizeSignedIntegerByFuzzing( + randomness: consuming FuzzerInt + ) throws { + for _ in 0 ..< 1024 { + let random = IX.entropic(using: &randomness) + + if IX.zero <= random, random <= IX.max { + let expectation = Fallible(Count(raw: IX(random))) + try #require(Count.exactly(random) == expectation) + try #require(Count(load: random) == expectation.value) + try #require(Count( random) == expectation.value) + + } else if IX.min < random, random < IX.zero { + let expectation = Count(raw: IX(random).decremented().value).veto() + try #require(Count.exactly(random) == expectation) + try #require(Count(load: random) == expectation.value) + + } else { + try #require(Count.exactly(random) == nil) + try #require(Count(load: random) == nil) + } + } + } +} + +//*============================================================================* +// MARK: * Count x Integers x Edge Cases +//*============================================================================* + +@Suite struct CountTestsOnIntegersEdgeCases { + + //=------------------------------------------------------------------------= + // MARK: Tests + //=------------------------------------------------------------------------= + + @Test( + "Count/integers: disambiguation", + Tag.List.tags(.disambiguation) + ) func disambiguation() { + func build() { + _ = Count.init(0) + _ = Count.init(load: 0) + _ = Count.exactly(0) + } + } + + @Test( + "Count/integers/edge-cases: IX.min → nil", + Tag.List.tags(.documentation, .important) + ) func fromSameSizeSignedIntegerMinValueIsNil() { + #expect(Count(load: (IX.min)) == nil) + #expect(Count(load: IXL(IX.min)) == nil) + #expect(Count.exactly( (IX.min)) == nil) + #expect(Count.exactly(IXL(IX.min)) == nil) + } } diff --git a/Tests/UltimathnumTests/Count+Text.swift b/Tests/UltimathnumTests/Count+Text.swift index 740de8c4..863b73ee 100644 --- a/Tests/UltimathnumTests/Count+Text.swift +++ b/Tests/UltimathnumTests/Count+Text.swift @@ -21,34 +21,32 @@ import TestKit //=------------------------------------------------------------------------= @Test( - "Count/text: description of natural", + "Count/text: finite", Tag.List.tags(.documentation), - ParallelizationTrait.serialized, - arguments: Array<(Count, String)>([ + arguments: Array<(IX, String)>.infer([ - (Count(IX( 0)), "0"), - (Count(IX( 1)), "1"), - (Count(IX( 2)), "2"), - (Count(IX( 3)), "3"), - (Count(IX.max), "\(IX.max)"), + (IX( 0), String("0")), + (IX( 1), String("1")), + (IX( 2), String("2")), + (IX( 3), String("3")), + (IX.max, String("\(IX.max)")), - ])) func descriptionOfNatural(instance: Count, expectation: String) { - Ɣexpect(instance, description: expectation) + ])) func finite(pattern: IX, expectation: String) { + Ɣexpect(Count(raw: pattern), description: expectation) } @Test( - "Count/text: description of infinite", + "Count/text: infinite", Tag.List.tags(.documentation), - ParallelizationTrait.serialized, - arguments: Array<(Count, String)>([ + arguments: Array<(IX, String)>.infer([ - (Count(raw: IX(~0)), "log2(&0+1)" ), - (Count(raw: IX(~1)), "log2(&0+1)-1"), - (Count(raw: IX(~2)), "log2(&0+1)-2"), - (Count(raw: IX(~3)), "log2(&0+1)-3"), - (Count(raw: IX.min), "log2(&0+1)-\(IX.max)"), + (IX(~0), String("log2(&0+1)" )), + (IX(~1), String("log2(&0+1)-1")), + (IX(~2), String("log2(&0+1)-2")), + (IX(~3), String("log2(&0+1)-3")), + (IX.min, String("log2(&0+1)-\(IX.max)")), - ])) func descriptionOfInfinite(instance: Count, expectation: String) { - Ɣexpect(instance, description: expectation) + ])) func infinite(pattern: IX, expectation: String) { + Ɣexpect(Count(raw: pattern), description: expectation) } } diff --git a/Tests/UltimathnumTests/Count.swift b/Tests/UltimathnumTests/Count.swift index 4ad2c1d4..30a8a904 100644 --- a/Tests/UltimathnumTests/Count.swift +++ b/Tests/UltimathnumTests/Count.swift @@ -21,13 +21,18 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test func instances() { + @Test( + "Count: instances" + ) func instances() { #expect(Count.zero == Count(raw: 0 as IX)) #expect(Count.infinity == Count(raw: -1 as IX)) } - @Test("Count.init(raw:)", arguments: fuzzers) - func pattern(_ randomness: consuming FuzzerInt) { + @Test( + "Count: init(raw:)", + Tag.List.tags(.random), + arguments: fuzzers + ) func bitcasting(randomness: consuming FuzzerInt) { for _ in 0 ..< 256 { let random = IX.entropic(using: &randomness) let result = IX(raw: Count(raw: random)) @@ -35,8 +40,11 @@ import TestKit } } - @Test("Count/natural", arguments: fuzzers) - func natural(_ randomness: consuming FuzzerInt) { + @Test( + "Count/natural", + Tag.List.tags(.random), + arguments: fuzzers + ) func natural(randomness: consuming FuzzerInt) { for _ in 0 ..< 256 { let random = IX.entropic(using: &randomness) let result = Count(raw: random).natural() diff --git a/Tests/UltimathnumTests/Divider+Division.swift b/Tests/UltimathnumTests/Divider+Division.swift index 5c791426..410c2456 100644 --- a/Tests/UltimathnumTests/Divider+Division.swift +++ b/Tests/UltimathnumTests/Divider+Division.swift @@ -43,7 +43,7 @@ import TestKit Tag.List.tags(.generic, .random), arguments: typesAsSystemsIntegerAsUnsigned, fuzzers ) func values( - _ type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt + type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) @@ -62,7 +62,7 @@ import TestKit Tag.List.tags(.generic, .random), arguments: typesAsSystemsIntegerAsUnsigned, fuzzers ) func entropies( - _ type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt + type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) @@ -82,7 +82,7 @@ import TestKit Tag.List.tags(.generic, .important, .random), arguments: typesAsSystemsIntegerAsUnsigned, fuzzers ) func whereDivisorIsPowersOf2( - _ type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt + type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) @@ -127,7 +127,7 @@ import TestKit Tag.List.tags(.generic, .random), arguments: typesAsSystemsIntegerAsUnsigned, fuzzers ) func values( - _ type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt + type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) @@ -148,7 +148,7 @@ import TestKit Tag.List.tags(.generic, .random), arguments: typesAsSystemsIntegerAsUnsigned, fuzzers ) func entropies( - _ type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt + type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) @@ -170,7 +170,7 @@ import TestKit Tag.List.tags(.generic, .important, .random), arguments: typesAsSystemsIntegerAsUnsigned, fuzzers ) func whereDivisorIsPowersOf2( - _ type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt + type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) diff --git a/Tests/UltimathnumTests/Divider+Validation.swift b/Tests/UltimathnumTests/Divider+Validation.swift index 3d6e600c..065ff825 100644 --- a/Tests/UltimathnumTests/Divider+Validation.swift +++ b/Tests/UltimathnumTests/Divider+Validation.swift @@ -26,19 +26,19 @@ import TestKit Tag.List.tags(.generic, .random), arguments: typesAsSystemsIntegerAsUnsigned, fuzzers ) func initialization( - _ type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt + type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) func whereIs(_ type: T.Type) throws where T: SystemsIntegerAsUnsigned { for _ in 0 ..< 32 { - let random = T.entropic(using: &randomness) + let value = T.entropic(using: &randomness) - if let result = Divider(exactly: random) { - try #require(result.div == random) + if let result = Divider(exactly: value) { + try #require((result).div == value) } - Ɣexpect(random, as: Divider.self, if: !random.isZero) + Ɣexpect(value, as: Divider.self, if: !value.isZero) } } } @@ -59,7 +59,7 @@ import TestKit Tag.List.tags(.generic, .random), arguments: typesAsSystemsIntegerAsUnsigned, fuzzers ) func initialization( - _ type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt + type: any SystemsIntegerAsUnsigned.Type, randomness: consuming FuzzerInt ) throws { try whereIs(type) diff --git a/Tests/UltimathnumTests/Divider.swift b/Tests/UltimathnumTests/Divider.swift index 9b29a75e..b2b5f74f 100644 --- a/Tests/UltimathnumTests/Divider.swift +++ b/Tests/UltimathnumTests/Divider.swift @@ -21,73 +21,72 @@ import TestKit //=------------------------------------------------------------------------= @Test( - "Divider: exampels from 1 through 12", + "Divider: examples", + Tag.List.tags(.generic), ParallelizationTrait.serialized, - arguments: [ - - (div: U8 ( 1), mul: U64( 255), add: true, shr: U64( 8 + 0)), - (div: U16( 1), mul: U64( 65535), add: true, shr: U64(16 + 0)), - (div: U32( 1), mul: U64( 4294967295), add: true, shr: U64(32 + 0)), - (div: U64( 1), mul: U64(18446744073709551615), add: true, shr: U64(64 + 0)), - - (div: U8 ( 2), mul: U64( 255), add: true, shr: U64( 8 + 1)), - (div: U16( 2), mul: U64( 65535), add: true, shr: U64(16 + 1)), - (div: U32( 2), mul: U64( 4294967295), add: true, shr: U64(32 + 1)), - (div: U64( 2), mul: U64(18446744073709551615), add: true, shr: U64(64 + 1)), - - (div: U8 ( 3), mul: U64( 171), add: false, shr: U64( 8 + 1)), - (div: U16( 3), mul: U64( 43691), add: false, shr: U64(16 + 1)), - (div: U32( 3), mul: U64( 2863311531), add: false, shr: U64(32 + 1)), - (div: U64( 3), mul: U64(12297829382473034411), add: false, shr: U64(64 + 1)), - - (div: U8 ( 4), mul: U64( 255), add: true, shr: U64( 8 + 2)), - (div: U16( 4), mul: U64( 65535), add: true, shr: U64(16 + 2)), - (div: U32( 4), mul: U64( 4294967295), add: true, shr: U64(32 + 2)), - (div: U64( 4), mul: U64(18446744073709551615), add: true, shr: U64(64 + 2)), - - (div: U8 ( 5), mul: U64( 205), add: false, shr: U64( 8 + 2)), - (div: U16( 5), mul: U64( 52429), add: false, shr: U64(16 + 2)), - (div: U32( 5), mul: U64( 3435973837), add: false, shr: U64(32 + 2)), - (div: U64( 5), mul: U64(14757395258967641293), add: false, shr: U64(64 + 2)), - - (div: U8 ( 6), mul: U64( 171), add: false, shr: U64( 8 + 2)), - (div: U16( 6), mul: U64( 43691), add: false, shr: U64(16 + 2)), - (div: U32( 6), mul: U64( 2863311531), add: false, shr: U64(32 + 2)), - (div: U64( 6), mul: U64(12297829382473034411), add: false, shr: U64(64 + 2)), - - (div: U8 ( 7), mul: U64( 146), add: true, shr: U64( 8 + 2)), - (div: U16( 7), mul: U64( 37449), add: true, shr: U64(16 + 2)), - (div: U32( 7), mul: U64( 2454267026), add: true, shr: U64(32 + 2)), - (div: U64( 7), mul: U64(10540996613548315209), add: true, shr: U64(64 + 2)), - - (div: U8 ( 8), mul: U64( 255), add: true, shr: U64( 8 + 3)), - (div: U16( 8), mul: U64( 65535), add: true, shr: U64(16 + 3)), - (div: U32( 8), mul: U64( 4294967295), add: true, shr: U64(32 + 3)), - (div: U64( 8), mul: U64(18446744073709551615), add: true, shr: U64(64 + 3)), - - (div: U8 ( 9), mul: U64( 227), add: true, shr: U64( 8 + 3)), - (div: U16( 9), mul: U64( 58254), add: true, shr: U64(16 + 3)), - (div: U32( 9), mul: U64( 3817748707), add: true, shr: U64(32 + 3)), - (div: U64( 9), mul: U64(16397105843297379214), add: true, shr: U64(64 + 3)), - - (div: U8 (10), mul: U64( 205), add: false, shr: U64( 8 + 3)), - (div: U16(10), mul: U64( 52429), add: false, shr: U64(16 + 3)), - (div: U32(10), mul: U64( 3435973837), add: false, shr: U64(32 + 3)), - (div: U64(10), mul: U64(14757395258967641293), add: false, shr: U64(64 + 3)), - - (div: U8 (11), mul: U64( 186), add: true, shr: U64( 8 + 3)), - (div: U16(11), mul: U64( 47662), add: true, shr: U64(16 + 3)), - (div: U32(11), mul: U64( 3123612579), add: false, shr: U64(32 + 3)), - (div: U64(11), mul: U64(13415813871788764811), add: true, shr: U64(64 + 3)), - - (div: U8 (12), mul: U64( 171), add: false, shr: U64( 8 + 3)), - (div: U16(12), mul: U64( 43691), add: false, shr: U64(16 + 3)), - (div: U32(12), mul: U64( 2863311531), add: false, shr: U64(32 + 3)), - (div: U64(12), mul: U64(12297829382473034411), add: false, shr: U64(64 + 3)), - - ] as [( - div: any SystemsIntegerAsUnsigned, mul: U64, add: Bool, shr: U64 - )]) func examplesFrom1Through12( + arguments: Array<(any SystemsIntegerAsUnsigned, U64, Bool, U64)>.infer([ + + (U8 ( 1), U64( 255), true, U64( 8 + 0)), + (U16( 1), U64( 65535), true, U64(16 + 0)), + (U32( 1), U64( 4294967295), true, U64(32 + 0)), + (U64( 1), U64(18446744073709551615), true, U64(64 + 0)), + + (U8 ( 2), U64( 255), true, U64( 8 + 1)), + (U16( 2), U64( 65535), true, U64(16 + 1)), + (U32( 2), U64( 4294967295), true, U64(32 + 1)), + (U64( 2), U64(18446744073709551615), true, U64(64 + 1)), + + (U8 ( 3), U64( 171), false, U64( 8 + 1)), + (U16( 3), U64( 43691), false, U64(16 + 1)), + (U32( 3), U64( 2863311531), false, U64(32 + 1)), + (U64( 3), U64(12297829382473034411), false, U64(64 + 1)), + + (U8 ( 4), U64( 255), true, U64( 8 + 2)), + (U16( 4), U64( 65535), true, U64(16 + 2)), + (U32( 4), U64( 4294967295), true, U64(32 + 2)), + (U64( 4), U64(18446744073709551615), true, U64(64 + 2)), + + (U8 ( 5), U64( 205), false, U64( 8 + 2)), + (U16( 5), U64( 52429), false, U64(16 + 2)), + (U32( 5), U64( 3435973837), false, U64(32 + 2)), + (U64( 5), U64(14757395258967641293), false, U64(64 + 2)), + + (U8 ( 6), U64( 171), false, U64( 8 + 2)), + (U16( 6), U64( 43691), false, U64(16 + 2)), + (U32( 6), U64( 2863311531), false, U64(32 + 2)), + (U64( 6), U64(12297829382473034411), false, U64(64 + 2)), + + (U8 ( 7), U64( 146), true, U64( 8 + 2)), + (U16( 7), U64( 37449), true, U64(16 + 2)), + (U32( 7), U64( 2454267026), true, U64(32 + 2)), + (U64( 7), U64(10540996613548315209), true, U64(64 + 2)), + + (U8 ( 8), U64( 255), true, U64( 8 + 3)), + (U16( 8), U64( 65535), true, U64(16 + 3)), + (U32( 8), U64( 4294967295), true, U64(32 + 3)), + (U64( 8), U64(18446744073709551615), true, U64(64 + 3)), + + (U8 ( 9), U64( 227), true, U64( 8 + 3)), + (U16( 9), U64( 58254), true, U64(16 + 3)), + (U32( 9), U64( 3817748707), true, U64(32 + 3)), + (U64( 9), U64(16397105843297379214), true, U64(64 + 3)), + + (U8 (10), U64( 205), false, U64( 8 + 3)), + (U16(10), U64( 52429), false, U64(16 + 3)), + (U32(10), U64( 3435973837), false, U64(32 + 3)), + (U64(10), U64(14757395258967641293), false, U64(64 + 3)), + + (U8 (11), U64( 186), true, U64( 8 + 3)), + (U16(11), U64( 47662), true, U64(16 + 3)), + (U32(11), U64( 3123612579), false, U64(32 + 3)), + (U64(11), U64(13415813871788764811), true, U64(64 + 3)), + + (U8 (12), U64( 171), false, U64( 8 + 3)), + (U16(12), U64( 43691), false, U64(16 + 3)), + (U32(12), U64( 2863311531), false, U64(32 + 3)), + (U64(12), U64(12297829382473034411), false, U64(64 + 3)), + + ])) func examples( div: any SystemsIntegerAsUnsigned, mul: U64, add: Bool, shr: U64 ) throws { @@ -114,73 +113,72 @@ import TestKit //=------------------------------------------------------------------------= @Test( - "Divider: exampels from 1 through 12", + "Divider21: examples", + Tag.List.tags(.generic), ParallelizationTrait.serialized, - arguments: [ - - (div: U8 ( 1), mul: Doublet(low: 255, high: 255), add: true, shr: U64( 16 + 0)), - (div: U16( 1), mul: Doublet(low: 65535, high: 65535), add: true, shr: U64( 32 + 0)), - (div: U32( 1), mul: Doublet(low: 4294967295, high: 4294967295), add: true, shr: U64( 64 + 0)), - (div: U64( 1), mul: Doublet(low: 18446744073709551615, high: 18446744073709551615), add: true, shr: U64(128 + 0)), + arguments: Array<(any SystemsIntegerAsUnsigned, Doublet, Bool, U64)>.infer([ - (div: U8 ( 2), mul: Doublet(low: 255, high: 255), add: true, shr: U64( 16 + 1)), - (div: U16( 2), mul: Doublet(low: 65535, high: 65535), add: true, shr: U64( 32 + 1)), - (div: U32( 2), mul: Doublet(low: 4294967295, high: 4294967295), add: true, shr: U64( 64 + 1)), - (div: U64( 2), mul: Doublet(low: 18446744073709551615, high: 18446744073709551615), add: true, shr: U64(128 + 1)), + (U8 ( 1), Doublet(low: 255, high: 255), true, U64( 16 + 0)), + (U16( 1), Doublet(low: 65535, high: 65535), true, U64( 32 + 0)), + (U32( 1), Doublet(low: 4294967295, high: 4294967295), true, U64( 64 + 0)), + (U64( 1), Doublet(low: 18446744073709551615, high: 18446744073709551615), true, U64(128 + 0)), + + (U8 ( 2), Doublet(low: 255, high: 255), true, U64( 16 + 1)), + (U16( 2), Doublet(low: 65535, high: 65535), true, U64( 32 + 1)), + (U32( 2), Doublet(low: 4294967295, high: 4294967295), true, U64( 64 + 1)), + (U64( 2), Doublet(low: 18446744073709551615, high: 18446744073709551615), true, U64(128 + 1)), - (div: U8 ( 3), mul: Doublet(low: 171, high: 170), add: false, shr: U64( 16 + 1)), - (div: U16( 3), mul: Doublet(low: 43691, high: 43690), add: false, shr: U64( 32 + 1)), - (div: U32( 3), mul: Doublet(low: 2863311531, high: 2863311530), add: false, shr: U64( 64 + 1)), - (div: U64( 3), mul: Doublet(low: 12297829382473034411, high: 12297829382473034410), add: false, shr: U64(128 + 1)), - - (div: U8 ( 4), mul: Doublet(low: 255, high: 255), add: true, shr: U64( 16 + 2)), - (div: U16( 4), mul: Doublet(low: 65535, high: 65535), add: true, shr: U64( 32 + 2)), - (div: U32( 4), mul: Doublet(low: 4294967295, high: 4294967295), add: true, shr: U64( 64 + 2)), - (div: U64( 4), mul: Doublet(low: 18446744073709551615, high: 18446744073709551615), add: true, shr: U64(128 + 2)), + (U8 ( 3), Doublet(low: 171, high: 170), false, U64( 16 + 1)), + (U16( 3), Doublet(low: 43691, high: 43690), false, U64( 32 + 1)), + (U32( 3), Doublet(low: 2863311531, high: 2863311530), false, U64( 64 + 1)), + (U64( 3), Doublet(low: 12297829382473034411, high: 12297829382473034410), false, U64(128 + 1)), + + (U8 ( 4), Doublet(low: 255, high: 255), true, U64( 16 + 2)), + (U16( 4), Doublet(low: 65535, high: 65535), true, U64( 32 + 2)), + (U32( 4), Doublet(low: 4294967295, high: 4294967295), true, U64( 64 + 2)), + (U64( 4), Doublet(low: 18446744073709551615, high: 18446744073709551615), true, U64(128 + 2)), - (div: U8 ( 5), mul: Doublet(low: 205, high: 204), add: false, shr: U64( 16 + 2)), - (div: U16( 5), mul: Doublet(low: 52429, high: 52428), add: false, shr: U64( 32 + 2)), - (div: U32( 5), mul: Doublet(low: 3435973837, high: 3435973836), add: false, shr: U64( 64 + 2)), - (div: U64( 5), mul: Doublet(low: 14757395258967641293, high: 14757395258967641292), add: false, shr: U64(128 + 2)), - - (div: U8 ( 6), mul: Doublet(low: 171, high: 170), add: false, shr: U64( 16 + 2)), - (div: U16( 6), mul: Doublet(low: 43691, high: 43690), add: false, shr: U64( 32 + 2)), - (div: U32( 6), mul: Doublet(low: 2863311531, high: 2863311530), add: false, shr: U64( 64 + 2)), - (div: U64( 6), mul: Doublet(low: 12297829382473034411, high: 12297829382473034410), add: false, shr: U64(128 + 2)), - - (div: U8 ( 7), mul: Doublet(low: 73, high: 146), add: true, shr: U64( 16 + 2)), - (div: U16( 7), mul: Doublet(low: 9362, high: 37449), add: true, shr: U64( 32 + 2)), - (div: U32( 7), mul: Doublet(low: 1227133513, high: 2454267026), add: true, shr: U64( 64 + 2)), - (div: U64( 7), mul: Doublet(low: 2635249153387078802, high: 10540996613548315209), add: true, shr: U64(128 + 2)), - - (div: U8 ( 8), mul: Doublet(low: 255, high: 255), add: true, shr: U64( 16 + 3)), - (div: U16( 8), mul: Doublet(low: 65535, high: 65535), add: true, shr: U64( 32 + 3)), - (div: U32( 8), mul: Doublet(low: 4294967295, high: 4294967295), add: true, shr: U64( 64 + 3)), - (div: U64( 8), mul: Doublet(low: 18446744073709551615, high: 18446744073709551615), add: true, shr: U64(128 + 3)), - - (div: U8 ( 9), mul: Doublet(low: 142, high: 227), add: true, shr: U64( 16 + 3)), - (div: U16( 9), mul: Doublet(low: 14563, high: 58254), add: true, shr: U64( 32 + 3)), - (div: U32( 9), mul: Doublet(low: 2386092942, high: 3817748707), add: true, shr: U64( 64 + 3)), - (div: U64( 9), mul: Doublet(low: 4099276460824344803, high: 16397105843297379214), add: true, shr: U64(128 + 3)), - - (div: U8 (10), mul: Doublet(low: 205, high: 204), add: false, shr: U64( 16 + 3)), - (div: U16(10), mul: Doublet(low: 52429, high: 52428), add: false, shr: U64( 32 + 3)), - (div: U32(10), mul: Doublet(low: 3435973837, high: 3435973836), add: false, shr: U64( 64 + 3)), - (div: U64(10), mul: Doublet(low: 14757395258967641293, high: 14757395258967641292), add: false, shr: U64(128 + 3)), - - (div: U8 (11), mul: Doublet(low: 46, high: 186), add: true, shr: U64( 16 + 3)), - (div: U16(11), mul: Doublet(low: 35747, high: 47662), add: false, shr: U64( 32 + 3)), - (div: U32(11), mul: Doublet(low: 3904515723, high: 3123612578), add: true, shr: U64( 64 + 3)), - (div: U64(11), mul: Doublet(low: 11738837137815169210, high: 13415813871788764811), add: true, shr: U64(128 + 3)), - - (div: U8 (12), mul: Doublet(low: 171, high: 170), add: false, shr: U64( 16 + 3)), - (div: U16(12), mul: Doublet(low: 43691, high: 43690), add: false, shr: U64( 32 + 3)), - (div: U32(12), mul: Doublet(low: 2863311531, high: 2863311530), add: false, shr: U64( 64 + 3)), - (div: U64(12), mul: Doublet(low: 12297829382473034411, high: 12297829382473034410), add: false, shr: U64(128 + 3)), + (U8 ( 5), Doublet(low: 205, high: 204), false, U64( 16 + 2)), + (U16( 5), Doublet(low: 52429, high: 52428), false, U64( 32 + 2)), + (U32( 5), Doublet(low: 3435973837, high: 3435973836), false, U64( 64 + 2)), + (U64( 5), Doublet(low: 14757395258967641293, high: 14757395258967641292), false, U64(128 + 2)), + + (U8 ( 6), Doublet(low: 171, high: 170), false, U64( 16 + 2)), + (U16( 6), Doublet(low: 43691, high: 43690), false, U64( 32 + 2)), + (U32( 6), Doublet(low: 2863311531, high: 2863311530), false, U64( 64 + 2)), + (U64( 6), Doublet(low: 12297829382473034411, high: 12297829382473034410), false, U64(128 + 2)), + + (U8 ( 7), Doublet(low: 73, high: 146), true, U64( 16 + 2)), + (U16( 7), Doublet(low: 9362, high: 37449), true, U64( 32 + 2)), + (U32( 7), Doublet(low: 1227133513, high: 2454267026), true, U64( 64 + 2)), + (U64( 7), Doublet(low: 2635249153387078802, high: 10540996613548315209), true, U64(128 + 2)), + + (U8 ( 8), Doublet(low: 255, high: 255), true, U64( 16 + 3)), + (U16( 8), Doublet(low: 65535, high: 65535), true, U64( 32 + 3)), + (U32( 8), Doublet(low: 4294967295, high: 4294967295), true, U64( 64 + 3)), + (U64( 8), Doublet(low: 18446744073709551615, high: 18446744073709551615), true, U64(128 + 3)), + + (U8 ( 9), Doublet(low: 142, high: 227), true, U64( 16 + 3)), + (U16( 9), Doublet(low: 14563, high: 58254), true, U64( 32 + 3)), + (U32( 9), Doublet(low: 2386092942, high: 3817748707), true, U64( 64 + 3)), + (U64( 9), Doublet(low: 4099276460824344803, high: 16397105843297379214), true, U64(128 + 3)), + + (U8 (10), Doublet(low: 205, high: 204), false, U64( 16 + 3)), + (U16(10), Doublet(low: 52429, high: 52428), false, U64( 32 + 3)), + (U32(10), Doublet(low: 3435973837, high: 3435973836), false, U64( 64 + 3)), + (U64(10), Doublet(low: 14757395258967641293, high: 14757395258967641292), false, U64(128 + 3)), + + (U8 (11), Doublet(low: 46, high: 186), true, U64( 16 + 3)), + (U16(11), Doublet(low: 35747, high: 47662), false, U64( 32 + 3)), + (U32(11), Doublet(low: 3904515723, high: 3123612578), true, U64( 64 + 3)), + (U64(11), Doublet(low: 11738837137815169210, high: 13415813871788764811), true, U64(128 + 3)), + + (U8 (12), Doublet(low: 171, high: 170), false, U64( 16 + 3)), + (U16(12), Doublet(low: 43691, high: 43690), false, U64( 32 + 3)), + (U32(12), Doublet(low: 2863311531, high: 2863311530), false, U64( 64 + 3)), + (U64(12), Doublet(low: 12297829382473034411, high: 12297829382473034410), false, U64(128 + 3)), - ] as [( - div: any SystemsIntegerAsUnsigned, mul: Doublet, add: Bool, shr: U64 - )]) func examplesFrom1Through12( + ])) func examplesFrom1Through12( div: any SystemsIntegerAsUnsigned, mul: Doublet, add: Bool, shr: U64 ) throws { diff --git a/Tests/UltimathnumTests/Doublet.swift b/Tests/UltimathnumTests/Doublet.swift index b6527506..389a842c 100644 --- a/Tests/UltimathnumTests/Doublet.swift +++ b/Tests/UltimathnumTests/Doublet.swift @@ -25,9 +25,11 @@ import TestKit "Doublet: from Source as Base", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func fromSourceAsBase(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func fromSourceAsBase( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 32 { let base = T.entropic(through: Shift.max(or: 255), using: &randomness) diff --git a/Tests/UltimathnumTests/Guarantees/Finite.swift b/Tests/UltimathnumTests/Guarantees/Finite.swift index b90944aa..9dee4f05 100644 --- a/Tests/UltimathnumTests/Guarantees/Finite.swift +++ b/Tests/UltimathnumTests/Guarantees/Finite.swift @@ -23,17 +23,25 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("Finite.init - [entropic]", arguments: typesAsBinaryInteger, fuzzers) - func initByFuzzingEntropies(_ type: any BinaryInteger.Type, randomness: consuming FuzzerInt) { - whereIs(type) + @Test( + "Finite: validation", + Tag.List.tags(.generic, .random), + arguments: typesAsBinaryInteger, fuzzers + ) func validation( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { - func whereIs(_ type: T.Type) where T: BinaryInteger { + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 128 { - let random = T.entropic(through: Shift.max(or: 255), using: &randomness) - Ɣexpect(random, as: Finite.self, if: !random.isInfinite) - if let result = Finite(exactly: random) { - #expect(result.value == random) - #expect(result.magnitude().value == random.magnitude()) + let index = Shift.max(or: 255) + let value = T.entropic(through: index, using: &randomness) + + Ɣexpect(value, as: Finite.self, if: !value.isInfinite) + + if let result = Finite(exactly: value) { + try #require(result.value == value) + try #require(result.magnitude().value == value.magnitude()) } } } diff --git a/Tests/UltimathnumTests/Guarantees/Natural.swift b/Tests/UltimathnumTests/Guarantees/Natural.swift index f9c993a9..3bbb7511 100644 --- a/Tests/UltimathnumTests/Guarantees/Natural.swift +++ b/Tests/UltimathnumTests/Guarantees/Natural.swift @@ -23,17 +23,25 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("Natural.init - [entropic]", arguments: typesAsBinaryInteger, fuzzers) - func initByFuzzingEntropies(_ type: any BinaryInteger.Type, randomness: consuming FuzzerInt) { - whereIs(type) - - func whereIs(_ type: T.Type) where T: BinaryInteger { + @Test( + "Natural: validation", + Tag.List.tags(.generic, .random), + arguments: typesAsBinaryInteger, fuzzers + ) func validation( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 128 { - let random = T.entropic(through: Shift.max(or: 255), using: &randomness) - Ɣexpect(random, as: Natural.self, if: !random.isInfinite && !random.isNegative) - if let result = Natural(exactly: random) { - #expect(result.value == random) - #expect(result.magnitude().value == random.magnitude()) + let index = Shift.max(or: 255) + let value = T.entropic(through: index, using: &randomness) + + Ɣexpect(value, as: Natural.self, if: !value.isInfinite && !value.isNegative) + + if let result = Natural(exactly: value) { + try #require(result.value == value) + try #require(result.magnitude().value == value.magnitude()) } } } diff --git a/Tests/UltimathnumTests/Guarantees/Nonzero.swift b/Tests/UltimathnumTests/Guarantees/Nonzero.swift index 2a7c3add..6df96710 100644 --- a/Tests/UltimathnumTests/Guarantees/Nonzero.swift +++ b/Tests/UltimathnumTests/Guarantees/Nonzero.swift @@ -23,20 +23,28 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("Nonzero.init - [entropic]", arguments: typesAsBinaryInteger, fuzzers) - func initByFuzzingEntropies(_ type: any BinaryInteger.Type, randomness: consuming FuzzerInt) { - whereIs(type) + @Test( + "Nonzero: validation", + Tag.List.tags(.generic, .random), + arguments: typesAsBinaryInteger, fuzzers + ) func validation( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { - func whereIs(_ type: T.Type) where T: BinaryInteger { + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 128 { - let random = T.entropic(through: Shift.max(or: 255), using: &randomness) - Ɣexpect(random, as: Nonzero.self, if: !random.isZero) - if let result = Nonzero(exactly: random) { - #expect(result.value == random) - #expect(result.complement().value == random.complement()) - #expect(result.magnitude ().value == random.magnitude ()) - #expect(Nonzero(raw: Nonzero(T.Signitude(raw: random))).value == random) - #expect(Nonzero(raw: Nonzero(T.Magnitude(raw: random))).value == random) + let index = Shift.max(or: 255) + let value = T.entropic(through: index, using: &randomness) + + Ɣexpect(value, as: Nonzero.self, if: !value.isZero) + + if let result = Nonzero(exactly: value) { + try #require(result.value == value) + try #require(result.complement().value == value.complement()) + try #require(result.magnitude ().value == value.magnitude ()) + try #require(Nonzero(raw: Nonzero(T.Signitude(raw: value))).value == value) + try #require(Nonzero(raw: Nonzero(T.Magnitude(raw: value))).value == value) } } } diff --git a/Tests/UltimathnumTests/Guarantees/Shift.swift b/Tests/UltimathnumTests/Guarantees/Shift.swift index 79b787b4..cb60e91f 100644 --- a/Tests/UltimathnumTests/Guarantees/Shift.swift +++ b/Tests/UltimathnumTests/Guarantees/Shift.swift @@ -23,22 +23,28 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("Shift.instance", arguments: typesAsBinaryIntegerAsUnsigned) - func instances(_ type: any UnsignedInteger.Type) { - whereIs(type) + @Test( + "Shift: instances", + Tag.List.tags(.generic), + arguments: typesAsBinaryIntegerAsUnsigned + ) func instances(type: any UnsignedInteger.Type) throws { - func whereIs(_ type: T.Type) where T: UnsignedInteger { + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: UnsignedInteger { #expect(Shift.min == Shift(Count(raw: 0 as IX))) #expect(Shift.one == Shift(Count(raw: 1 as IX))) #expect(Shift.max == Shift(Count(raw: IX(raw: T.size) - 1))) } } - @Test("Shift.predicate(_:)", arguments: typesAsBinaryIntegerAsUnsigned) - func predicate(_ type: any UnsignedInteger.Type) { - whereIs(type) + @Test( + "Shift: predicate(_:)", + Tag.List.tags(.generic), + arguments: typesAsBinaryIntegerAsUnsigned + ) func predicate(type: any UnsignedInteger.Type) throws { - func whereIs(_ type: T.Type) where T: UnsignedInteger { + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: UnsignedInteger { always: do { #expect( Shift.predicate(Count(raw: 0 as IX))) #expect( Shift.predicate(Count(raw: 1 as IX))) @@ -63,15 +69,16 @@ import TestKit } } - //=------------------------------------------------------------------------= - // MARK: Tests - //=------------------------------------------------------------------------= - - @Test("Shift.init - [entropic]", arguments: typesAsBinaryInteger, fuzzers) - func initByFuzzingEntropies(_ type: any BinaryInteger.Type, randomness: consuming FuzzerInt) { - whereIs(type) + @Test( + "Shift: validation", + Tag.List.tags(.generic, .random), + arguments: typesAsBinaryInteger, fuzzers + ) func validation( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { - func whereIs(_ type: T.Type) where T: BinaryInteger { + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 128 { let random = Count(raw: IX.entropic(using: &randomness)) Ɣexpect(random, as: Shift.self, if: random < T.size) @@ -83,27 +90,32 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("Shift/isZero - load each I8", arguments: typesAsBinaryIntegerAsUnsigned) - func isZero(_ type: any UnsignedInteger.Type) { - whereIs(type) - - func whereIs(_ type: T.Type) where T: UnsignedInteger { + @Test( + "Shift: isZero - loading each I8", + Tag.List.tags(.generic), + arguments: typesAsBinaryIntegerAsUnsigned + ) func isZero(type: any UnsignedInteger.Type) throws { + + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: UnsignedInteger { for relative: IX in I8.all.lazy.map(IX.init) { if let shift = Shift(exactly: Count(raw: relative)) { - #expect(shift.isZero == relative.isZero) + try #require(shift.isZero == relative.isZero) } } } } - @Test("Shift/isInfinite - load each I8", arguments: typesAsBinaryIntegerAsUnsigned) - func isInfinite(_ type: any UnsignedInteger.Type) { - whereIs(type) - - func whereIs(_ type: T.Type) where T: UnsignedInteger { + @Test( + "Shift: isInfinite - loading each I8", + arguments: typesAsBinaryIntegerAsUnsigned + ) func isInfinite(_ type: any UnsignedInteger.Type) throws { + + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: UnsignedInteger { for relative: IX in I8.all.lazy.map(IX.init) { if let shift = Shift(exactly: Count(raw: relative)) { - #expect(shift.isInfinite == relative.isNegative) + try #require(shift.isInfinite == relative.isNegative) } } } @@ -113,15 +125,16 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - /// - 2024-06-15: Checks that the inverse of zero is nil. - @Test("Shift/inverse()", arguments: typesAsBinaryIntegerAsUnsigned) - func inverse(_ type: any UnsignedInteger.Type) { - whereIs(type) + @Test( + "Shift: inverse()", + Tag.List.tags(.generic), + arguments: typesAsBinaryIntegerAsUnsigned + ) func inverse(_ type: any UnsignedInteger.Type) throws { - func whereIs(_ type: T.Type) where T: UnsignedInteger { - //=----------------------------------= - let size = IX(raw: T.size) - //=----------------------------------= + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: UnsignedInteger { + let size = IX(raw: T.size) + #expect(Shift(Count(0 as IX)).inverse() == nil) #expect(Shift(Count(1 as IX)).inverse() == Shift(Count(raw: size - 1))) #expect(Shift(Count(2 as IX)).inverse() == Shift(Count(raw: size - 2))) @@ -149,14 +162,16 @@ import TestKit } } - @Test("Shift/natural()", arguments: typesAsBinaryIntegerAsUnsigned) - func natural(_ type: any UnsignedInteger.Type) { - whereIs(type) + @Test( + "Shift: natural()", + Tag.List.tags(.generic), + arguments: typesAsBinaryIntegerAsUnsigned + ) func natural(type: any UnsignedInteger.Type) throws { - func whereIs(_ type: T.Type) where T: UnsignedInteger { - //=----------------------------------= - let size = IX(raw: T.size) - //=----------------------------------= + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: UnsignedInteger { + let size = IX(raw: T.size) + #expect(Shift(Count(0 as IX)).natural() == Fallible(0 as IX)) #expect(Shift(Count(1 as IX)).natural() == Fallible(1 as IX)) #expect(Shift(Count(2 as IX)).natural() == Fallible(2 as IX)) diff --git a/Tests/UltimathnumTests/TextInt+Exponentiation.swift b/Tests/UltimathnumTests/TextInt+Exponentiation.swift index 800f1089..d892adf2 100644 --- a/Tests/UltimathnumTests/TextInt+Exponentiation.swift +++ b/Tests/UltimathnumTests/TextInt+Exponentiation.swift @@ -20,8 +20,10 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("TextInt.Exponentiation: each radix < 2 is nil", .tags(.exhaustive)) - func eachRadixLessThanTwoIsNil() throws { + @Test( + "TextInt/exponentiation: each radix < 2 is nil", + Tag.List.tags(.exhaustive) + ) func eachRadixLessThanTwoIsNil() throws { for radix: UX in 0 ..< 2 { #expect(throws: TextInt.Error.invalid) { try TextInt.Exponentiation(radix) @@ -29,8 +31,9 @@ import TestKit } } - @Test("TextInt.Exponentiation: each radix in [2, 1024]") - func eachRadixFromTwoThrough1024() throws { + @Test( + "TextInt/exponentiation: each radix in [2, 1024]" + ) func eachRadixFromTwoThrough1024() throws { for radix: UX in 2...1024 { let radixLog2: UX = UX(raw: try #require(radix .ilog2())) let radixLog2Log2 = UX(raw: try #require(radixLog2.ilog2())) diff --git a/Tests/UltimathnumTests/TextInt+Letters.swift b/Tests/UltimathnumTests/TextInt+Letters.swift index 107aa56d..2096e125 100644 --- a/Tests/UltimathnumTests/TextInt+Letters.swift +++ b/Tests/UltimathnumTests/TextInt+Letters.swift @@ -14,34 +14,42 @@ import TestKit // MARK: * Text Int x Letters //*============================================================================* -@Suite(Tag.List.tags(.exhaustive), ParallelizationTrait.serialized) -struct TextIntTestsOnLetters { +@Suite(.serialized) struct TextIntTestsOnLetters { //=------------------------------------------------------------------------= // MARK: Tests //=------------------------------------------------------------------------= - @Test("TextInt.Letters: start", arguments: [ + @Test( + "TextInt/letters: start", + Tag.List.tags(.exhaustive), + arguments: Array<(TextInt.Letters, U8)>.infer([ - (instance: TextInt.Letters.lowercase, start: 97 as U8), - (instance: TextInt.Letters.uppercase, start: 65 as U8), + (TextInt.Letters.lowercase, U8(97)), + (TextInt.Letters.uppercase, U8(65)), - ] as [(TextInt.Letters, U8)]) - func start(instance: TextInt.Letters, start: U8) throws { - #expect(instance.start == start) + ])) func start( + instance: TextInt.Letters, start: U8 + ) throws { + #expect(instance.start == start) let numerals = try TextInt.Numerals(radix: 36, letters: instance) #expect(try numerals.decode(start) == 10) #expect(try numerals.encode(10) == start) } - @Test("TextInt.Letters: uppercase", arguments: [ + @Test( + "TextInt/letters: init(uppercase:)", + Tag.List.tags(.exhaustive), + arguments: Array<(TextInt.Letters, Bool)>.infer([ - (instance: TextInt.Letters.lowercase, uppercase: false), - (instance: TextInt.Letters.uppercase, uppercase: true ), + (TextInt.Letters.lowercase, false), + (TextInt.Letters.uppercase, true ), - ] as [(TextInt.Letters, Bool)]) - func uppercase(instance: TextInt.Letters, uppercase: Bool) { + ])) func uppercase( + instance: TextInt.Letters, uppercase: Bool + ) throws { + #expect((instance == TextInt.Letters (uppercase: uppercase))) #expect((instance == TextInt.Letters .uppercase) == uppercase) } diff --git a/Tests/UltimathnumTests/TextInt+Numerals.swift b/Tests/UltimathnumTests/TextInt+Numerals.swift index 7ddde9be..0f2b047d 100644 --- a/Tests/UltimathnumTests/TextInt+Numerals.swift +++ b/Tests/UltimathnumTests/TextInt+Numerals.swift @@ -36,7 +36,7 @@ private let letters: [TextInt.Letters] = [.lowercase, .uppercase] //=------------------------------------------------------------------------= @Test( - "TextInt.Numerals: decode each byte for each instance", + "TextInt/numerals: decode each byte for each instance", Tag.List.tags(.exhaustive) ) func decodeEachByteForEachInstance() throws { var expectation: [U8: U8] = [:] @@ -78,15 +78,17 @@ private let letters: [TextInt.Letters] = [.lowercase, .uppercase] } @Test( - "TextInt.Numerals: encode each byte for each instance", + "TextInt/numerals: encode each byte for each instance", Tag.List.tags(.exhaustive), - arguments: [ - - (TextInt.Letters.lowercase, [U8](48...57) + [U8](97...122)), - (TextInt.Letters.uppercase, [U8](48...57) + [U8](65...090)), + arguments: Array<(TextInt.Letters, [U8])>.infer([ + + (TextInt.Letters.lowercase, [U8](48...57) + [U8](97...122)), + (TextInt.Letters.uppercase, [U8](48...57) + [U8](65...090)), - ] as [(TextInt.Letters, [U8])]) - func encodeEachByteForEachInstance(letters: TextInt.Letters, expectation: [U8]) throws { + ])) func encodeEachByteForEachInstance( + letters: TextInt.Letters, expectation: [U8] + ) throws { + for radix in radices { let numerals = try TextInt.Numerals(radix: radix, letters: letters) @@ -137,7 +139,9 @@ private let letters: [TextInt.Letters] = [.lowercase, .uppercase] "TextInt.Numerals/initialization: from each radix in [0, 36]", Tag.List.tags(.generic, .exhaustive), arguments: typesAsBinaryInteger - ) func fromEachRadixFromZeroThrough36(type: any BinaryInteger.Type) throws { + ) func fromEachRadixFromZeroThrough36( + type: any BinaryInteger.Type + ) throws { try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { @@ -169,7 +173,9 @@ private let letters: [TextInt.Letters] = [.lowercase, .uppercase] Tag.List.tags(.generic, .random), TimeLimitTrait.timeLimit(TimeLimitTrait.Duration.minutes(3)), arguments: typesAsBinaryInteger, fuzzers - ) func throwsErrorIfRadixIsInvalid(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func throwsErrorIfRadixIsInvalid( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { @@ -197,7 +203,9 @@ private let letters: [TextInt.Letters] = [.lowercase, .uppercase] "TextInt.Numerals/initialization: throws error if radix is one past limit", Tag.List.tags(.generic, .exhaustive), arguments: typesAsBinaryInteger, [-1, 37] as [I8] - ) func throwsErrorIfRadixIsOnePastLimit(type: any BinaryInteger.Type, radix: I8) throws { + ) func throwsErrorIfRadixIsOnePastLimit( + type: any BinaryInteger.Type, radix: I8 + ) throws { try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { diff --git a/Tests/UltimathnumTests/TextInt.swift b/Tests/UltimathnumTests/TextInt.swift index e238e380..7f1da86c 100644 --- a/Tests/UltimathnumTests/TextInt.swift +++ b/Tests/UltimathnumTests/TextInt.swift @@ -39,14 +39,15 @@ import TestKit "TextInt: named instances", Tag.List.tags(.documentation, .exhaustive), ParallelizationTrait.serialized, - arguments: [ + arguments: Array<(TextInt, U8, TextInt.Letters)>.infer([ - (TextInt.binary, 02 as U8, TextInt.Letters.lowercase), - (TextInt.decimal, 10 as U8, TextInt.Letters.lowercase), - (TextInt.hexadecimal, 16 as U8, TextInt.Letters.lowercase), + (TextInt.binary, U8(02), TextInt.Letters.lowercase), + (TextInt.decimal, U8(10), TextInt.Letters.lowercase), + (TextInt.hexadecimal, U8(16), TextInt.Letters.lowercase), - ] as [(TextInt, U8, TextInt.Letters)] - ) func namedInstances(instance: TextInt, radix: U8, letters: TextInt.Letters) throws { + ])) func namedInstances( + instance: TextInt, radix: U8, letters: TextInt.Letters + ) throws { #expect(instance.radix == radix) #expect(instance.letters == letters) } @@ -77,7 +78,9 @@ import TestKit "TextInt: from each radix in [2, 36]", Tag.List.tags(.exhaustive, .generic), arguments: typesAsBinaryInteger - ) func fromEachRadixFromTwoThrough36(type: any BinaryInteger.Type) throws { + ) func fromEachRadixFromTwoThrough36( + type: any BinaryInteger.Type + ) throws { try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { @@ -109,7 +112,9 @@ import TestKit Tag.List.tags(.generic, .random), TimeLimitTrait.timeLimit(TimeLimitTrait.Duration.minutes(3)), arguments: typesAsBinaryInteger, fuzzers - ) func throwsErrorIfRadixIsInvalid(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { + ) func throwsErrorIfRadixIsInvalid( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { @@ -137,7 +142,9 @@ import TestKit "TextInt: throws error if radix is one past limit", Tag.List.tags(.generic, .exhaustive), arguments: typesAsBinaryInteger, [1, 37] as [I8] - ) func throwsErrorIfRadixIsOnePastLimit(type: any BinaryInteger.Type, radix: I8) throws { + ) func throwsErrorIfRadixIsOnePastLimit( + type: any BinaryInteger.Type, radix: I8 + ) throws { try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { diff --git a/Tests/UltimathnumTests/Triplet.swift b/Tests/UltimathnumTests/Triplet.swift index 4937442f..add49574 100644 --- a/Tests/UltimathnumTests/Triplet.swift +++ b/Tests/UltimathnumTests/Triplet.swift @@ -25,9 +25,11 @@ import TestKit "Triplet: from Source as Base", Tag.List.tags(.generic, .random), arguments: typesAsBinaryInteger, fuzzers - ) func fromSourceAsBase(type: any BinaryInteger.Type, randomness: consuming FuzzerInt) throws { - try whereIs(type) + ) func fromSourceAsBase( + type: any BinaryInteger.Type, randomness: consuming FuzzerInt + ) throws { + try whereIs(type) func whereIs(_ type: T.Type) throws where T: BinaryInteger { for _ in 0 ..< 32 { let base = T.entropic(through: Shift.max(or: 255), using: &randomness) diff --git a/Tests/UltimathnumTests/Utilities/Utilities+Text.swift b/Tests/UltimathnumTests/Utilities/Utilities+Text.swift index 62dc899f..9a36200f 100644 --- a/Tests/UltimathnumTests/Utilities/Utilities+Text.swift +++ b/Tests/UltimathnumTests/Utilities/Utilities+Text.swift @@ -16,7 +16,7 @@ import TestKit // MARK: * Utilities x Text //*============================================================================* -@Suite struct UtilitiesTestsOnText { +@Suite(.serialized) struct UtilitiesTestsOnText { typealias I8L = InfiniInt typealias U8L = InfiniInt @@ -25,46 +25,64 @@ import TestKit // MARK: Tests //=------------------------------------------------------------------------= - @Test("Utilities/text: BinaryInteger/bitstring()") - func bitstring() { - #expect(I8 ( 2).bitstring() == "01000000") - #expect(I8 ( 1).bitstring() == "10000000") - #expect(I8 ( 0).bitstring() == "00000000") - #expect(I8 (~0).bitstring() == "11111111") - #expect(I8 (~1).bitstring() == "01111111") - #expect(I8 (~2).bitstring() == "10111111") + @Test( + "Utilities/text: Bit/ascii", + Tag.List.tags(.exhaustive), + arguments: Array<(Bit, U8)>.infer([ + + (Bit.zero, U8(UInt8(ascii: "0"))), + (Bit.one, U8(UInt8(ascii: "1"))), + + ])) func ascii(instance: Bit, expectation: U8) { + #expect(instance.ascii == expectation) + } + + @Test( + "Utilities/text: BinaryInteger/bitstring()", + Tag.List.tags(.generic), + arguments: Array<(any BinaryInteger.Type, IXL, String)>.infer([ + + (I8 .self, IXL( 2), String("01000000")), + (I8 .self, IXL( 1), String("10000000")), + (I8 .self, IXL( 0), String("00000000")), + (I8 .self, IXL(~0), String("11111111")), + (I8 .self, IXL(~1), String("01111111")), + (I8 .self, IXL(~2), String("10111111")), - #expect(U8 ( 2).bitstring() == "01000000") - #expect(U8 ( 1).bitstring() == "10000000") - #expect(U8 ( 0).bitstring() == "00000000") - #expect(U8 (~0).bitstring() == "11111111") - #expect(U8 (~1).bitstring() == "01111111") - #expect(U8 (~2).bitstring() == "10111111") + (U8 .self, IXL( 2), String("01000000")), + (U8 .self, IXL( 1), String("10000000")), + (U8 .self, IXL( 0), String("00000000")), + (U8 .self, IXL(~0), String("11111111")), + (U8 .self, IXL(~1), String("01111111")), + (U8 .self, IXL(~2), String("10111111")), - #expect(I8L( 2).bitstring() == "01000000...0") - #expect(I8L( 1).bitstring() == "10000000...0") - #expect(I8L( 0).bitstring() == "...0") - #expect(I8L(~0).bitstring() == "...1") - #expect(I8L(~1).bitstring() == "01111111...1") - #expect(I8L(~2).bitstring() == "10111111...1") + (I8L.self, IXL( 2), String("01000000...0")), + (I8L.self, IXL( 1), String("10000000...0")), + (I8L.self, IXL( 0), String( "...0")), + (I8L.self, IXL(~0), String( "...1")), + (I8L.self, IXL(~1), String("01111111...1")), + (I8L.self, IXL(~2), String("10111111...1")), - #expect(U8L( 2).bitstring() == "01000000...0") - #expect(U8L( 1).bitstring() == "10000000...0") - #expect(U8L( 0).bitstring() == "...0") - #expect(U8L(~0).bitstring() == "...1") - #expect(U8L(~1).bitstring() == "01111111...1") - #expect(U8L(~2).bitstring() == "10111111...1") + (U8L.self, IXL( 2), String("01000000...0")), + (U8L.self, IXL( 1), String("10000000...0")), + (U8L.self, IXL( 0), String( "...0")), + (U8L.self, IXL(~0), String( "...1")), + (U8L.self, IXL(~1), String("01111111...1")), + (U8L.self, IXL(~2), String("10111111...1")), - #expect(I32( 0x55555555).bitstring() == "10101010101010101010101010101010") - #expect(I32(~0x55555555).bitstring() == "01010101010101010101010101010101") + (I32.self, IXL( 0x55555555), String("10101010101010101010101010101010")), + (I32.self, IXL(~0x55555555), String("01010101010101010101010101010101")), - #expect(U32( 0x55555555).bitstring() == "10101010101010101010101010101010") - #expect(U32(~0x55555555).bitstring() == "01010101010101010101010101010101") - } - - @Test("Utilities/text: Bit/ascii") - func ascii() { - #expect(Bit.zero.ascii == U8(UInt8(ascii: "0"))) - #expect(Bit.one .ascii == U8(UInt8(ascii: "1"))) + (U32.self, IXL( 0x55555555), String("10101010101010101010101010101010")), + (U32.self, IXL(~0x55555555), String("01010101010101010101010101010101")), + + ])) func bitstring( + type: any BinaryInteger.Type, source: IXL, expectation: String + ) throws { + + try whereIs(type) + func whereIs(_ type: T.Type) throws where T: BinaryInteger { + try #require(T(load: source).bitstring() == expectation) + } } }