Skip to content

Commit

Permalink
Skip rework of TripleInt tests (#124).
Browse files Browse the repository at this point in the history
  • Loading branch information
oscbyspro committed Nov 4, 2024
1 parent d92d248 commit 46af546
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 411 deletions.
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ let package = Package(
),
.testTarget(
name: "CoreKitTests",
dependencies: ["CoreKit", "TestKit", "TestKit2"]
dependencies: ["CoreKit", "TestKit2"]
),
.target(
name: "DoubleIntKit",
dependencies: ["CoreKit"]
),
.testTarget(
name: "DoubleIntKitTests",
dependencies: ["DoubleIntKit", "TestKit", "TestKit2"]
dependencies: ["DoubleIntKit", "TestKit2"]
),
.target(
name: "FibonacciKit",
dependencies: ["CoreKit"]
),
.testTarget(
name: "FibonacciKitTests",
dependencies: ["DoubleIntKit", "FibonacciKit", "InfiniIntKit", "TestKit"]
dependencies: ["DoubleIntKit", "FibonacciKit", "InfiniIntKit", "TestKit", "TestKit2"]
),
.target(
name: "InfiniIntKit",
Expand All @@ -108,7 +108,7 @@ let package = Package(
),
.testTarget(
name: "RandomIntKitTests",
dependencies: ["RandomIntKit", "TestKit", "TestKit2"]
dependencies: ["RandomIntKit", "TestKit2"]
),
.target(
name: "StdlibIntKit",
Expand Down
7 changes: 5 additions & 2 deletions Sources/TestKit2/Models/Tag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ extension Tag {
/// Inspired by an open-source project.
@Tag public static var opensource: Self

/// Happening, done, or chosen by chance.
@Tag public static var random: Self

/// Something that may be regained.
@Tag public static var recoverable: Self

/// Happening, done, or chosen by chance.
@Tag public static var random: Self
/// A task.
@Tag public static var todo: Self

/// Not officially authorized or confirmed.
@Tag public static var unofficial: Self
Expand Down
194 changes: 131 additions & 63 deletions Tests/DoubleIntKitTests/TripleInt+Addition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,103 +9,171 @@

import CoreKit
import DoubleIntKit
import TestKit
import TestKit2

//*============================================================================*
// MARK: * Triple Int x Addition
//*============================================================================*

final class TripleIntTestsOnAddition: XCTestCase {
@Suite struct TripleIntTestsOnAddition {

//=------------------------------------------------------------------------=
// MARK: Tests
//=------------------------------------------------------------------------=

func testAddition32B() {
func whereTheBaseIsSigned<B>(_ type: B.Type) where B: SystemsInteger & SignedInteger {
@Test(
"TripleInt: addition 323 (#124)",
Tag.List.tags(.todo),
arguments: TripleIntTests.bases
) func addition323(_ base: any SystemsInteger.Type) throws {

try whereIs(base)
func whereIs<B>(_ type: B.Type) throws where B: SystemsInteger {
typealias X = DoubleInt<B>.Magnitude
typealias Y = TripleInt<B>
typealias F = Fallible<TripleInt<B>>
//=----------------------------------=
let x = B.msb
//=----------------------------------=
Test().same(Y(low: 0, mid: 0, high: 0).plus(X(low: ~4, high: ~5)), F(Y(low: ~4, mid: ~5, high: 0)))
Test().same(Y(low: 1, mid: 2, high: 3).plus(X(low: ~4, high: ~5)), F(Y(low: ~3, mid: ~3, high: 3)))
Test().same(Y(low: ~1, mid: ~2, high: ~3).plus(X(low: 4, high: 5)), F(Y(low: 2, mid: 3, high: ~2)))
Test().same(Y(low: ~0, mid: ~0, high: ~0).plus(X(low: 4, high: 5)), F(Y(low: 3, mid: 5, high: 0)))

Test().same(Y(low: 4, mid: 5, high: x).plus(X(low: ~4, high: ~5)), F(Y(low: ~0, mid: ~0, high: x)))
Test().same(Y(low: 5, mid: 5, high: x).plus(X(low: ~4, high: ~5)), F(Y(low: 0, mid: 0, high: x ^ 1)))
Test().same(Y(low: ~4, mid: ~5, high: ~x).plus(X(low: 4, high: 5)), F(Y(low: ~0, mid: ~0, high: ~x)))
Test().same(Y(low: ~3, mid: ~5, high: ~x).plus(X(low: 4, high: 5)), F(Y(low: 0, mid: 0, high: x), error: true))
if B.isSigned {
try #require(Y(low: 0, mid: 0, high: 0).plus(X(low: ~4, high: ~5)) == F(Y(low: ~4, mid: ~5, high: 0)))
try #require(Y(low: 1, mid: 2, high: 3).plus(X(low: ~4, high: ~5)) == F(Y(low: ~3, mid: ~3, high: 3)))
try #require(Y(low: ~1, mid: ~2, high: ~3).plus(X(low: 4, high: 5)) == F(Y(low: 2, mid: 3, high: ~2)))
try #require(Y(low: ~0, mid: ~0, high: ~0).plus(X(low: 4, high: 5)) == F(Y(low: 3, mid: 5, high: 0)))

try #require(Y(low: 4, mid: 5, high: x).plus(X(low: ~4, high: ~5)) == F(Y(low: ~0, mid: ~0, high: x)))
try #require(Y(low: 5, mid: 5, high: x).plus(X(low: ~4, high: ~5)) == F(Y(low: 0, mid: 0, high: x ^ 1)))
try #require(Y(low: ~4, mid: ~5, high: ~x).plus(X(low: 4, high: 5)) == F(Y(low: ~0, mid: ~0, high: ~x)))
try #require(Y(low: ~3, mid: ~5, high: ~x).plus(X(low: 4, high: 5)) == F(Y(low: 0, mid: 0, high: x), error: true))
} else {
try #require(Y(low: 0, mid: 0, high: 0).plus(X(low: ~4, high: ~5)) == F(Y(low: ~4, mid: ~5, high: 0)))
try #require(Y(low: 1, mid: 2, high: 3).plus(X(low: ~4, high: ~5)) == F(Y(low: ~3, mid: ~3, high: 3)))
try #require(Y(low: ~1, mid: ~2, high: ~3).plus(X(low: 4, high: 5)) == F(Y(low: 2, mid: 3, high: ~2)))
try #require(Y(low: ~0, mid: ~0, high: ~0).plus(X(low: 4, high: 5)) == F(Y(low: 3, mid: 5, high: 0), error: true))

try #require(Y(low: 4, mid: 5, high: ~0).plus(X(low: ~4, high: ~5)) == F(Y(low: ~0, mid: ~0, high: ~0)))
try #require(Y(low: 5, mid: 5, high: ~0).plus(X(low: ~4, high: ~5)) == F(Y(low: 0, mid: 0, high: 0), error: true))
try #require(Y(low: ~4, mid: ~5, high: ~0).plus(X(low: 4, high: 5)) == F(Y(low: ~0, mid: ~0, high: ~0)))
try #require(Y(low: ~3, mid: ~5, high: ~0).plus(X(low: 4, high: 5)) == F(Y(low: 0, mid: 0, high: 0), error: true))
}
}
}

@Test(
"TripleInt: subtraction 323 (#124)",
Tag.List.tags(.todo),
arguments: TripleIntTests.bases
) func subtraction323(_ base: any SystemsInteger.Type) throws {

func whereTheBaseIsUnsigned<B>(_ type: B.Type) where B: SystemsInteger & UnsignedInteger {
try whereIs(base)
func whereIs<B>(_ type: B.Type) throws where B: SystemsInteger {
typealias X = DoubleInt<B>.Magnitude
typealias Y = TripleInt<B>
typealias F = Fallible<TripleInt<B>>

Test().same(Y(low: 0, mid: 0, high: 0).plus(X(low: ~4, high: ~5)), F(Y(low: ~4, mid: ~5, high: 0)))
Test().same(Y(low: 1, mid: 2, high: 3).plus(X(low: ~4, high: ~5)), F(Y(low: ~3, mid: ~3, high: 3)))
Test().same(Y(low: ~1, mid: ~2, high: ~3).plus(X(low: 4, high: 5)), F(Y(low: 2, mid: 3, high: ~2)))
Test().same(Y(low: ~0, mid: ~0, high: ~0).plus(X(low: 4, high: 5)), F(Y(low: 3, mid: 5, high: 0), error: true))

Test().same(Y(low: 4, mid: 5, high: ~0).plus(X(low: ~4, high: ~5)), F(Y(low: ~0, mid: ~0, high: ~0)))
Test().same(Y(low: 5, mid: 5, high: ~0).plus(X(low: ~4, high: ~5)), F(Y(low: 0, mid: 0, high: 0), error: true))
Test().same(Y(low: ~4, mid: ~5, high: ~0).plus(X(low: 4, high: 5)), F(Y(low: ~0, mid: ~0, high: ~0)))
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 TripleIntTests.basesAsSigned {
whereTheBaseIsSigned(base)
}

for base in TripleIntTests.basesAsUnsigned {
whereTheBaseIsUnsigned(base)
//=----------------------------------=
let x = B.msb
//=----------------------------------=
if B.isSigned {
try #require(Y(low: 0, mid: 0, high: 0).minus(X(low: ~4, high: ~5)) == F(Y(low: 5, mid: 5, high: ~0)))
try #require(Y(low: 1, mid: 2, high: 3).minus(X(low: ~4, high: ~5)) == F(Y(low: 6, mid: 7, high: 2)))
try #require(Y(low: ~1, mid: ~2, high: ~3).minus(X(low: 4, high: 5)) == F(Y(low: ~5, mid: ~7, high: ~3)))
try #require(Y(low: ~0, mid: ~0, high: ~0).minus(X(low: 4, high: 5)) == F(Y(low: ~4, mid: ~5, high: ~0)))

try #require(Y(low: ~4, mid: ~5, high: ~x).minus(X(low: ~4, high: ~5)) == F(Y(low: 0, mid: 0, high: ~x)))
try #require(Y(low: ~5, mid: ~5, high: ~x).minus(X(low: ~4, high: ~5)) == F(Y(low: ~0, mid: ~0, high: ~x ^ 1)))
try #require(Y(low: 4, mid: 5, high: x).minus(X(low: 4, high: 5)) == F(Y(low: 0, mid: 0, high: x)))
try #require(Y(low: 3, mid: 5, high: x).minus(X(low: 4, high: 5)) == F(Y(low: ~0, mid: ~0, high: ~x), error: true))
} else {
try #require(Y(low: 0, mid: 0, high: 0).minus(X(low: ~4, high: ~5)) == F(Y(low: 5, mid: 5, high: ~0), error: true))
try #require(Y(low: 1, mid: 2, high: 3).minus(X(low: ~4, high: ~5)) == F(Y(low: 6, mid: 7, high: 2)))
try #require(Y(low: ~1, mid: ~2, high: ~3).minus(X(low: 4, high: 5)) == F(Y(low: ~5, mid: ~7, high: ~3)))
try #require(Y(low: ~0, mid: ~0, high: ~0).minus(X(low: 4, high: 5)) == F(Y(low: ~4, mid: ~5, high: ~0)))

try #require(Y(low: ~4, mid: ~5, high: 0).minus(X(low: ~4, high: ~5)) == F(Y(low: 0, mid: 0, high: 0)))
try #require(Y(low: ~5, mid: ~5, high: 0).minus(X(low: ~4, high: ~5)) == F(Y(low: ~0, mid: ~0, high: ~0), error: true))
try #require(Y(low: 4, mid: 5, high: 0).minus(X(low: 4, high: 5)) == F(Y(low: 0, mid: 0, high: 0)))
try #require(Y(low: 3, mid: 5, high: 0).minus(X(low: 4, high: 5)) == F(Y(low: ~0, mid: ~0, high: ~0), error: true))
}
}
}

func testAddition33B() {
func whereTheBaseIsSigned<B>(_ type: B.Type) where B: SystemsInteger & SignedInteger {
@Test(
"TripleInt: addition 333 (#124)",
Tag.List.tags(.todo),
arguments: TripleIntTests.bases
) func addition333(base: any SystemsInteger.Type) throws {

try whereIs(base)
func whereIs<B>(_ type: B.Type) throws where B: SystemsInteger {
typealias X = DoubleInt<B>
typealias Y = TripleInt<B>
typealias F = Fallible<TripleInt<B>>
//=----------------------------------=
let x = B.msb
let x = B.msb
let y = B.msb + 6
let z = ~B.msb - 6
//=----------------------------------=
Test().same(Y(low: 0, mid: 0, high: 0).plus(Y(low: ~4, mid: ~5, high: ~6)), F(Y(low: ~4, mid: ~5, high: ~6)))
Test().same(Y(low: 1, mid: 2, high: 3).plus(Y(low: ~4, mid: ~5, high: ~6)), F(Y(low: ~3, mid: ~3, high: ~3)))
Test().same(Y(low: ~1, mid: ~2, high: ~3).plus(Y(low: 4, mid: 5, high: 6)), F(Y(low: 2, mid: 3, high: 3)))
Test().same(Y(low: ~0, mid: ~0, high: ~0).plus(Y(low: 4, mid: 5, high: 6)), F(Y(low: 3, mid: 5, high: 6)))

Test().same(Y(low: 5, mid: 5, high: x + 6).plus(Y(low: ~4, mid: ~5, high: ~6)), F(Y(low: 0, mid: 0, high: x)))
Test().same(Y(low: 4, mid: 5, high: x + 6).plus(Y(low: ~4, mid: ~5, high: ~6)), F(Y(low: ~0, mid: ~0, high: ~x), error: true))
Test().same(Y(low: ~4, mid: ~5, high: ~x - 6).plus(Y(low: 4, mid: 5, high: 6)), F(Y(low: ~0, mid: ~0, high: ~x)))
Test().same(Y(low: ~3, mid: ~5, high: ~x - 6).plus(Y(low: 4, mid: 5, high: 6)), F(Y(low: 0, mid: 0, high: x), error: true))
if B.isSigned {
try #require(Y(low: 0, mid: 0, high: 0).plus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: ~4, mid: ~5, high: ~6)))
try #require(Y(low: 1, mid: 2, high: 3).plus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: ~3, mid: ~3, high: ~3)))
try #require(Y(low: ~1, mid: ~2, high: ~3).plus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: 2, mid: 3, high: 3)))
try #require(Y(low: ~0, mid: ~0, high: ~0).plus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: 3, mid: 5, high: 6)))

try #require(Y(low: 5, mid: 5, high: y).plus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: 0, mid: 0, high: x)))
try #require(Y(low: 4, mid: 5, high: y).plus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: ~0, mid: ~0, high: ~x), error: true))
try #require(Y(low: ~4, mid: ~5, high: z).plus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: ~0, mid: ~0, high: ~x)))
try #require(Y(low: ~3, mid: ~5, high: z).plus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: 0, mid: 0, high: x), error: true))
} else {
try #require(Y(low: 0, mid: 0, high: 0).plus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: ~4, mid: ~5, high: ~6)))
try #require(Y(low: 1, mid: 2, high: 3).plus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: ~3, mid: ~3, high: ~3)))
try #require(Y(low: ~1, mid: ~2, high: ~3).plus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: 2, mid: 3, high: 3), error: true))
try #require(Y(low: ~0, mid: ~0, high: ~0).plus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: 3, mid: 5, high: 6), error: true))

try #require(Y(low: 4, mid: 5, high: 6).plus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: ~0, mid: ~0, high: ~0)))
try #require(Y(low: 5, mid: 5, high: 6).plus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: 0, mid: 0, high: 0), error: true))
try #require(Y(low: ~4, mid: ~5, high: ~6).plus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: ~0, mid: ~0, high: ~0)))
try #require(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))
}
}
}

@Test(
"TripleInt: subtraction 333 (#124)",
Tag.List.tags(.todo),
arguments: TripleIntTests.bases
) func subtraction333(_ base: any SystemsInteger.Type) throws {

func whereTheBaseIsUnsigned<B>(_ type: B.Type) where B: SystemsInteger & UnsignedInteger {
try whereIs(base)
func whereIs<B>(_ type: B.Type) throws where B: SystemsInteger {
typealias X = DoubleInt<B>
typealias Y = TripleInt<B>
typealias F = Fallible<TripleInt<B>>

Test().same(Y(low: 0, mid: 0, high: 0).plus(Y(low: ~4, mid: ~5, high: ~6)), F(Y(low: ~4, mid: ~5, high: ~6)))
Test().same(Y(low: 1, mid: 2, high: 3).plus(Y(low: ~4, mid: ~5, high: ~6)), F(Y(low: ~3, mid: ~3, high: ~3)))
Test().same(Y(low: ~1, mid: ~2, high: ~3).plus(Y(low: 4, mid: 5, high: 6)), F(Y(low: 2, mid: 3, high: 3), error: true))
Test().same(Y(low: ~0, mid: ~0, high: ~0).plus(Y(low: 4, mid: 5, high: 6)), F(Y(low: 3, mid: 5, high: 6), error: true))

Test().same(Y(low: 4, mid: 5, high: 6).plus(Y(low: ~4, mid: ~5, high: ~6)), F(Y(low: ~0, mid: ~0, high: ~0)))
Test().same(Y(low: 5, mid: 5, high: 6).plus(Y(low: ~4, mid: ~5, high: ~6)), F(Y(low: 0, mid: 0, high: 0), error: true))
Test().same(Y(low: ~4, mid: ~5, high: ~6).plus(Y(low: 4, mid: 5, high: 6)), F(Y(low: ~0, mid: ~0, high: ~0)))
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 TripleIntTests.basesAsSigned {
whereTheBaseIsSigned(base)
}

for base in TripleIntTests.basesAsUnsigned {
whereTheBaseIsUnsigned(base)
//=----------------------------------=
let x = B.msb
let y = B.msb + 6
let z = ~B.msb - 6
//=----------------------------------=
if B.isSigned {
try #require(Y(low: 0, mid: 0, high: 0).minus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: 5, mid: 5, high: 6)))
try #require(Y(low: 1, mid: 2, high: 3).minus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: 6, mid: 7, high: 9)))
try #require(Y(low: ~1, mid: ~2, high: ~3).minus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: ~5, mid: ~7, high: ~9)))
try #require(Y(low: ~0, mid: ~0, high: ~0).minus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: ~4, mid: ~5, high: ~6)))

try #require(Y(low: ~5, mid: ~5, high: z).minus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: ~0, mid: ~0, high: ~x)))
try #require(Y(low: ~4, mid: ~5, high: z).minus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: 0, mid: 0, high: x), error: true))
try #require(Y(low: 4, mid: 5, high: y).minus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: 0, mid: 0, high: x)))
try #require(Y(low: 3, mid: 5, high: y).minus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: ~0, mid: ~0, high: ~x), error: true))
} else {
try #require(Y(low: 0, mid: 0, high: 0).minus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: 5, mid: 5, high: 6), error: true))
try #require(Y(low: 1, mid: 2, high: 3).minus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: 6, mid: 7, high: 9), error: true))
try #require(Y(low: ~1, mid: ~2, high: ~3).minus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: ~5, mid: ~7, high: ~9)))
try #require(Y(low: ~0, mid: ~0, high: ~0).minus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: ~4, mid: ~5, high: ~6)))

try #require(Y(low: ~4, mid: ~5, high: ~6).minus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: 0, mid: 0, high: 0)))
try #require(Y(low: ~5, mid: ~5, high: ~6).minus(Y(low: ~4, mid: ~5, high: ~6)) == F(Y(low: ~0, mid: ~0, high: ~0), error: true))
try #require(Y(low: 4, mid: 5, high: 6).minus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: 0, mid: 0, high: 0)))
try #require(Y(low: 3, mid: 5, high: 6).minus(Y(low: 4, mid: 5, high: 6)) == F(Y(low: ~0, mid: ~0, high: ~0), error: true))
}
}
}
}
Loading

0 comments on commit 46af546

Please sign in to comment.