diff --git a/Package.swift b/Package.swift index a7c36ea3..2f9ff23b 100644 --- a/Package.swift +++ b/Package.swift @@ -68,7 +68,7 @@ let package = Package( ), .testTarget( name: "CoreKitTests", - dependencies: ["CoreKit", "TestKit", "TestKit2"] + dependencies: ["CoreKit", "TestKit2"] ), .target( name: "DoubleIntKit", @@ -76,7 +76,7 @@ let package = Package( ), .testTarget( name: "DoubleIntKitTests", - dependencies: ["DoubleIntKit", "TestKit", "TestKit2"] + dependencies: ["DoubleIntKit", "TestKit2"] ), .target( name: "FibonacciKit", @@ -84,7 +84,7 @@ let package = Package( ), .testTarget( name: "FibonacciKitTests", - dependencies: ["DoubleIntKit", "FibonacciKit", "InfiniIntKit", "TestKit"] + dependencies: ["DoubleIntKit", "FibonacciKit", "InfiniIntKit", "TestKit", "TestKit2"] ), .target( name: "InfiniIntKit", @@ -108,7 +108,7 @@ let package = Package( ), .testTarget( name: "RandomIntKitTests", - dependencies: ["RandomIntKit", "TestKit", "TestKit2"] + dependencies: ["RandomIntKit", "TestKit2"] ), .target( name: "StdlibIntKit", diff --git a/Sources/TestKit2/Models/Tag.swift b/Sources/TestKit2/Models/Tag.swift index cb4ecd37..532f90c5 100644 --- a/Sources/TestKit2/Models/Tag.swift +++ b/Sources/TestKit2/Models/Tag.swift @@ -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 diff --git a/Tests/DoubleIntKitTests/TripleInt+Addition.swift b/Tests/DoubleIntKitTests/TripleInt+Addition.swift index dd6e3245..87180d63 100644 --- a/Tests/DoubleIntKitTests/TripleInt+Addition.swift +++ b/Tests/DoubleIntKitTests/TripleInt+Addition.swift @@ -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(_ 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(_ type: B.Type) throws where B: SystemsInteger { typealias X = DoubleInt.Magnitude typealias Y = TripleInt typealias F = Fallible> //=----------------------------------= 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(_ type: B.Type) where B: SystemsInteger & UnsignedInteger { + try whereIs(base) + func whereIs(_ type: B.Type) throws where B: SystemsInteger { typealias X = DoubleInt.Magnitude typealias Y = TripleInt typealias F = Fallible> - - 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(_ 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(_ type: B.Type) throws where B: SystemsInteger { typealias X = DoubleInt typealias Y = TripleInt typealias F = Fallible> //=----------------------------------= - 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(_ type: B.Type) where B: SystemsInteger & UnsignedInteger { + try whereIs(base) + func whereIs(_ type: B.Type) throws where B: SystemsInteger { typealias X = DoubleInt typealias Y = TripleInt typealias F = Fallible> - - 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)) + } } } } diff --git a/Tests/DoubleIntKitTests/TripleInt+Bitwise.swift b/Tests/DoubleIntKitTests/TripleInt+Bitwise.swift index 8e4970fe..5d0eab74 100644 --- a/Tests/DoubleIntKitTests/TripleInt+Bitwise.swift +++ b/Tests/DoubleIntKitTests/TripleInt+Bitwise.swift @@ -9,64 +9,38 @@ import CoreKit import DoubleIntKit -import TestKit +import TestKit2 //*============================================================================* // MARK: * Triple Int x Bitwise //*============================================================================* -final class TripleIntTestsOnBitwise: XCTestCase { +@Suite struct TripleIntTestsOnBitwise { //=------------------------------------------------------------------------= // MARK: Tests //=------------------------------------------------------------------------= - func testComplement() { - func whereTheBaseIs(_ base: B.Type) where B: SystemsInteger { + @Test( + "TripleInt: complement (#124)", + Tag.List.tags(.todo), + arguments: TripleIntTests.bases + ) func complement(base: any SystemsInteger.Type) throws { + + try whereIs(base) + func whereIs(_ base: B.Type) throws where B: SystemsInteger { typealias T = TripleInt typealias F = Fallible - Test().complement(T(low: 0, mid: 0, high: 00000), false, F(T(low: ~0, mid: ~0, high: ~00000))) - Test().complement(T(low: 0, mid: 0, high: 00000), true, F(T(low: 0, mid: 0, high: 00000), error: !B.isSigned)) - Test().complement(T(low: 1, mid: 2, high: 00003), false, F(T(low: ~1, mid: ~2, high: ~00003))) - Test().complement(T(low: 1, mid: 2, high: 00003), true, F(T(low: ~0, mid: ~2, high: ~00003))) + try #require(T(low: 0, mid: 0, high: 00000).complement(false) == F(T(low: ~0, mid: ~0, high: ~00000))) + try #require(T(low: 0, mid: 0, high: 00000).complement(true ) == F(T(low: 0, mid: 0, high: 00000), error: !B.isSigned)) + try #require(T(low: 1, mid: 2, high: 00003).complement(false) == F(T(low: ~1, mid: ~2, high: ~00003))) + try #require(T(low: 1, mid: 2, high: 00003).complement(true ) == F(T(low: ~0, mid: ~2, high: ~00003))) - Test().complement(T(low: ~0, mid: ~0, high: ~B.msb), false, F(T(low: 0, mid: 0, high: B.msb))) - Test().complement(T(low: ~0, mid: ~0, high: ~B.msb), true, F(T(low: 1, mid: 0, high: B.msb))) - Test().complement(T(low: 0, mid: 0, high: B.msb), false, F(T(low: ~0, mid: ~0, high: ~B.msb))) - Test().complement(T(low: 0, mid: 0, high: B.msb), true, F(T(low: 0, mid: 0, high: B.msb), error: B.isSigned)) - } - - for base in TripleIntTests.bases { - whereTheBaseIs(base) - } - } -} - -//=----------------------------------------------------------------------------= -// MARK: + Assertions -//=----------------------------------------------------------------------------= - -private extension Test { - - //=------------------------------------------------------------------------= - // MARK: Utilities - //=------------------------------------------------------------------------= - - func complement(_ instance: TripleInt, _ increment: Bool, _ expectation: Fallible>) { - same(instance.complement(increment), expectation, "complement [0]") - - if increment { - same(instance.complement(), expectation.value, "complement [1]") - } else { - let roundtrip = instance.complement(increment).value.complement(increment).value - same(roundtrip, instance, "complement [2]") - } - - if increment, instance.high.isNegative { - same(TripleInt(raw: instance.magnitude()), expectation.value, "complement [3]") - } else { - same(TripleInt(raw: instance.magnitude()), instance, "complement [4]") + try #require(T(low: ~0, mid: ~0, high: ~B.msb).complement(false) == F(T(low: 0, mid: 0, high: B.msb))) + try #require(T(low: ~0, mid: ~0, high: ~B.msb).complement(true ) == F(T(low: 1, mid: 0, high: B.msb))) + try #require(T(low: 0, mid: 0, high: B.msb).complement(false) == F(T(low: ~0, mid: ~0, high: ~B.msb))) + try #require(T(low: 0, mid: 0, high: B.msb).complement(true ) == F(T(low: 0, mid: 0, high: B.msb), error: B.isSigned)) } } } diff --git a/Tests/DoubleIntKitTests/TripleInt+Comparison.swift b/Tests/DoubleIntKitTests/TripleInt+Comparison.swift index 7d732d0c..190a400a 100644 --- a/Tests/DoubleIntKitTests/TripleInt+Comparison.swift +++ b/Tests/DoubleIntKitTests/TripleInt+Comparison.swift @@ -9,157 +9,150 @@ import CoreKit import DoubleIntKit -import TestKit +import TestKit2 //*============================================================================* // MARK: * Triple Int x Comparison //*============================================================================* -final class TripleIntTestsOnComparison: XCTestCase { +@Suite struct TripleIntTestsOnComparison { //=------------------------------------------------------------------------= // MARK: Tests //=------------------------------------------------------------------------= - func testComparison() { - func whereTheBaseIs(_ base: B.Type) where B: SystemsInteger { + @Test( + "TripleInt: comparison (#124)", + Tag.List.tags(.todo), + arguments: TripleIntTests.bases + ) func comparison(base: any SystemsInteger.Type) throws { + + try whereIs(base) + func whereIs(_ base: B.Type) throws where B: SystemsInteger { typealias T = TripleInt //=----------------------------------= - let a1 = T(low: 1, mid: 1, high: 1) - let b1 = T(low: ~1, mid: ~1, high: ~1) + let a1 = T(low: 1, mid: 1, high: 1) + let b1 = T(low: ~1, mid: ~1, high: ~1) //=----------------------------------= - Test().comparison(T(low: 0, mid: 0, high: 0), a1, Signum.negative) - Test().comparison(T(low: 1, mid: 0, high: 0), a1, Signum.negative) - Test().comparison(T(low: 2, mid: 0, high: 0), a1, Signum.negative) - Test().comparison(T(low: 0, mid: 1, high: 0), a1, Signum.negative) - Test().comparison(T(low: 1, mid: 1, high: 0), a1, Signum.negative) - Test().comparison(T(low: 2, mid: 1, high: 0), a1, Signum.negative) - Test().comparison(T(low: 0, mid: 2, high: 0), a1, Signum.negative) - Test().comparison(T(low: 1, mid: 2, high: 0), a1, Signum.negative) - Test().comparison(T(low: 2, mid: 2, high: 0), a1, Signum.negative) - Test().comparison(T(low: 0, mid: 0, high: 1), a1, Signum.negative) - Test().comparison(T(low: 1, mid: 0, high: 1), a1, Signum.negative) - Test().comparison(T(low: 2, mid: 0, high: 1), a1, Signum.negative) - Test().comparison(T(low: 0, mid: 1, high: 1), a1, Signum.negative) - Test().comparison(T(low: 1, mid: 1, high: 1), a1, Signum.zero) - Test().comparison(T(low: 2, mid: 1, high: 1), a1, Signum.positive) - Test().comparison(T(low: 0, mid: 2, high: 1), a1, Signum.positive) - Test().comparison(T(low: 1, mid: 2, high: 1), a1, Signum.positive) - Test().comparison(T(low: 2, mid: 2, high: 1), a1, Signum.positive) - Test().comparison(T(low: 0, mid: 0, high: 2), a1, Signum.positive) - Test().comparison(T(low: 1, mid: 0, high: 2), a1, Signum.positive) - Test().comparison(T(low: 2, mid: 0, high: 2), a1, Signum.positive) - Test().comparison(T(low: 0, mid: 1, high: 2), a1, Signum.positive) - Test().comparison(T(low: 1, mid: 1, high: 2), a1, Signum.positive) - Test().comparison(T(low: 2, mid: 1, high: 2), a1, Signum.positive) - Test().comparison(T(low: 0, mid: 2, high: 2), a1, Signum.positive) - Test().comparison(T(low: 1, mid: 2, high: 2), a1, Signum.positive) - Test().comparison(T(low: 2, mid: 2, high: 2), a1, Signum.positive) + try Ɣrequire(T(low: 0, mid: 0, high: 0), equals: a1, is: Signum.negative) + try Ɣrequire(T(low: 1, mid: 0, high: 0), equals: a1, is: Signum.negative) + try Ɣrequire(T(low: 2, mid: 0, high: 0), equals: a1, is: Signum.negative) + try Ɣrequire(T(low: 0, mid: 1, high: 0), equals: a1, is: Signum.negative) + try Ɣrequire(T(low: 1, mid: 1, high: 0), equals: a1, is: Signum.negative) + try Ɣrequire(T(low: 2, mid: 1, high: 0), equals: a1, is: Signum.negative) + try Ɣrequire(T(low: 0, mid: 2, high: 0), equals: a1, is: Signum.negative) + try Ɣrequire(T(low: 1, mid: 2, high: 0), equals: a1, is: Signum.negative) + try Ɣrequire(T(low: 2, mid: 2, high: 0), equals: a1, is: Signum.negative) + try Ɣrequire(T(low: 0, mid: 0, high: 1), equals: a1, is: Signum.negative) + try Ɣrequire(T(low: 1, mid: 0, high: 1), equals: a1, is: Signum.negative) + try Ɣrequire(T(low: 2, mid: 0, high: 1), equals: a1, is: Signum.negative) + try Ɣrequire(T(low: 0, mid: 1, high: 1), equals: a1, is: Signum.negative) + try Ɣrequire(T(low: 1, mid: 1, high: 1), equals: a1, is: Signum.zero) + try Ɣrequire(T(low: 2, mid: 1, high: 1), equals: a1, is: Signum.positive) + try Ɣrequire(T(low: 0, mid: 2, high: 1), equals: a1, is: Signum.positive) + try Ɣrequire(T(low: 1, mid: 2, high: 1), equals: a1, is: Signum.positive) + try Ɣrequire(T(low: 2, mid: 2, high: 1), equals: a1, is: Signum.positive) + try Ɣrequire(T(low: 0, mid: 0, high: 2), equals: a1, is: Signum.positive) + try Ɣrequire(T(low: 1, mid: 0, high: 2), equals: a1, is: Signum.positive) + try Ɣrequire(T(low: 2, mid: 0, high: 2), equals: a1, is: Signum.positive) + try Ɣrequire(T(low: 0, mid: 1, high: 2), equals: a1, is: Signum.positive) + try Ɣrequire(T(low: 1, mid: 1, high: 2), equals: a1, is: Signum.positive) + try Ɣrequire(T(low: 2, mid: 1, high: 2), equals: a1, is: Signum.positive) + try Ɣrequire(T(low: 0, mid: 2, high: 2), equals: a1, is: Signum.positive) + try Ɣrequire(T(low: 1, mid: 2, high: 2), equals: a1, is: Signum.positive) + try Ɣrequire(T(low: 2, mid: 2, high: 2), equals: a1, is: Signum.positive) //=----------------------------------= - Test().comparison(T(low: 0, mid: 0, high: 0), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 1, mid: 0, high: 0), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 2, mid: 0, high: 0), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 0, mid: 1, high: 0), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 1, mid: 1, high: 0), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 2, mid: 1, high: 0), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 0, mid: 2, high: 0), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 1, mid: 2, high: 0), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 2, mid: 2, high: 0), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 0, mid: 0, high: 1), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 1, mid: 0, high: 1), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 2, mid: 0, high: 1), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 0, mid: 1, high: 1), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 1, mid: 1, high: 1), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 2, mid: 1, high: 1), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 0, mid: 2, high: 1), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 1, mid: 2, high: 1), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 2, mid: 2, high: 1), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 0, mid: 0, high: 2), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 1, mid: 0, high: 2), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 2, mid: 0, high: 2), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 0, mid: 1, high: 2), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 1, mid: 1, high: 2), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 2, mid: 1, high: 2), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 0, mid: 2, high: 2), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 1, mid: 2, high: 2), b1, -Signum(Sign(B.isSigned))) - Test().comparison(T(low: 2, mid: 2, high: 2), b1, -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 0, mid: 0, high: 0), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 1, mid: 0, high: 0), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 2, mid: 0, high: 0), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 0, mid: 1, high: 0), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 1, mid: 1, high: 0), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 2, mid: 1, high: 0), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 0, mid: 2, high: 0), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 1, mid: 2, high: 0), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 2, mid: 2, high: 0), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 0, mid: 0, high: 1), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 1, mid: 0, high: 1), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 2, mid: 0, high: 1), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 0, mid: 1, high: 1), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 1, mid: 1, high: 1), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 2, mid: 1, high: 1), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 0, mid: 2, high: 1), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 1, mid: 2, high: 1), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 2, mid: 2, high: 1), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 0, mid: 0, high: 2), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 1, mid: 0, high: 2), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 2, mid: 0, high: 2), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 0, mid: 1, high: 2), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 1, mid: 1, high: 2), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 2, mid: 1, high: 2), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 0, mid: 2, high: 2), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 1, mid: 2, high: 2), equals: b1, is: -Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: 2, mid: 2, high: 2), equals: b1, is: -Signum(Sign(B.isSigned))) //=----------------------------------= - Test().comparison(T(low: ~0, mid: ~0, high: ~0), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~1, mid: ~0, high: ~0), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~2, mid: ~0, high: ~0), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~0, mid: ~1, high: ~0), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~1, mid: ~1, high: ~0), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~2, mid: ~1, high: ~0), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~0, mid: ~2, high: ~0), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~1, mid: ~2, high: ~0), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~2, mid: ~2, high: ~0), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~0, mid: ~0, high: ~1), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~1, mid: ~0, high: ~1), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~2, mid: ~0, high: ~1), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~0, mid: ~1, high: ~1), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~1, mid: ~1, high: ~1), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~2, mid: ~1, high: ~1), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~0, mid: ~2, high: ~1), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~1, mid: ~2, high: ~1), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~2, mid: ~2, high: ~1), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~0, mid: ~0, high: ~2), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~1, mid: ~0, high: ~2), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~2, mid: ~0, high: ~2), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~0, mid: ~1, high: ~2), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~1, mid: ~1, high: ~2), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~2, mid: ~1, high: ~2), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~0, mid: ~2, high: ~2), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~1, mid: ~2, high: ~2), a1, Signum(Sign(B.isSigned))) - Test().comparison(T(low: ~2, mid: ~2, high: ~2), a1, Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~0, mid: ~0, high: ~0), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~1, mid: ~0, high: ~0), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~2, mid: ~0, high: ~0), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~0, mid: ~1, high: ~0), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~1, mid: ~1, high: ~0), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~2, mid: ~1, high: ~0), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~0, mid: ~2, high: ~0), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~1, mid: ~2, high: ~0), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~2, mid: ~2, high: ~0), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~0, mid: ~0, high: ~1), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~1, mid: ~0, high: ~1), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~2, mid: ~0, high: ~1), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~0, mid: ~1, high: ~1), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~1, mid: ~1, high: ~1), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~2, mid: ~1, high: ~1), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~0, mid: ~2, high: ~1), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~1, mid: ~2, high: ~1), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~2, mid: ~2, high: ~1), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~0, mid: ~0, high: ~2), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~1, mid: ~0, high: ~2), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~2, mid: ~0, high: ~2), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~0, mid: ~1, high: ~2), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~1, mid: ~1, high: ~2), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~2, mid: ~1, high: ~2), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~0, mid: ~2, high: ~2), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~1, mid: ~2, high: ~2), equals: a1, is: Signum(Sign(B.isSigned))) + try Ɣrequire(T(low: ~2, mid: ~2, high: ~2), equals: a1, is: Signum(Sign(B.isSigned))) //=----------------------------------= - Test().comparison(T(low: ~0, mid: ~0, high: ~0), b1, Signum.positive) - Test().comparison(T(low: ~1, mid: ~0, high: ~0), b1, Signum.positive) - Test().comparison(T(low: ~2, mid: ~0, high: ~0), b1, Signum.positive) - Test().comparison(T(low: ~0, mid: ~1, high: ~0), b1, Signum.positive) - Test().comparison(T(low: ~1, mid: ~1, high: ~0), b1, Signum.positive) - Test().comparison(T(low: ~2, mid: ~1, high: ~0), b1, Signum.positive) - Test().comparison(T(low: ~0, mid: ~2, high: ~0), b1, Signum.positive) - Test().comparison(T(low: ~1, mid: ~2, high: ~0), b1, Signum.positive) - Test().comparison(T(low: ~2, mid: ~2, high: ~0), b1, Signum.positive) - Test().comparison(T(low: ~0, mid: ~0, high: ~1), b1, Signum.positive) - Test().comparison(T(low: ~1, mid: ~0, high: ~1), b1, Signum.positive) - Test().comparison(T(low: ~2, mid: ~0, high: ~1), b1, Signum.positive) - Test().comparison(T(low: ~0, mid: ~1, high: ~1), b1, Signum.positive) - Test().comparison(T(low: ~1, mid: ~1, high: ~1), b1, Signum.zero) - Test().comparison(T(low: ~2, mid: ~1, high: ~1), b1, Signum.negative) - Test().comparison(T(low: ~0, mid: ~2, high: ~1), b1, Signum.negative) - Test().comparison(T(low: ~1, mid: ~2, high: ~1), b1, Signum.negative) - Test().comparison(T(low: ~2, mid: ~2, high: ~1), b1, Signum.negative) - Test().comparison(T(low: ~0, mid: ~0, high: ~2), b1, Signum.negative) - Test().comparison(T(low: ~1, mid: ~0, high: ~2), b1, Signum.negative) - Test().comparison(T(low: ~2, mid: ~0, high: ~2), b1, Signum.negative) - Test().comparison(T(low: ~0, mid: ~1, high: ~2), b1, Signum.negative) - Test().comparison(T(low: ~1, mid: ~1, high: ~2), b1, Signum.negative) - Test().comparison(T(low: ~2, mid: ~1, high: ~2), b1, Signum.negative) - Test().comparison(T(low: ~0, mid: ~2, high: ~2), b1, Signum.negative) - Test().comparison(T(low: ~1, mid: ~2, high: ~2), b1, Signum.negative) - Test().comparison(T(low: ~2, mid: ~2, high: ~2), b1, Signum.negative) - } - - for base in TripleIntTests.bases { - whereTheBaseIs(base) + try Ɣrequire(T(low: ~0, mid: ~0, high: ~0), equals: b1, is: Signum.positive) + try Ɣrequire(T(low: ~1, mid: ~0, high: ~0), equals: b1, is: Signum.positive) + try Ɣrequire(T(low: ~2, mid: ~0, high: ~0), equals: b1, is: Signum.positive) + try Ɣrequire(T(low: ~0, mid: ~1, high: ~0), equals: b1, is: Signum.positive) + try Ɣrequire(T(low: ~1, mid: ~1, high: ~0), equals: b1, is: Signum.positive) + try Ɣrequire(T(low: ~2, mid: ~1, high: ~0), equals: b1, is: Signum.positive) + try Ɣrequire(T(low: ~0, mid: ~2, high: ~0), equals: b1, is: Signum.positive) + try Ɣrequire(T(low: ~1, mid: ~2, high: ~0), equals: b1, is: Signum.positive) + try Ɣrequire(T(low: ~2, mid: ~2, high: ~0), equals: b1, is: Signum.positive) + try Ɣrequire(T(low: ~0, mid: ~0, high: ~1), equals: b1, is: Signum.positive) + try Ɣrequire(T(low: ~1, mid: ~0, high: ~1), equals: b1, is: Signum.positive) + try Ɣrequire(T(low: ~2, mid: ~0, high: ~1), equals: b1, is: Signum.positive) + try Ɣrequire(T(low: ~0, mid: ~1, high: ~1), equals: b1, is: Signum.positive) + try Ɣrequire(T(low: ~1, mid: ~1, high: ~1), equals: b1, is: Signum.zero) + try Ɣrequire(T(low: ~2, mid: ~1, high: ~1), equals: b1, is: Signum.negative) + try Ɣrequire(T(low: ~0, mid: ~2, high: ~1), equals: b1, is: Signum.negative) + try Ɣrequire(T(low: ~1, mid: ~2, high: ~1), equals: b1, is: Signum.negative) + try Ɣrequire(T(low: ~2, mid: ~2, high: ~1), equals: b1, is: Signum.negative) + try Ɣrequire(T(low: ~0, mid: ~0, high: ~2), equals: b1, is: Signum.negative) + try Ɣrequire(T(low: ~1, mid: ~0, high: ~2), equals: b1, is: Signum.negative) + try Ɣrequire(T(low: ~2, mid: ~0, high: ~2), equals: b1, is: Signum.negative) + try Ɣrequire(T(low: ~0, mid: ~1, high: ~2), equals: b1, is: Signum.negative) + try Ɣrequire(T(low: ~1, mid: ~1, high: ~2), equals: b1, is: Signum.negative) + try Ɣrequire(T(low: ~2, mid: ~1, high: ~2), equals: b1, is: Signum.negative) + try Ɣrequire(T(low: ~0, mid: ~2, high: ~2), equals: b1, is: Signum.negative) + try Ɣrequire(T(low: ~1, mid: ~2, high: ~2), equals: b1, is: Signum.negative) + try Ɣrequire(T(low: ~2, mid: ~2, high: ~2), equals: b1, is: Signum.negative) + + func Ɣrequire(_ lhs: T, equals rhs: T, is expectation: Signum) throws { + Ɣexpect(lhs, equals: rhs, is: expectation) + Ɣexpect(rhs, equals: lhs, is: expectation.negated()) + + try #require(lhs.compared(to: rhs) == expectation) + try #require(rhs.compared(to: lhs) == expectation.negated()) + } } } } - -//=----------------------------------------------------------------------------= -// MARK: + Assertions -//=----------------------------------------------------------------------------= - -private extension Test { - - //=------------------------------------------------------------------------= - // MARK: Utilities - //=------------------------------------------------------------------------= - - func comparison(_ lhs: TripleInt, _ rhs: TripleInt, _ expectation: Signum) { - same(lhs.compared(to: rhs), expectation) - same(rhs.compared(to: lhs), expectation.negated()) - comparison(lhs, rhs, expectation, id: ComparableID()) - } -} diff --git a/Tests/DoubleIntKitTests/TripleInt+Division.swift b/Tests/DoubleIntKitTests/TripleInt+Division.swift index 58244c7b..ea967332 100644 --- a/Tests/DoubleIntKitTests/TripleInt+Division.swift +++ b/Tests/DoubleIntKitTests/TripleInt+Division.swift @@ -9,73 +9,60 @@ import CoreKit import DoubleIntKit -import TestKit +import TestKit2 //*============================================================================* // MARK: * Triple Int x Division //*============================================================================* -final class TripleIntTestsOnDivision: XCTestCase { +@Suite struct TripleIntTestsOnDivision { //=------------------------------------------------------------------------= // MARK: Tests //=------------------------------------------------------------------------= - func testDivision3212MSB() { - func whereTheBaseIs(_ type: B.Type) where B: SystemsInteger & UnsignedInteger { + @Test( + "TripleInt: division 3212MSB (#124)", + Tag.List.tags(.todo), + arguments: TripleIntTests.basesAsUnsigned + ) func division3212MSB(_ base: any SystemsIntegerAsUnsigned.Type) throws { + + try whereIs(base) + func whereIs(_ type: B.Type) throws where B: SystemsIntegerAsUnsigned { typealias X = DoubleInt typealias Y = TripleInt typealias D = Division> + //=----------------------------------= + let x = B.msb + //=----------------------------------= + try Ɣrequire(Y(low: 0, mid: 0, high: ~0), by: X(low: 1, high: ~0), is: D(quotient: ~0 as B, remainder: X(low: 1, high: ~1))) + try Ɣrequire(Y(low: 0, mid: 0, high: ~0), by: X(low: ~1, high: ~0), is: D(quotient: ~0 as B, remainder: X(low: ~1, high: 1))) + try Ɣrequire(Y(low: ~0, mid: ~0, high: ~1), by: X(low: 0, high: ~0), is: D(quotient: ~0 as B, remainder: X(low: ~0, high: ~1))) + try Ɣrequire(Y(low: ~0, mid: ~0, high: ~1), by: X(low: ~0, high: ~0), is: D(quotient: ~0 as B, remainder: X(low: ~1, high: 0))) - Test().division3212MSB(Y(low: 0, mid: 0, high: ~0), X(low: 1, high: ~0), D(quotient: ~0 as B, remainder: X(low: 1, high: ~1))) - Test().division3212MSB(Y(low: 0, mid: 0, high: ~0), X(low: ~1, high: ~0), D(quotient: ~0 as B, remainder: X(low: ~1, high: 1))) - Test().division3212MSB(Y(low: ~0, mid: ~0, high: ~1), X(low: 0, high: ~0), D(quotient: ~0 as B, remainder: X(low: ~0, high: ~1))) - Test().division3212MSB(Y(low: ~0, mid: ~0, high: ~1), X(low: ~0, high: ~0), D(quotient: ~0 as B, remainder: X(low: ~1, high: 0))) + try Ɣrequire(Y(low: 0, mid: 0, high: ~x), by: X(low: ~0, high: x), is: D(quotient: ~3 as B, remainder: X(low: ~3, high: 4))) // 2 + try Ɣrequire(Y(low: ~0, mid: 0, high: ~x), by: X(low: ~0, high: x), is: D(quotient: ~3 as B, remainder: X(low: ~4, high: 5))) // 2 + try Ɣrequire(Y(low: 0, mid: ~0, high: ~x), by: X(low: ~0, high: x), is: D(quotient: ~1 as B, remainder: X(low: ~1, high: 1))) // 1 + try Ɣrequire(Y(low: ~0, mid: ~0, high: ~x), by: X(low: ~0, high: x), is: D(quotient: ~1 as B, remainder: X(low: ~2, high: 2))) // 1 - Test().division3212MSB(Y(low: 0, mid: 0, high: B.msb - 1), X(low: ~0, high: B.msb), D(quotient: ~3 as B, remainder: X(low: ~3, high: 4))) // 2 - Test().division3212MSB(Y(low: ~0, mid: 0, high: B.msb - 1), X(low: ~0, high: B.msb), D(quotient: ~3 as B, remainder: X(low: ~4, high: 5))) // 2 - Test().division3212MSB(Y(low: 0, mid: ~0, high: B.msb - 1), X(low: ~0, high: B.msb), D(quotient: ~1 as B, remainder: X(low: ~1, high: 1))) // 1 - Test().division3212MSB(Y(low: ~0, mid: ~0, high: B.msb - 1), X(low: ~0, high: B.msb), D(quotient: ~1 as B, remainder: X(low: ~2, high: 2))) // 1 - } - - for base in TripleIntTests.basesAsUnsigned { - whereTheBaseIs(base) - } - } -} - -//=----------------------------------------------------------------------------= -// MARK: + Assertions -//=----------------------------------------------------------------------------= - -private extension Test { - - //=------------------------------------------------------------------------= - // MARK: Utilities - //=------------------------------------------------------------------------= - - func division3212MSB( - _ dividend: TripleInt, - _ divisor: DoubleInt, - _ expectation: Division>? - ) where B: SystemsInteger & UnsignedInteger { - //=--------------------------------------= - guard let expectation else { - return same(divisor, 0, "division by zero is undefined [0]") - } - - guard let divisor = Nonzero(exactly: divisor) else { - return none(expectation, "division by zero is undefined [1]") - } - //=--------------------------------------= - let result: Division> = dividend.division3212(normalized: divisor) - //=--------------------------------------= - recover: do { - let remainder = TripleInt(low: result.remainder.low, mid: result.remainder.high, high: B.zero) - let recovered = divisor.value.multiplication(result.quotient).plus(remainder) - same(Fallible(dividend), recovered, "dividend != divisor * quotient + remainder") + + func Ɣrequire(_ dividend: Y, by divisor: X, is expectation: D) throws { + try #require(Bool(divisor.msb)) + + let result: D = dividend.division3212(normalized: Nonzero(divisor)) + try #require(result == expectation) + + recover: do { + let remainder = TripleInt( + low: result.remainder.low, + mid: result.remainder.high, + high: B.zero + ) + + let recovered = divisor.multiplication(result.quotient).plus(remainder) + try #require(Fallible(dividend) == recovered) + } + } } - //=--------------------------------------= - same(result, expectation, "3 by 2 division") } } diff --git a/Tests/DoubleIntKitTests/TripleInt+Subtraction.swift b/Tests/DoubleIntKitTests/TripleInt+Subtraction.swift deleted file mode 100644 index 149a3d7d..00000000 --- a/Tests/DoubleIntKitTests/TripleInt+Subtraction.swift +++ /dev/null @@ -1,111 +0,0 @@ -//=----------------------------------------------------------------------------= -// 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. -//=----------------------------------------------------------------------------= - -import CoreKit -import DoubleIntKit -import TestKit - -//*============================================================================* -// MARK: * Triple Int x Subtraction -//*============================================================================* - -final class TripleIntTestsOnSubtraction: XCTestCase { - - //=------------------------------------------------------------------------= - // MARK: Tests - //=------------------------------------------------------------------------= - - func testSubtraction32B() { - func whereTheBaseIsSigned(_ type: B.Type) where B: SystemsInteger & SignedInteger { - typealias X = DoubleInt.Magnitude - typealias Y = TripleInt - typealias F = Fallible> - //=----------------------------------= - let x = B.msb - //=----------------------------------= - Test().same(Y(low: 0, mid: 0, high: 0).minus(X(low: ~4, high: ~5)), F(Y(low: 5, mid: 5, high: ~0))) - Test().same(Y(low: 1, mid: 2, high: 3).minus(X(low: ~4, high: ~5)), F(Y(low: 6, mid: 7, high: 2))) - Test().same(Y(low: ~1, mid: ~2, high: ~3).minus(X(low: 4, high: 5)), F(Y(low: ~5, mid: ~7, high: ~3))) - Test().same(Y(low: ~0, mid: ~0, high: ~0).minus(X(low: 4, high: 5)), F(Y(low: ~4, mid: ~5, high: ~0))) - - Test().same(Y(low: ~4, mid: ~5, high: ~x).minus(X(low: ~4, high: ~5)), F(Y(low: 0, mid: 0, high: ~x))) - Test().same(Y(low: ~5, mid: ~5, high: ~x).minus(X(low: ~4, high: ~5)), F(Y(low: ~0, mid: ~0, high: ~x ^ 1))) - Test().same(Y(low: 4, mid: 5, high: x).minus(X(low: 4, high: 5)), F(Y(low: 0, mid: 0, high: x))) - Test().same(Y(low: 3, mid: 5, high: x).minus(X(low: 4, high: 5)), F(Y(low: ~0, mid: ~0, high: ~x), error: true)) - } - - func whereTheBaseIsUnsigned(_ type: B.Type) where B: SystemsInteger & UnsignedInteger { - typealias X = DoubleInt.Magnitude - typealias Y = TripleInt - typealias F = Fallible> - - Test().same(Y(low: 0, mid: 0, high: 0).minus(X(low: ~4, high: ~5)), F(Y(low: 5, mid: 5, high: ~0), error: true)) - Test().same(Y(low: 1, mid: 2, high: 3).minus(X(low: ~4, high: ~5)), F(Y(low: 6, mid: 7, high: 2))) - Test().same(Y(low: ~1, mid: ~2, high: ~3).minus(X(low: 4, high: 5)), F(Y(low: ~5, mid: ~7, high: ~3))) - Test().same(Y(low: ~0, mid: ~0, high: ~0).minus(X(low: 4, high: 5)), F(Y(low: ~4, mid: ~5, high: ~0))) - - Test().same(Y(low: ~4, mid: ~5, high: 0).minus(X(low: ~4, high: ~5)), F(Y(low: 0, mid: 0, high: 0))) - Test().same(Y(low: ~5, mid: ~5, high: 0).minus(X(low: ~4, high: ~5)), F(Y(low: ~0, mid: ~0, high: ~0), error: true)) - Test().same(Y(low: 4, mid: 5, high: 0).minus(X(low: 4, high: 5)), F(Y(low: 0, mid: 0, high: 0))) - Test().same(Y(low: 3, mid: 5, high: 0).minus(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) - } - } - - func testSubtraction33B() { - func whereTheBaseIsSigned(_ type: B.Type) where B: SystemsInteger & SignedInteger { - typealias X = DoubleInt - typealias Y = TripleInt - typealias F = Fallible> - //=----------------------------------= - let x = B.msb - //=----------------------------------= - Test().same(Y(low: 0, mid: 0, high: 0).minus(Y(low: ~4, mid: ~5, high: ~6)), F(Y(low: 5, mid: 5, high: 6))) - Test().same(Y(low: 1, mid: 2, high: 3).minus(Y(low: ~4, mid: ~5, high: ~6)), F(Y(low: 6, mid: 7, high: 9))) - Test().same(Y(low: ~1, mid: ~2, high: ~3).minus(Y(low: 4, mid: 5, high: 6)), F(Y(low: ~5, mid: ~7, high: ~9))) - Test().same(Y(low: ~0, mid: ~0, high: ~0).minus(Y(low: 4, mid: 5, high: 6)), F(Y(low: ~4, mid: ~5, high: ~6))) - - Test().same(Y(low: ~5, mid: ~5, high: ~x - 6).minus(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).minus(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).minus(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).minus(Y(low: 4, mid: 5, high: 6)), F(Y(low: ~0, mid: ~0, high: ~x), error: true)) - } - - func whereTheBaseIsUnsigned(_ type: B.Type) where B: SystemsInteger & UnsignedInteger { - typealias X = DoubleInt - typealias Y = TripleInt - typealias F = Fallible> - - Test().same(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)) - Test().same(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)) - Test().same(Y(low: ~1, mid: ~2, high: ~3).minus(Y(low: 4, mid: 5, high: 6)), F(Y(low: ~5, mid: ~7, high: ~9))) - Test().same(Y(low: ~0, mid: ~0, high: ~0).minus(Y(low: 4, mid: 5, high: 6)), F(Y(low: ~4, mid: ~5, high: ~6))) - - Test().same(Y(low: ~4, mid: ~5, high: ~6).minus(Y(low: ~4, mid: ~5, high: ~6)), F(Y(low: 0, mid: 0, high: 0))) - Test().same(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)) - Test().same(Y(low: 4, mid: 5, high: 6).minus(Y(low: 4, mid: 5, high: 6)), F(Y(low: 0, mid: 0, high: 0))) - Test().same(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)) - } - - for base in TripleIntTests.basesAsSigned { - whereTheBaseIsSigned(base) - } - - for base in TripleIntTests.basesAsUnsigned { - whereTheBaseIsUnsigned(base) - } - } -}