Skip to content

Commit

Permalink
Rewrite TripleInt.swift tests (#110).
Browse files Browse the repository at this point in the history
  • Loading branch information
oscbyspro committed Nov 4, 2024
1 parent fd442f5 commit d92d248
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 190 deletions.
8 changes: 4 additions & 4 deletions Sources/TestKit2/Global+Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ import CoreKit
//=----------------------------------------------------------------------------=

public let typesAsCoreInteger: [any CoreInteger.Type] = {
typesAsCoreIntegersAsSigned +
typesAsCoreIntegersAsUnsigned
typesAsCoreIntegerAsSigned +
typesAsCoreIntegerAsUnsigned
}()

public let typesAsCoreIntegerAsByte: [any CoreInteger.Type] = [
I8.self,
U8.self,
]

public let typesAsCoreIntegersAsSigned: [any CoreIntegerAsSigned.Type] = [
public let typesAsCoreIntegerAsSigned: [any CoreIntegerAsSigned.Type] = [
IX.self, I8.self, I16.self, I32.self, I64.self,
]

public let typesAsCoreIntegersAsUnsigned: [any CoreIntegerAsUnsigned.Type] = [
public let typesAsCoreIntegerAsUnsigned: [any CoreIntegerAsUnsigned.Type] = [
UX.self, U8.self, U16.self, U32.self, U64.self,
]

Expand Down
16 changes: 8 additions & 8 deletions Tests/CoreKitTests/DataInteger+Addition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import TestKit2
@Test(
"DataInt/increment(by:plus:) - 0-by-0-plus-bit",
Tag.List.tags(.exhaustive, .generic),
arguments: typesAsCoreIntegersAsUnsigned
arguments: typesAsCoreIntegerAsUnsigned
) func incrementByNonePlusBit(type: any CoreIntegerAsUnsigned.Type) throws {
try whereIs(type)

Expand All @@ -37,7 +37,7 @@ import TestKit2
@Test(
"DataInt/decrement(by:plus:) - 0-by-0-plus-bit",
Tag.List.tags(.exhaustive, .generic),
arguments: typesAsCoreIntegersAsUnsigned
arguments: typesAsCoreIntegerAsUnsigned
) func decrementByNonePlusBit(type: any CoreIntegerAsUnsigned.Type) throws {
try whereIs(type)

Expand All @@ -54,7 +54,7 @@ import TestKit2
@Test(
"DataInt/decrement(by:plus:) - [bidirectional][uniform]",
Tag.List.tags(.generic, .random),
arguments: typesAsCoreIntegersAsUnsigned, fuzzers
arguments: typesAsCoreIntegerAsUnsigned, fuzzers
) func incrementByManyPlusBit(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand Down Expand Up @@ -86,7 +86,7 @@ import TestKit2
@Test(
"DataInt/decrement(by:plus:) - [bidirectional][uniform]",
Tag.List.tags(.generic, .random),
arguments: typesAsCoreIntegersAsUnsigned, fuzzers
arguments: typesAsCoreIntegerAsUnsigned, fuzzers
) func decrementByManyPlusBit(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand Down Expand Up @@ -122,7 +122,7 @@ import TestKit2
@Test(
"DataInt/increment(by:times:plus:) - [bidirectional][uniform]",
Tag.List.tags(.generic, .random),
arguments: typesAsCoreIntegersAsUnsigned, fuzzers
arguments: typesAsCoreIntegerAsUnsigned, fuzzers
) func incrementByManyTimesSomePlusSome(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand Down Expand Up @@ -159,7 +159,7 @@ import TestKit2
@Test(
"DataInt/decrement(by:times:plus:) - [bidirectional][uniform]",
Tag.List.tags(.generic, .random),
arguments: typesAsCoreIntegersAsUnsigned, fuzzers
arguments: typesAsCoreIntegerAsUnsigned, fuzzers
) func decrementByManyTimesSomePlusSome(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand Down Expand Up @@ -200,7 +200,7 @@ import TestKit2
@Test(
"DataInt/incrementSameSize(repeating:plus:) - [bidirectional][uniform]",
Tag.List.tags(.generic, .random),
arguments: typesAsCoreIntegersAsUnsigned, fuzzers
arguments: typesAsCoreIntegerAsUnsigned, fuzzers
) func incrementByRepsPlusBit(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand Down Expand Up @@ -229,7 +229,7 @@ import TestKit2
@Test(
"DataInt/decrementSameSize(repeating:plus:) - [bidirectional][uniform]",
Tag.List.tags(.generic, .random),
arguments: typesAsCoreIntegersAsUnsigned, fuzzers
arguments: typesAsCoreIntegerAsUnsigned, fuzzers
) func decrementByRepsPlusBit(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand Down
4 changes: 2 additions & 2 deletions Tests/CoreKitTests/DataInteger+Comparison.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import TestKit2
@Test(
"DataInt/signum()",
Tag.List.tags(.generic),
arguments: typesAsCoreIntegersAsUnsigned
arguments: typesAsCoreIntegerAsUnsigned
) func signum(_ type: any CoreIntegerAsUnsigned.Type) {
whereIs(type)

Expand Down Expand Up @@ -93,7 +93,7 @@ import TestKit2
@Test(
"DataInt/compared(to:) - ignores body appendix extensions",
Tag.List.tags(.generic),
arguments: typesAsCoreIntegersAsUnsigned
arguments: typesAsCoreIntegerAsUnsigned
) func comparisonIgnoresBodyAppendixExtensions(_ type: any CoreIntegerAsUnsigned.Type) {
whereIs(type)

Expand Down
8 changes: 4 additions & 4 deletions Tests/CoreKitTests/DataInteger+Count.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import TestKit2
// MARK: Tests
//=------------------------------------------------------------------------=

@Test("DataInt/size()", arguments: typesAsCoreIntegersAsUnsigned)
@Test("DataInt/size()", arguments: typesAsCoreIntegerAsUnsigned)
func size(type: any CoreIntegerAsUnsigned.Type) {
whereIs(type)

Expand Down Expand Up @@ -48,7 +48,7 @@ import TestKit2
}
}

@Test("DataInt/count(_:)", arguments: typesAsCoreIntegersAsUnsigned)
@Test("DataInt/count(_:)", arguments: typesAsCoreIntegerAsUnsigned)
func count(type: any CoreIntegerAsUnsigned.Type) {
whereIs(type)

Expand Down Expand Up @@ -84,7 +84,7 @@ import TestKit2
}
}

@Test("DataInt/ascending(_:)", arguments: typesAsCoreIntegersAsUnsigned)
@Test("DataInt/ascending(_:)", arguments: typesAsCoreIntegerAsUnsigned)
func ascending(type: any CoreIntegerAsUnsigned.Type) {
whereIs(type)

Expand Down Expand Up @@ -134,7 +134,7 @@ import TestKit2
}
}

@Test("DataInt/descending(_:)", arguments: typesAsCoreIntegersAsUnsigned)
@Test("DataInt/descending(_:)", arguments: typesAsCoreIntegerAsUnsigned)
func descending(type: any CoreIntegerAsUnsigned.Type) {
whereIs(type)

Expand Down
6 changes: 3 additions & 3 deletions Tests/CoreKitTests/DataInteger+Division.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import TestKit2
// MARK: Tests x Many ÷ Some
//=------------------------------------------------------------------------=

@Test("DataInt/division(_:) - 0-by-1 [uniform]", arguments: typesAsCoreIntegersAsUnsigned, fuzzers)
@Test("DataInt/division(_:) - 0-by-1 [uniform]", arguments: typesAsCoreIntegerAsUnsigned, fuzzers)
func division01(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand All @@ -34,7 +34,7 @@ import TestKit2
}
}

@Test("DataInt/division(_:) - 1-by-1 [uniform]", arguments: typesAsCoreIntegersAsUnsigned, fuzzers)
@Test("DataInt/division(_:) - 1-by-1 [uniform]", arguments: typesAsCoreIntegerAsUnsigned, fuzzers)
func division11(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand All @@ -54,7 +54,7 @@ import TestKit2
}
}

@Test("DataInt/division(_:) - X-by-1 [uniform]", arguments: typesAsCoreIntegersAsUnsigned, fuzzers)
@Test("DataInt/division(_:) - X-by-1 [uniform]", arguments: typesAsCoreIntegerAsUnsigned, fuzzers)
func divisionX1(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand Down
4 changes: 2 additions & 2 deletions Tests/CoreKitTests/DataInteger+Elements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import TestKit2
// MARK: Tests
//=------------------------------------------------------------------------=

@Test("DataInt/buffer()", arguments: typesAsCoreIntegersAsUnsigned)
@Test("DataInt/buffer()", arguments: typesAsCoreIntegerAsUnsigned)
func buffer(type: any CoreIntegerAsUnsigned.Type) throws {
whereIs(type)

Expand Down Expand Up @@ -75,7 +75,7 @@ import TestKit2
}
}

@Test("DataInt/subscript(_:) - [uniform]", arguments: typesAsCoreIntegersAsUnsigned, fuzzers)
@Test("DataInt/subscript(_:) - [uniform]", arguments: typesAsCoreIntegerAsUnsigned, fuzzers)
func element(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) {
whereIs(type)

Expand Down
2 changes: 1 addition & 1 deletion Tests/CoreKitTests/DataInteger+Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import TestKit2
// MARK: Tests
//=------------------------------------------------------------------------=

@Test("DataInt.capacity", .tags(.generic), arguments: typesAsCoreIntegersAsUnsigned)
@Test("DataInt.capacity", .tags(.generic), arguments: typesAsCoreIntegerAsUnsigned)
func capacity(_ type: any CoreIntegerAsUnsigned.Type) throws {
try whereIs(type)

Expand Down
10 changes: 5 additions & 5 deletions Tests/CoreKitTests/DataInteger+Multiplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import TestKit2
@Test(
"DataInt/initialize(to:times:plus:) - none-by-none-plus-none",
Tag.List.tags(.exhaustive, .generic),
arguments: typesAsCoreIntegersAsUnsigned
arguments: typesAsCoreIntegerAsUnsigned
) func multiplicationOfNoneByNonePlusNone(type: any CoreIntegerAsUnsigned.Type) throws {
try whereIs(type)

Expand All @@ -38,7 +38,7 @@ import TestKit2
@Test(
"DataInt/initialize(to:times:plus:) - some-by-none-plus-some [uniform]",
Tag.List.tags(.generic, .random),
arguments: typesAsCoreIntegersAsUnsigned, fuzzers
arguments: typesAsCoreIntegerAsUnsigned, fuzzers
) func multiplicationOfSomeByNonePlusSome(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand All @@ -55,7 +55,7 @@ import TestKit2
@Test(
"DataInt/initialize(to:times:plus:) - some-by-some-plus-some [uniform]",
Tag.List.tags(.generic, .random),
arguments: typesAsCoreIntegersAsUnsigned, fuzzers
arguments: typesAsCoreIntegerAsUnsigned, fuzzers
) func multiplicationOfSomeBySomePlusSome(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand All @@ -82,7 +82,7 @@ import TestKit2
@Test(
"DataInt/initialize(to:times:plus:) - many-by-some-plus-some [uniform]",
Tag.List.tags(.generic, .random),
arguments: typesAsCoreIntegersAsUnsigned, fuzzers
arguments: typesAsCoreIntegerAsUnsigned, fuzzers
) func multiplicationOfManyBySomePlusSome(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand All @@ -107,7 +107,7 @@ import TestKit2
@Test(
"DataInt/initialize(to:times:plus:) - many-by-many-plus-some [uniform]",
Tag.List.tags(.generic, .random),
arguments: typesAsCoreIntegersAsUnsigned, fuzzers
arguments: typesAsCoreIntegerAsUnsigned, fuzzers
) func multiplicationOfManyByManyPlusSome(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand Down
8 changes: 4 additions & 4 deletions Tests/CoreKitTests/DataInteger+Partition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import TestKit2
// MARK: Tests
//=------------------------------------------------------------------------=

@Test("DataInt/split(at:)", .tags(.generic), arguments: typesAsCoreIntegersAsUnsigned)
@Test("DataInt/split(at:)", .tags(.generic), arguments: typesAsCoreIntegerAsUnsigned)
func split(_ type: any CoreIntegerAsUnsigned.Type) {
whereIs(type)

Expand Down Expand Up @@ -68,7 +68,7 @@ import TestKit2
// MARK: Tests
//=------------------------------------------------------------------------=

@Test("DataInt/body", .tags(.generic), arguments: typesAsCoreIntegersAsUnsigned)
@Test("DataInt/body", .tags(.generic), arguments: typesAsCoreIntegerAsUnsigned)
func body(_ type: any CoreIntegerAsUnsigned.Type) {
whereIs(type)

Expand All @@ -92,7 +92,7 @@ import TestKit2
// MARK: Tests
//=------------------------------------------------------------------------=

@Test("DataInt/normalized()", .tags(.generic), arguments: typesAsCoreIntegersAsUnsigned)
@Test("DataInt/normalized()", .tags(.generic), arguments: typesAsCoreIntegerAsUnsigned)
func normalized(_ type: any CoreIntegerAsUnsigned.Type) {
whereIs(type)

Expand Down Expand Up @@ -150,7 +150,7 @@ import TestKit2
// MARK: Tests
//=------------------------------------------------------------------------=

@Test("DataInt/prefix(_:)", .tags(.generic), arguments: typesAsCoreIntegersAsUnsigned)
@Test("DataInt/prefix(_:)", .tags(.generic), arguments: typesAsCoreIntegerAsUnsigned)
func prefix(_ type: any CoreIntegerAsUnsigned.Type) {
whereIs(type)

Expand Down
4 changes: 2 additions & 2 deletions Tests/CoreKitTests/DataInteger+Shift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import TestKit2
@Test(
"DataInt/shift: upshift(major:minor:environment:)",
Tag.List.tags(.generic, .random),
arguments: typesAsCoreIntegersAsUnsigned, fuzzers
arguments: typesAsCoreIntegerAsUnsigned, fuzzers
) func upshift(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand Down Expand Up @@ -58,7 +58,7 @@ import TestKit2
@Test(
"DataInt/shift: downshift(major:minor:environment:)",
Tag.List.tags(.generic, .random),
arguments: typesAsCoreIntegersAsUnsigned, fuzzers
arguments: typesAsCoreIntegerAsUnsigned, fuzzers
) func downshift(type: any CoreIntegerAsUnsigned.Type, randomness: consuming FuzzerInt) throws {
try whereIs(type)

Expand Down
24 changes: 2 additions & 22 deletions Tests/DoubleIntKitTests/DoubleInt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,6 @@ import TestKit2
// MARK: Metadata
//=------------------------------------------------------------------------=

static let types: [any SystemsInteger.Type] = {
typesAsSigned +
typesAsUnsigned
}()

static let typesAsSigned: [any SystemsIntegerAsSigned.Type] = [
I8x2.self,
I8x4.self,
IXx2.self,
IXx4.self,
]

static let typesAsUnsigned: [any SystemsIntegerAsUnsigned.Type] = [
U8x2.self,
U8x4.self,
UXx2.self,
UXx4.self,
]

static let bases: [any SystemsInteger.Type] = {
basesAsSigned +
basesAsUnsigned
Expand Down Expand Up @@ -91,15 +72,14 @@ import TestKit2
}
}


@Test("DoubleInt: bitcasting", .tags(.generic, .random), arguments: Self.bases, fuzzers)
func bitcasting(base: any SystemsInteger.Type, randomness: consuming FuzzerInt) throws {

try whereIs(base)
func whereIs<B>(_ base: B.Type) throws where B: SystemsInteger {
typealias T = DoubleInt<B>

for _ in 0 ..< 32 {
for _ in 0 ..< 8 {
let low = T.Low .random(using: &randomness)
let high = T.High.random(using: &randomness)
let full = T(low: low, high: high)
Expand All @@ -120,7 +100,7 @@ import TestKit2
func whereIs<B>(_ base: B.Type) throws where B: SystemsInteger {
typealias T = DoubleInt<B>

for _ in 0 ..< 32 {
for _ in 0 ..< 8 {
let low = T.Low .random(using: &randomness)
let high = T.High.random(using: &randomness)

Expand Down
10 changes: 5 additions & 5 deletions Tests/DoubleIntKitTests/TripleInt+Addition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import TestKit
// MARK: * Triple Int x Addition
//*============================================================================*

extension TripleIntTests {
final class TripleIntTestsOnAddition: XCTestCase {

//=------------------------------------------------------------------------=
// MARK: Tests
Expand Down Expand Up @@ -56,11 +56,11 @@ extension TripleIntTests {
Test().same(Y(low: ~3, mid: ~5, high: ~0).plus(X(low: 4, high: 5)), F(Y(low: 0, mid: 0, high: 0), error: true))
}

for base in Self.basesAsSigned {
for base in TripleIntTests.basesAsSigned {
whereTheBaseIsSigned(base)
}

for base in Self.basesAsUnsigned {
for base in TripleIntTests.basesAsUnsigned {
whereTheBaseIsUnsigned(base)
}
}
Expand Down Expand Up @@ -100,11 +100,11 @@ extension TripleIntTests {
Test().same(Y(low: ~3, mid: ~5, high: ~6).plus(Y(low: 4, mid: 5, high: 6)), F(Y(low: 0, mid: 0, high: 0), error: true))
}

for base in Self.basesAsSigned {
for base in TripleIntTests.basesAsSigned {
whereTheBaseIsSigned(base)
}

for base in Self.basesAsUnsigned {
for base in TripleIntTests.basesAsUnsigned {
whereTheBaseIsUnsigned(base)
}
}
Expand Down
Loading

0 comments on commit d92d248

Please sign in to comment.