Skip to content

Commit

Permalink
Rewrite of BinaryInteger+Floats.swift tests (#108) (#110).
Browse files Browse the repository at this point in the history
  • Loading branch information
oscbyspro committed Oct 28, 2024
1 parent f9a9acf commit b837384
Show file tree
Hide file tree
Showing 4 changed files with 434 additions and 250 deletions.
2 changes: 1 addition & 1 deletion Sources/TestKit2/Global+Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public let typesAsCoreIntegersAsUnsigned: [any CoreIntegerAsUnsigned.Type] = [
// MARK: + Floats
//=----------------------------------------------------------------------------=

public let allSwiftBinaryFloatingPointTypes: [any Swift.BinaryFloatingPoint.Type] = [
public let typesAsSwiftBinaryFloatingPoint: [any Swift.BinaryFloatingPoint.Type] = [
Float32.self,
Float64.self,
]
23 changes: 23 additions & 0 deletions Sources/TestKit2/Utilities+Sign.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//=----------------------------------------------------------------------------=
// 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

//*============================================================================*
// MARK: * Utilities x Sign
//*============================================================================*

extension Sign {

//=------------------------------------------------------------------------=
// MARK: Metadata
//=------------------------------------------------------------------------=

public static let all: [Self] = [plus, minus]
}
54 changes: 36 additions & 18 deletions Tests/StdlibIntKitTests/StdlibInt+Floats.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ import TestKit2
// MARK: Tests x Swift.BinaryFloatingPoint
//=------------------------------------------------------------------------=

@Test("StdlibInt ← Swift.BinaryFloatingPoint - nan is nil", arguments: allSwiftBinaryFloatingPointTypes)
func initSwiftBinaryFloatingPointNanIsNil(type: any Swift.BinaryFloatingPoint.Type) {
@Test(
"StdlibInt ← Swift.BinaryFloatingPoint - nan is nil",
arguments: typesAsSwiftBinaryFloatingPoint
) func initSwiftBinaryFloatingPointNanIsNil(type: any Swift.BinaryFloatingPoint.Type) {
whereIs(type)

func whereIs<T>(_ type: T.Type) where T: Swift.BinaryFloatingPoint {
Expand All @@ -43,8 +45,10 @@ import TestKit2
}
}

@Test("StdlibInt ← Swift.BinaryFloatingPoint - infinity is nil", arguments: allSwiftBinaryFloatingPointTypes)
func initSwiftBinaryFloatingPointInfinityIsNil(type: any Swift.BinaryFloatingPoint.Type) {
@Test(
"StdlibInt ← Swift.BinaryFloatingPoint - infinity is nil",
arguments: typesAsSwiftBinaryFloatingPoint
) func initSwiftBinaryFloatingPointInfinityIsNil(type: any Swift.BinaryFloatingPoint.Type) {
whereIs(type)

func whereIs<T>(_ type: T.Type) where T: Swift.BinaryFloatingPoint {
Expand All @@ -53,8 +57,10 @@ import TestKit2
}
}

@Test("StdlibInt ← Swift.BinaryFloatingPoint - rounds towards zero", arguments: allSwiftBinaryFloatingPointTypes)
func initSwiftBinaryFloatingPointRoundsTowardsZero(type: any Swift.BinaryFloatingPoint.Type) {
@Test(
"StdlibInt ← Swift.BinaryFloatingPoint - rounds towards zero",
arguments: typesAsSwiftBinaryFloatingPoint
) func initSwiftBinaryFloatingPointRoundsTowardsZero(type: any Swift.BinaryFloatingPoint.Type) {
whereIs(type)

func whereIs<T>(_ type: T.Type) where T: Swift.BinaryFloatingPoint {
Expand Down Expand Up @@ -128,8 +134,10 @@ import TestKit2
/// 1111111111111111111111111111111111111111111111111110110011000011 →
/// 1111111111111111111111111111111111111111111111111111110011000011 →
///
@Test("StdlibInt ← Swift.BinaryFloatingPoint - [large][negative]", arguments: allSwiftBinaryFloatingPointTypes)
func initLargeNegativeFloats(source: any Swift.BinaryFloatingPoint.Type) {
@Test(
"StdlibInt ← Swift.BinaryFloatingPoint - [large][negative]",
arguments: typesAsSwiftBinaryFloatingPoint
) func initLargeNegativeFloats(source: any Swift.BinaryFloatingPoint.Type) {
whereIs(source: source, exponents: 32, steps: source.significandBitCount)

func whereIs<T>(source: T.Type, exponents: Int, steps: Int) where T: Swift.BinaryFloatingPoint {
Expand Down Expand Up @@ -165,8 +173,10 @@ import TestKit2
/// 0110000000000000000000000000000000000000000000000000110011000011 →
/// 1110000000000000000000000000000000000000000000000000110011000011 →
///
@Test("StdlibInt ← Swift.BinaryFloatingPoint - [large][negative][min]", arguments: allSwiftBinaryFloatingPointTypes)
func initLargeNegativeFloatsNearMinSignificandBitPattern(source: any Swift.BinaryFloatingPoint.Type) {
@Test(
"StdlibInt ← Swift.BinaryFloatingPoint - [large][negative][min]",
arguments: typesAsSwiftBinaryFloatingPoint
) func initLargeNegativeFloatsNearMinSignificandBitPattern(source: any Swift.BinaryFloatingPoint.Type) {
whereIs(source: source, exponents: 32, steps: 32)

func whereIs<T>(source: T.Type, exponents: Int, steps: Int) where T: Swift.BinaryFloatingPoint {
Expand Down Expand Up @@ -200,8 +210,10 @@ import TestKit2
/// 1001111111111111111111111111111111111111111111111111110011000011 →
/// 0001111111111111111111111111111111111111111111111111110011000011 →
///
@Test("StdlibInt ← Swift.BinaryFloatingPoint - [large][negative][max]", arguments: allSwiftBinaryFloatingPointTypes)
func initLargeNegativeFloatsNearMaxSignificandBitPattern(source: any Swift.BinaryFloatingPoint.Type) {
@Test(
"StdlibInt ← Swift.BinaryFloatingPoint - [large][negative][max]",
arguments: typesAsSwiftBinaryFloatingPoint
) func initLargeNegativeFloatsNearMaxSignificandBitPattern(source: any Swift.BinaryFloatingPoint.Type) {
whereIs(source: source, exponents: 32, steps: 32)

func whereIs<T>(source: T.Type, exponents: Int, steps: Int) where T: Swift.BinaryFloatingPoint {
Expand Down Expand Up @@ -235,8 +247,10 @@ import TestKit2
/// 1111111111111111111111111111111111111111111111111110110011000010 →
/// 1111111111111111111111111111111111111111111111111111110011000010 →
///
@Test("StdlibInt ← Swift.BinaryFloatingPoint - [large][positive]", arguments: allSwiftBinaryFloatingPointTypes)
func initLargePositiveFloats(source: any Swift.BinaryFloatingPoint.Type) {
@Test(
"StdlibInt ← Swift.BinaryFloatingPoint - [large][positive]",
arguments: typesAsSwiftBinaryFloatingPoint
) func initLargePositiveFloats(source: any Swift.BinaryFloatingPoint.Type) {
whereIs(source: source, exponents: 32, steps: source.significandBitCount)

func whereIs<T>(source: T.Type, exponents: Int, steps: Int) where T: Swift.BinaryFloatingPoint {
Expand Down Expand Up @@ -272,8 +286,10 @@ import TestKit2
/// 0110000000000000000000000000000000000000000000000000110011000010 →
/// 1110000000000000000000000000000000000000000000000000110011000010 →
///
@Test("StdlibInt ← Swift.BinaryFloatingPoint - [large][positive][min]", arguments: allSwiftBinaryFloatingPointTypes)
func initLargePositiveFloatsNearMinSignificandBitPattern(source: any Swift.BinaryFloatingPoint.Type) {
@Test(
"StdlibInt ← Swift.BinaryFloatingPoint - [large][positive][min]",
arguments: typesAsSwiftBinaryFloatingPoint
) func initLargePositiveFloatsNearMinSignificandBitPattern(source: any Swift.BinaryFloatingPoint.Type) {
whereIs(source: source, exponents: 32, steps: 32)

func whereIs<T>(source: T.Type, exponents: Int, steps: Int) where T: Swift.BinaryFloatingPoint {
Expand Down Expand Up @@ -307,8 +323,10 @@ import TestKit2
/// 1001111111111111111111111111111111111111111111111111110011000010 →
/// 0001111111111111111111111111111111111111111111111111110011000010 →
///
@Test("StdlibInt ← Swift.BinaryFloatingPoint - [large][positive][max]", arguments: allSwiftBinaryFloatingPointTypes)
func initLargePositiveFloatsNearMaxSignificandBitPattern(source: any Swift.BinaryFloatingPoint.Type) {
@Test(
"StdlibInt ← Swift.BinaryFloatingPoint - [large][positive][max]",
arguments: typesAsSwiftBinaryFloatingPoint
) func initLargePositiveFloatsNearMaxSignificandBitPattern(source: any Swift.BinaryFloatingPoint.Type) {
whereIs(source: source, exponents: 32, steps: 32)

func whereIs<T>(source: T.Type, exponents: Int, steps: Int) where T: Swift.BinaryFloatingPoint {
Expand Down
Loading

0 comments on commit b837384

Please sign in to comment.