From 26102d58c1f4a34039de79e10b11eb6fde527a18 Mon Sep 17 00:00:00 2001 From: Steffan Andrews Date: Sat, 9 Nov 2024 23:12:37 -0800 Subject: [PATCH] Migrated unit tests to Swift Testing --- .../xcschemes/SwiftRadix-CI.xcscheme | 6 +- .../Radix/Binary/Binary Tests.swift | 38 +- .../Binary/Binary Type Extensions Tests.swift | 71 +-- .../SwiftRadixTests/Radix/Hex/Hex Tests.swift | 48 +- .../Radix/Hex/Hex Type Extensions Tests.swift | 71 +-- .../Radix/Octal/Octal Tests.swift | 38 +- .../Octal/Octal Type Extensions Tests.swift | 71 +-- .../Radix/Radix Bit Tests.swift | 76 +-- .../Radix/Radix Bytes Tests.swift | 42 +- .../Radix Collection Methods Tests.swift | 342 +++++++------- .../Radix/Radix Nibble Tests.swift | 52 +-- .../Radix/Radix Operators Tests.swift | 180 +++---- .../Radix Protocol Adoptions Tests.swift | 50 +- .../Radix/Radix Strings Tests.swift | 314 ++++++------- Tests/SwiftRadixTests/Radix/Radix Tests.swift | 442 +++++++++--------- .../Radix/Radix Type Extensions Tests.swift | 71 +-- 16 files changed, 958 insertions(+), 954 deletions(-) diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/SwiftRadix-CI.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/SwiftRadix-CI.xcscheme index c0c5118..0157f07 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/SwiftRadix-CI.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/SwiftRadix-CI.xcscheme @@ -22,10 +22,10 @@ + buildForAnalyzing = "NO"> // binary @@ -62,11 +62,11 @@ final class RadixBitTests: XCTestCase { radix[bit: 0] = 1 - XCTAssertEqual(radix.value, 0b11001101) + #expect(radix.value == 0b11001101) radix[bit: 1] = 1 - XCTAssertEqual(radix.value, 0b11001111) + #expect(radix.value == 0b11001111) // hex @@ -74,11 +74,11 @@ final class RadixBitTests: XCTestCase { radix[bit: 0] = 1 - XCTAssertEqual(radix.value, 0b11001101) + #expect(radix.value == 0b11001101) radix[bit: 1] = 1 - XCTAssertEqual(radix.value, 0b11001111) + #expect(radix.value == 0b11001111) // octal @@ -86,11 +86,11 @@ final class RadixBitTests: XCTestCase { radix[bit: 0] = 1 - XCTAssertEqual(radix.value, 0b11001101) + #expect(radix.value == 0b11001101) radix[bit: 1] = 1 - XCTAssertEqual(radix.value, 0b11001111) + #expect(radix.value == 0b11001111) // edge cases @@ -98,12 +98,12 @@ final class RadixBitTests: XCTestCase { radix[bit: 0] = 3 // invalid value, fails silently - XCTAssertEqual(radix.value, 0b11001100) + #expect(radix.value == 0b11001100) radix = 0b11001100.hex radix[bit: -1] = 1 // invalid index, fails silently - XCTAssertEqual(radix.value, 0b11001100) + #expect(radix.value == 0b11001100) } } diff --git a/Tests/SwiftRadixTests/Radix/Radix Bytes Tests.swift b/Tests/SwiftRadixTests/Radix/Radix Bytes Tests.swift index 371c4f6..06cdd7b 100644 --- a/Tests/SwiftRadixTests/Radix/Radix Bytes Tests.swift +++ b/Tests/SwiftRadixTests/Radix/Radix Bytes Tests.swift @@ -5,58 +5,58 @@ // import SwiftRadix -import XCTest +import Testing -final class RadixBytesTests: XCTestCase { - func testRadix_Bytes() { +@Suite struct RadixBytesTests { + @Test func radix_Bytes() { // binary - XCTAssertEqual( - UInt8(0xFF).binary.bytes, + #expect( + UInt8(0xFF).binary.bytes == [0xFF] ) - XCTAssertEqual( - UInt16(0xFF).binary.bytes, + #expect( + UInt16(0xFF).binary.bytes == [0xFF, 0x00] ) - XCTAssertEqual( - Int(0xFF).binary.bytes, + #expect( + Int(0xFF).binary.bytes == [0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] ) // hex - XCTAssertEqual( - UInt8(0xFF).hex.bytes, + #expect( + UInt8(0xFF).hex.bytes == [0xFF] ) - XCTAssertEqual( - UInt16(0xFF).hex.bytes, + #expect( + UInt16(0xFF).hex.bytes == [0xFF, 0x00] ) - XCTAssertEqual( - Int(0xFF).hex.bytes, + #expect( + Int(0xFF).hex.bytes == [0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] ) // octal - XCTAssertEqual( - UInt8(0xFF).octal.bytes, + #expect( + UInt8(0xFF).octal.bytes == [0xFF] ) - XCTAssertEqual( - UInt16(0xFF).octal.bytes, + #expect( + UInt16(0xFF).octal.bytes == [0xFF, 0x00] ) - XCTAssertEqual( - Int(0xFF).octal.bytes, + #expect( + Int(0xFF).octal.bytes == [0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] ) } diff --git a/Tests/SwiftRadixTests/Radix/Radix Collection Methods Tests.swift b/Tests/SwiftRadixTests/Radix/Radix Collection Methods Tests.swift index 55ebb18..cdf6ca9 100644 --- a/Tests/SwiftRadixTests/Radix/Radix Collection Methods Tests.swift +++ b/Tests/SwiftRadixTests/Radix/Radix Collection Methods Tests.swift @@ -5,16 +5,16 @@ // import SwiftRadix -import XCTest +import Testing -final class RadixCollectionMethodsTests: XCTestCase { - func testRadix_CollectionExtension_stringValue() { +@Suite struct RadixCollectionMethodsTests { + @Test func radix_CollectionExtension_stringValue() { // binary let source1 = [0x00.binary, 0xFF.binary] - XCTAssertEqual( - source1.stringValue, + #expect( + source1.stringValue == "0 11111111" ) @@ -22,8 +22,8 @@ final class RadixCollectionMethodsTests: XCTestCase { let source2 = [0x00.hex, 0xFF.hex] - XCTAssertEqual( - source2.stringValue, + #expect( + source2.stringValue == "0 FF" ) @@ -31,24 +31,24 @@ final class RadixCollectionMethodsTests: XCTestCase { let source3 = [0x000.octal, 0o123.octal] - XCTAssertEqual( - source3.stringValue, + #expect( + source3.stringValue == "0 123" ) } - func testRadix_CollectionExtension_stringValue_Prefix() { + @Test func radix_CollectionExtension_stringValue_Prefix() { // binary let source1 = [0x00.binary, 0xFF.binary] - XCTAssertEqual( - source1.stringValue(prefix: true), + #expect( + source1.stringValue(prefix: true) == "0b0 0b11111111" ) - XCTAssertEqual( - source1.stringValue(prefix: false), + #expect( + source1.stringValue(prefix: false) == "0 11111111" ) @@ -56,13 +56,13 @@ final class RadixCollectionMethodsTests: XCTestCase { let source2 = [0x00.hex, 0xFF.hex] - XCTAssertEqual( - source2.stringValue(prefix: true, uppercase: false), + #expect( + source2.stringValue(prefix: true, uppercase: false) == "0x0 0xff" ) - XCTAssertEqual( - source2.stringValue(prefix: false, uppercase: true), + #expect( + source2.stringValue(prefix: false, uppercase: true) == "0 FF" ) @@ -70,29 +70,29 @@ final class RadixCollectionMethodsTests: XCTestCase { let source3 = [0x000.octal, 0o123.octal] - XCTAssertEqual( - source3.stringValue(prefix: true), + #expect( + source3.stringValue(prefix: true) == "0o0 0o123" ) - XCTAssertEqual( - source3.stringValue(prefix: false), + #expect( + source3.stringValue(prefix: false) == "0 123" ) } - func testRadix_CollectionExtension_stringValue_PrefixSeparatorUppercase() { + @Test func radix_CollectionExtension_stringValue_PrefixSeparatorUppercase() { // binary let source1 = [0x00.binary, 0xFF.binary] - XCTAssertEqual( - source1.stringValue(prefix: true, separator: ", "), + #expect( + source1.stringValue(prefix: true, separator: ", ") == "0b0, 0b11111111" ) - XCTAssertEqual( - source1.stringValue(prefix: false, separator: ", "), + #expect( + source1.stringValue(prefix: false, separator: ", ") == "0, 11111111" ) @@ -100,13 +100,13 @@ final class RadixCollectionMethodsTests: XCTestCase { let source2 = [0x00.hex, 0xFF.hex] - XCTAssertEqual( - source2.stringValue(prefix: true, separator: ", ", uppercase: false), + #expect( + source2.stringValue(prefix: true, separator: ", ", uppercase: false) == "0x0, 0xff" ) - XCTAssertEqual( - source2.stringValue(prefix: false, separator: ", ", uppercase: true), + #expect( + source2.stringValue(prefix: false, separator: ", ", uppercase: true) == "0, FF" ) @@ -114,29 +114,29 @@ final class RadixCollectionMethodsTests: XCTestCase { let source3 = [0x000.octal, 0o123.octal] - XCTAssertEqual( - source3.stringValue(prefix: true, separator: ", "), + #expect( + source3.stringValue(prefix: true, separator: ", ") == "0o0, 0o123" ) - XCTAssertEqual( - source3.stringValue(prefix: false, separator: ", "), + #expect( + source3.stringValue(prefix: false, separator: ", ") == "0, 123" ) } - func testRadix_CollectionExtension_stringValue_PadTo() { + @Test func radix_CollectionExtension_stringValue_PadTo() { // binary let source1 = [0x00.binary, 0xFF.binary] - XCTAssertEqual( - source1.stringValue(padTo: 2), + #expect( + source1.stringValue(padTo: 2) == "00 11111111" ) - XCTAssertEqual( - source1.stringValue(padTo: 2, prefix: true, separator: ", "), + #expect( + source1.stringValue(padTo: 2, prefix: true, separator: ", ") == "0b00, 0b11111111" ) @@ -144,13 +144,13 @@ final class RadixCollectionMethodsTests: XCTestCase { let source2 = [0x00.hex, 0xFF.hex] - XCTAssertEqual( - source2.stringValue(padTo: 2), + #expect( + source2.stringValue(padTo: 2) == "00 FF" ) - XCTAssertEqual( - source2.stringValue(padTo: 2, prefix: true, separator: ", ", uppercase: false), + #expect( + source2.stringValue(padTo: 2, prefix: true, separator: ", ", uppercase: false) == "0x00, 0xff" ) @@ -158,13 +158,13 @@ final class RadixCollectionMethodsTests: XCTestCase { let source3 = [0x000.octal, 0o123.octal] - XCTAssertEqual( - source3.stringValue(padTo: 2), + #expect( + source3.stringValue(padTo: 2) == "00 123" ) - XCTAssertEqual( - source3.stringValue(padTo: 2, prefix: true, separator: ", "), + #expect( + source3.stringValue(padTo: 2, prefix: true, separator: ", ") == "0o00, 0o123" ) @@ -172,34 +172,34 @@ final class RadixCollectionMethodsTests: XCTestCase { let source4 = [0x00.hex, 0xFF.hex] - XCTAssertEqual( - source4.stringValue(padTo: -1), + #expect( + source4.stringValue(padTo: -1) == "0 FF" ) } - func testRadix_CollectionExtension_stringValue_PadToEvery() { + @Test func radix_CollectionExtension_stringValue_PadToEvery() { // binary let source1 = [0x00.binary, 0xFF.binary] - XCTAssertEqual( - source1.stringValue(padToEvery: 0), + #expect( + source1.stringValue(padToEvery: 0) == "0 11111111" ) - XCTAssertEqual( - source1.stringValue(padToEvery: 2), + #expect( + source1.stringValue(padToEvery: 2) == "00 11111111" ) - XCTAssertEqual( - source1.stringValue(padToEvery: 3), + #expect( + source1.stringValue(padToEvery: 3) == "000 011111111" ) - XCTAssertEqual( - source1.stringValue(padToEvery: 2, prefix: true, separator: ", "), + #expect( + source1.stringValue(padToEvery: 2, prefix: true, separator: ", ") == "0b00, 0b11111111" ) @@ -207,23 +207,23 @@ final class RadixCollectionMethodsTests: XCTestCase { let source2 = [0x00.hex, 0xFF.hex] - XCTAssertEqual( - source2.stringValue(padToEvery: 0), + #expect( + source2.stringValue(padToEvery: 0) == "0 FF" ) - XCTAssertEqual( - source2.stringValue(padToEvery: 2), + #expect( + source2.stringValue(padToEvery: 2) == "00 FF" ) - XCTAssertEqual( - source2.stringValue(padToEvery: 3), + #expect( + source2.stringValue(padToEvery: 3) == "000 0FF" ) - XCTAssertEqual( - source2.stringValue(padToEvery: 2, prefix: true, separator: ", ", uppercase: false), + #expect( + source2.stringValue(padToEvery: 2, prefix: true, separator: ", ", uppercase: false) == "0x00, 0xff" ) @@ -231,28 +231,28 @@ final class RadixCollectionMethodsTests: XCTestCase { let source3 = [0x000.octal, 0o123.octal] - XCTAssertEqual( - source3.stringValue(padToEvery: 0), + #expect( + source3.stringValue(padToEvery: 0) == "0 123" ) - XCTAssertEqual( - source3.stringValue(padToEvery: 2), + #expect( + source3.stringValue(padToEvery: 2) == "00 0123" ) - XCTAssertEqual( - source3.stringValue(padToEvery: 3), + #expect( + source3.stringValue(padToEvery: 3) == "000 123" ) - XCTAssertEqual( - source3.stringValue(padToEvery: 5), + #expect( + source3.stringValue(padToEvery: 5) == "00000 00123" ) - XCTAssertEqual( - source3.stringValue(padToEvery: 2, prefix: true, separator: ", "), + #expect( + source3.stringValue(padToEvery: 2, prefix: true, separator: ", ") == "0o00, 0o0123" ) @@ -260,19 +260,19 @@ final class RadixCollectionMethodsTests: XCTestCase { let source4 = [0x00.hex, 0xFF.hex] - XCTAssertEqual( - source4.stringValue(padToEvery: -1), + #expect( + source4.stringValue(padToEvery: -1) == "0 FF" ) } - func testRadix_CollectionExtension_stringValueArrayLiteral() { + @Test func radix_CollectionExtension_stringValueArrayLiteral() { // binary let source1 = [0x00.binary, 0xFF.binary] - XCTAssertEqual( - source1.stringValueArrayLiteral, + #expect( + source1.stringValueArrayLiteral == "[0b0, 0b11111111]" ) @@ -280,8 +280,8 @@ final class RadixCollectionMethodsTests: XCTestCase { let source2 = [0x00.hex, 0xFF.hex] - XCTAssertEqual( - source2.stringValueArrayLiteral, + #expect( + source2.stringValueArrayLiteral == "[0x0, 0xFF]" ) @@ -289,19 +289,19 @@ final class RadixCollectionMethodsTests: XCTestCase { let source3 = [0o000.octal, 0o123.octal] - XCTAssertEqual( - source3.stringValueArrayLiteral, + #expect( + source3.stringValueArrayLiteral == "[0o0, 0o123]" ) } - func testRadix_CollectionExtension_stringValueArrayLiteral_PadTo() { + @Test func radix_CollectionExtension_stringValueArrayLiteral_PadTo() { // binary let source1 = [0x00.binary, 0xFF.binary] - XCTAssertEqual( - source1.stringValueArrayLiteral(padTo: 4), + #expect( + source1.stringValueArrayLiteral(padTo: 4) == "[0b0000, 0b11111111]" ) @@ -309,13 +309,13 @@ final class RadixCollectionMethodsTests: XCTestCase { let source2 = [0x00.hex, 0xFF.hex] - XCTAssertEqual( - source2.stringValueArrayLiteral(padTo: 4, uppercase: true), + #expect( + source2.stringValueArrayLiteral(padTo: 4, uppercase: true) == "[0x0000, 0x00FF]" ) - XCTAssertEqual( - source2.stringValueArrayLiteral(padTo: 4, uppercase: false), + #expect( + source2.stringValueArrayLiteral(padTo: 4, uppercase: false) == "[0x0000, 0x00ff]" ) @@ -323,19 +323,19 @@ final class RadixCollectionMethodsTests: XCTestCase { let source3 = [0o000.octal, 0o123.octal] - XCTAssertEqual( - source3.stringValueArrayLiteral(padTo: 4), + #expect( + source3.stringValueArrayLiteral(padTo: 4) == "[0o0000, 0o0123]" ) } - func testRadix_CollectionExtension_stringValueArrayLiteral_PadToEvery() { + @Test func radix_CollectionExtension_stringValueArrayLiteral_PadToEvery() { // binary let source1 = [0x00.binary, 0xFF.binary] - XCTAssertEqual( - source1.stringValueArrayLiteral(padToEvery: 2), + #expect( + source1.stringValueArrayLiteral(padToEvery: 2) == "[0b00, 0b11111111]" ) @@ -343,13 +343,13 @@ final class RadixCollectionMethodsTests: XCTestCase { let source2 = [0x00.hex, 0xFF.hex] - XCTAssertEqual( - source2.stringValueArrayLiteral(padToEvery: 2, uppercase: true), + #expect( + source2.stringValueArrayLiteral(padToEvery: 2, uppercase: true) == "[0x00, 0xFF]" ) - XCTAssertEqual( - source2.stringValueArrayLiteral(padToEvery: 2, uppercase: false), + #expect( + source2.stringValueArrayLiteral(padToEvery: 2, uppercase: false) == "[0x00, 0xff]" ) @@ -357,19 +357,19 @@ final class RadixCollectionMethodsTests: XCTestCase { let source3 = [0o000.octal, 0o123.octal] - XCTAssertEqual( - source3.stringValueArrayLiteral(padToEvery: 2), + #expect( + source3.stringValueArrayLiteral(padToEvery: 2) == "[0o00, 0o0123]" ) } - func testRadix_CollectionExtension_stringValues() { + @Test func radix_CollectionExtension_stringValues() { // binary let source1 = [0x00.binary, 0xFF.binary] - XCTAssertEqual( - source1.stringValues, + #expect( + source1.stringValues == ["0", "11111111"] ) @@ -377,8 +377,8 @@ final class RadixCollectionMethodsTests: XCTestCase { let source2 = [0x00.hex, 0xFF.hex] - XCTAssertEqual( - source2.stringValues, + #expect( + source2.stringValues == ["0", "FF"] ) @@ -386,29 +386,29 @@ final class RadixCollectionMethodsTests: XCTestCase { let source3 = [0o000.octal, 0o123.octal] - XCTAssertEqual( - source3.stringValues, + #expect( + source3.stringValues == ["0", "123"] ) } - func testRadix_CollectionExtension_stringValues_PadTo() { + @Test func radix_CollectionExtension_stringValues_PadTo() { // binary let source1 = [0x00.binary, 0xFF.binary] - XCTAssertEqual( - source1.stringValues(padTo: 0), + #expect( + source1.stringValues(padTo: 0) == ["0", "11111111"] ) - XCTAssertEqual( - source1.stringValues(padTo: 2), + #expect( + source1.stringValues(padTo: 2) == ["00", "11111111"] ) - XCTAssertEqual( - source1.stringValues(padTo: 3), + #expect( + source1.stringValues(padTo: 3) == ["000", "11111111"] ) @@ -416,18 +416,18 @@ final class RadixCollectionMethodsTests: XCTestCase { let source2 = [0x00.hex, 0xFF.hex] - XCTAssertEqual( - source2.stringValues(padTo: 0), + #expect( + source2.stringValues(padTo: 0) == ["0", "FF"] ) - XCTAssertEqual( - source2.stringValues(padTo: 2), + #expect( + source2.stringValues(padTo: 2) == ["00", "FF"] ) - XCTAssertEqual( - source2.stringValues(padTo: 3, uppercase: false), + #expect( + source2.stringValues(padTo: 3, uppercase: false) == ["000", "0ff"] ) @@ -435,44 +435,44 @@ final class RadixCollectionMethodsTests: XCTestCase { let source3 = [0o000.octal, 0o123.octal] - XCTAssertEqual( - source3.stringValues(padTo: 0), + #expect( + source3.stringValues(padTo: 0) == ["0", "123"] ) - XCTAssertEqual( - source3.stringValues(padTo: 2), + #expect( + source3.stringValues(padTo: 2) == ["00", "123"] ) - XCTAssertEqual( - source3.stringValues(padTo: 3), + #expect( + source3.stringValues(padTo: 3) == ["000", "123"] ) - XCTAssertEqual( - source3.stringValues(padTo: 5), + #expect( + source3.stringValues(padTo: 5) == ["00000", "00123"] ) } - func testRadix_CollectionExtension_stringValues_PadToEvery() { + @Test func radix_CollectionExtension_stringValues_PadToEvery() { // binary let source1 = [0x00.binary, 0xFF.binary] - XCTAssertEqual( - source1.stringValues(padToEvery: 0), + #expect( + source1.stringValues(padToEvery: 0) == ["0", "11111111"] ) - XCTAssertEqual( - source1.stringValues(padToEvery: 2), + #expect( + source1.stringValues(padToEvery: 2) == ["00", "11111111"] ) - XCTAssertEqual( - source1.stringValues(padToEvery: 3), + #expect( + source1.stringValues(padToEvery: 3) == ["000", "011111111"] ) @@ -480,45 +480,45 @@ final class RadixCollectionMethodsTests: XCTestCase { let source2 = [0x00.hex, 0xFF.hex] - XCTAssertEqual( - source2.stringValues(padToEvery: 0), + #expect( + source2.stringValues(padToEvery: 0) == ["0", "FF"] ) - XCTAssertEqual( - source2.stringValues(padToEvery: 2), + #expect( + source2.stringValues(padToEvery: 2) == ["00", "FF"] ) - XCTAssertEqual( - source2.stringValues(padToEvery: 3), + #expect( + source2.stringValues(padToEvery: 3) == ["000", "0FF"] ) - XCTAssertEqual( - source2.stringValues(padToEvery: 2, prefixes: true, uppercase: false), + #expect( + source2.stringValues(padToEvery: 2, prefixes: true, uppercase: false) == ["0x00", "0xff"] ) let source2B = [0x00.hex, 0xFFFF.hex] - XCTAssertEqual( - source2B.stringValues(padToEvery: 0), + #expect( + source2B.stringValues(padToEvery: 0) == ["0", "FFFF"] ) - XCTAssertEqual( - source2B.stringValues(padToEvery: 2), + #expect( + source2B.stringValues(padToEvery: 2) == ["00", "FFFF"] ) - XCTAssertEqual( - source2B.stringValues(padToEvery: 3), + #expect( + source2B.stringValues(padToEvery: 3) == ["000", "00FFFF"] ) - XCTAssertEqual( - source2B.stringValues(padToEvery: 3, prefixes: true, uppercase: false), + #expect( + source2B.stringValues(padToEvery: 3, prefixes: true, uppercase: false) == ["0x000", "0x00ffff"] ) @@ -526,70 +526,70 @@ final class RadixCollectionMethodsTests: XCTestCase { let source3 = [0o000.octal, 0o123.octal] - XCTAssertEqual( - source3.stringValues(padToEvery: 0), + #expect( + source3.stringValues(padToEvery: 0) == ["0", "123"] ) - XCTAssertEqual( - source3.stringValues(padToEvery: 2), + #expect( + source3.stringValues(padToEvery: 2) == ["00", "0123"] ) - XCTAssertEqual( - source3.stringValues(padToEvery: 3), + #expect( + source3.stringValues(padToEvery: 3) == ["000", "123"] ) - XCTAssertEqual( - source3.stringValues(padToEvery: 5), + #expect( + source3.stringValues(padToEvery: 5) == ["00000", "00123"] ) } - func testRadix_CollectionExtension_values() { + @Test func radix_CollectionExtension_values() { // binary let source1: [Radix] = [0x00.binary, 0xFF.binary] - XCTAssertEqual(source1.values, [0x00, 0xFF]) + #expect(source1.values == [0x00, 0xFF]) // hex let source2: [Radix] = [0x00.hex, 0xFF.hex] - XCTAssertEqual(source2.values, [0x00, 0xFF]) + #expect(source2.values == [0x00, 0xFF]) // octal let source3: [Radix] = [0x00.octal, 0xFF.octal] - XCTAssertEqual(source3.values, [0x00, 0xFF]) + #expect(source3.values == [0x00, 0xFF]) } - func testRadix_CollectionExtension_Optional_values() { + @Test func radix_CollectionExtension_Optional_values() { // binary let source1: [Radix?] = [0x00.binary, 0xFF.binary, nil] - XCTAssertEqual(source1.values, [0x00, 0xFF, nil]) + #expect(source1.values == [0x00, 0xFF, nil]) // hex let source2: [Radix?] = [0x00.hex, 0xFF.hex, nil] - XCTAssertEqual(source2.values, [0x00, 0xFF, nil]) + #expect(source2.values == [0x00, 0xFF, nil]) // octal let source3: [Radix?] = [0x00.octal, 0xFF.octal, nil] - XCTAssertEqual(source3.values, [0x00, 0xFF, nil]) + #expect(source3.values == [0x00, 0xFF, nil]) } } diff --git a/Tests/SwiftRadixTests/Radix/Radix Nibble Tests.swift b/Tests/SwiftRadixTests/Radix/Radix Nibble Tests.swift index 9321461..a5cf4ac 100644 --- a/Tests/SwiftRadixTests/Radix/Radix Nibble Tests.swift +++ b/Tests/SwiftRadixTests/Radix/Radix Nibble Tests.swift @@ -5,43 +5,43 @@ // import SwiftRadix -import XCTest +import Testing -final class RadixNibbleTests: XCTestCase { - func testRadix_Nibble_Get() { +@Suite struct RadixNibbleTests { + @Test func radix_Nibble_Get() { let source = 0b01011100 // binary - XCTAssertTrue(source.binary.nibble(0) == 0b1100) - XCTAssertTrue(source.binary.nibble(1) == 0b0101) + #expect(source.binary.nibble(0) == 0b1100) + #expect(source.binary.nibble(1) == 0b0101) - XCTAssertTrue(source.binary[nibble: 0] == 0b1100) - XCTAssertTrue(source.binary[nibble: 1] == 0b0101) + #expect(source.binary[nibble: 0] == 0b1100) + #expect(source.binary[nibble: 1] == 0b0101) // hex - XCTAssertTrue(source.hex.nibble(0) == 0b1100) - XCTAssertTrue(source.hex.nibble(1) == 0b0101) + #expect(source.hex.nibble(0) == 0b1100) + #expect(source.hex.nibble(1) == 0b0101) - XCTAssertTrue(source.hex[nibble: 0] == 0b1100) - XCTAssertTrue(source.hex[nibble: 1] == 0b0101) + #expect(source.hex[nibble: 0] == 0b1100) + #expect(source.hex[nibble: 1] == 0b0101) // octal - XCTAssertTrue(source.octal.nibble(0) == 0b1100) - XCTAssertTrue(source.octal.nibble(1) == 0b0101) + #expect(source.octal.nibble(0) == 0b1100) + #expect(source.octal.nibble(1) == 0b0101) - XCTAssertTrue(source.octal[nibble: 0] == 0b1100) - XCTAssertTrue(source.octal[nibble: 1] == 0b0101) + #expect(source.octal[nibble: 0] == 0b1100) + #expect(source.octal[nibble: 1] == 0b0101) // edge cases - XCTAssertTrue(source.binary.nibble(-1) == 0) // out of bounds, default 0 - XCTAssertTrue(source.binary.nibble(2) == 0) // out of bounds, default 0 + #expect(source.binary.nibble(-1) == 0) // out of bounds, default 0 + #expect(source.binary.nibble(2) == 0) // out of bounds, default 0 } - func testRadix_Nibble_Subscript_Set() { + @Test func radix_Nibble_Subscript_Set() { var radix: Radix // binary @@ -50,11 +50,11 @@ final class RadixNibbleTests: XCTestCase { radix[nibble: 0] = 0b0110 - XCTAssertEqual(radix.value, 0b01010110) + #expect(radix.value == 0b01010110) radix[nibble: 1] = 0b0110 - XCTAssertEqual(radix.value, 0b01100110) + #expect(radix.value == 0b01100110) // hex @@ -62,11 +62,11 @@ final class RadixNibbleTests: XCTestCase { radix[nibble: 0] = 0b0110 - XCTAssertEqual(radix.value, 0b01010110) + #expect(radix.value == 0b01010110) radix[nibble: 1] = 0b0110 - XCTAssertEqual(radix.value, 0b01100110) + #expect(radix.value == 0b01100110) // octal @@ -74,11 +74,11 @@ final class RadixNibbleTests: XCTestCase { radix[nibble: 0] = 0b0110 - XCTAssertEqual(radix.value, 0b01010110) + #expect(radix.value == 0b01010110) radix[nibble: 1] = 0b0110 - XCTAssertEqual(radix.value, 0b01100110) + #expect(radix.value == 0b01100110) // edge cases @@ -86,10 +86,10 @@ final class RadixNibbleTests: XCTestCase { radix[nibble: 0] = 20 // invalid value, fails silently - XCTAssertEqual(radix.value, 0b01011100) + #expect(radix.value == 0b01011100) radix[nibble: -1] = 1 // invalid index, fails silently - XCTAssertEqual(radix.value, 0b01011100) + #expect(radix.value == 0b01011100) } } diff --git a/Tests/SwiftRadixTests/Radix/Radix Operators Tests.swift b/Tests/SwiftRadixTests/Radix/Radix Operators Tests.swift index 43cb85f..ff8762b 100644 --- a/Tests/SwiftRadixTests/Radix/Radix Operators Tests.swift +++ b/Tests/SwiftRadixTests/Radix/Radix Operators Tests.swift @@ -5,88 +5,88 @@ // import SwiftRadix -import XCTest +import Testing -final class RadixOperatorsTests: XCTestCase { - func testRadix_Operators() { +@Suite struct RadixOperatorsTests { + @Test func radix_Operators() { // just test hex (base-16) // (since all operators operate on the underlying value, agnostic of radix) // Equatable - XCTAssert(1.hex == 1.hex) - XCTAssert(1.hex != 2.hex) + #expect(1.hex == 1.hex) + #expect(1.hex != 2.hex) - XCTAssert(1.hex == 1) - XCTAssert(1.hex == UInt8(1)) - XCTAssert(UInt8(1) == 1.hex) - XCTAssert(1.hex != 2) - XCTAssert(1.hex != UInt8(2)) - XCTAssert(UInt8(2) != 1.hex) + #expect(1.hex == 1) + #expect(1.hex == UInt8(1)) + #expect(UInt8(1) == 1.hex) + #expect(1.hex != 2) + #expect(1.hex != UInt8(2)) + #expect(UInt8(2) != 1.hex) // Equatable - Optionals - XCTAssert("1".hex == "1".hex) - XCTAssert("1".hex != "2".hex) + #expect("1".hex == "1".hex) + #expect("1".hex != "2".hex) - XCTAssert("1".hex == 1) - XCTAssert("1".hex == UInt8(1)) - XCTAssert(UInt8(1) == 1.hex) - XCTAssert("1".hex != 2) - XCTAssert("1".hex != UInt8(2)) - XCTAssert(UInt8(2) != "1".hex) + #expect("1".hex == 1) + #expect("1".hex == UInt8(1)) + #expect(UInt8(1) == 1.hex) + #expect("1".hex != 2) + #expect("1".hex != UInt8(2)) + #expect(UInt8(2) != "1".hex) // Comparable - XCTAssert(2.hex > 1.hex) - XCTAssertFalse(1.hex > 2.hex) + #expect(2.hex > 1.hex) + #expect(!(1.hex > 2.hex)) - XCTAssert(2.hex > UInt8(1)) - XCTAssert(UInt8(2) > 1.hex) - XCTAssertFalse(1.hex > UInt8(2)) - XCTAssertFalse(UInt8(1) > 2.hex) + #expect(2.hex > UInt8(1)) + #expect(UInt8(2) > 1.hex) + #expect(!(1.hex > UInt8(2))) + #expect(!(UInt8(1) > 2.hex)) - XCTAssert(1.hex < 2.hex) - XCTAssertFalse(2.hex < 1.hex) + #expect(1.hex < 2.hex) + #expect(!(2.hex < 1.hex)) - XCTAssert(1.hex < UInt8(2)) - XCTAssert(UInt8(1) < 2.hex) - XCTAssertFalse(2.hex < Int8(1)) - XCTAssertFalse(UInt8(2) < 1.hex) + #expect(1.hex < UInt8(2)) + #expect(UInt8(1) < 2.hex) + #expect(!(2.hex < Int8(1))) + #expect(!(UInt8(2) < 1.hex)) - XCTAssert(1.hex >= 1.hex) - XCTAssert(2.hex >= 1.hex) + #expect(1.hex >= 1.hex) + #expect(2.hex >= 1.hex) - XCTAssert(1.hex >= UInt8(1)) - XCTAssert(UInt8(2) >= 1.hex) + #expect(1.hex >= UInt8(1)) + #expect(UInt8(2) >= 1.hex) - XCTAssert(1.hex <= 2.hex) - XCTAssert(2.hex <= 2.hex) + #expect(1.hex <= 2.hex) + #expect(2.hex <= 2.hex) - XCTAssert(1.hex <= UInt8(2)) - XCTAssert(UInt8(2) <= 2.hex) + #expect(1.hex <= UInt8(2)) + #expect(UInt8(2) <= 2.hex) // Math operators - XCTAssertEqual(2.hex + 2.hex, 4.hex) - XCTAssertEqual(2.hex + 2, 4.hex) - XCTAssertEqual(2 + 2.hex, 4) - XCTAssertEqual(UInt8(2) + UInt8(2).hex, UInt8(4)) + #expect(2.hex + 2.hex == 4.hex) + #expect(2.hex + 2 == 4.hex) + #expect(2 + 2.hex == 4) + #expect(UInt8(2) + UInt8(2).hex == UInt8(4)) - XCTAssertEqual(4.hex - 2.hex, 2.hex) - XCTAssertEqual(4.hex - 2, 2.hex) - XCTAssertEqual(4 - 2.hex, 2) - XCTAssertEqual(UInt8(4) - UInt8(2).hex, UInt8(2)) + #expect(4.hex - 2.hex == 2.hex) + #expect(4.hex - 2 == 2.hex) + #expect(4 - 2.hex == 2) + #expect(UInt8(4) - UInt8(2).hex == UInt8(2)) - XCTAssertEqual(4.hex * 2.hex, 8.hex) - XCTAssertEqual(4.hex * 2, 8.hex) - XCTAssertEqual(4 * 2.hex, 8) - XCTAssertEqual(UInt8(4) * UInt8(2).hex, UInt8(8)) + #expect(4.hex * 2.hex == 8.hex) + #expect(4.hex * 2 == 8.hex) + #expect(4 * 2.hex == 8) + #expect(UInt8(4) * UInt8(2).hex == UInt8(8)) - XCTAssertEqual(8.hex / 2.hex, 4.hex) - XCTAssertEqual(8.hex / 2, 4.hex) - XCTAssertEqual(8 / 2.hex, 4) - XCTAssertEqual(UInt8(8) / UInt8(2).hex, UInt8(4)) + #expect(8.hex / 2.hex == 4.hex) + #expect(8.hex / 2 == 4.hex) + #expect(8 / 2.hex == 4) + #expect(UInt8(8) / UInt8(2).hex == UInt8(4)) // Mutating math operators @@ -95,71 +95,71 @@ final class RadixOperatorsTests: XCTestCase { hexVal = Radix(0, base: 16)! hexVal += 1 - XCTAssert(hexVal == 1) + #expect(hexVal == 1) hexVal += 1.hex - XCTAssert(hexVal == 2) + #expect(hexVal == 2) hexVal -= 1 - XCTAssert(hexVal == 1) + #expect(hexVal == 1) hexVal -= 1.hex - XCTAssert(hexVal == 0) + #expect(hexVal == 0) intVal = 0 intVal += 1.hex - XCTAssert(intVal == 1) + #expect(intVal == 1) intVal -= 1.hex - XCTAssert(intVal == 0) + #expect(intVal == 0) hexVal = Radix(2, base: 16)! hexVal *= 2 - XCTAssert(hexVal == 4) + #expect(hexVal == 4) hexVal *= 2.hex - XCTAssert(hexVal == 8) + #expect(hexVal == 8) hexVal /= 2 - XCTAssert(hexVal == 4) + #expect(hexVal == 4) hexVal /= 2.hex - XCTAssert(hexVal == 2) + #expect(hexVal == 2) intVal = 2 intVal *= 2.hex - XCTAssert(intVal == 4) + #expect(intVal == 4) intVal /= 2.hex - XCTAssert(intVal == 2) + #expect(intVal == 2) // Bitwise bit shift operators - XCTAssertEqual(0b010.hex >> 1, 0b001.hex) - XCTAssertEqual(0b010.hex >> 1.hex, 0b001.hex) - XCTAssertEqual(0b010 >> 1.hex, 0b001) + #expect(0b010.hex >> 1 == 0b001.hex) + #expect(0b010.hex >> 1.hex == 0b001.hex) + #expect(0b010 >> 1.hex == 0b001) - XCTAssertEqual(0b010.hex << 1, 0b100.hex) - XCTAssertEqual(0b010.hex << 1.hex, 0b100.hex) - XCTAssertEqual(0b010 << 1.hex, 0b100) + #expect(0b010.hex << 1 == 0b100.hex) + #expect(0b010.hex << 1.hex == 0b100.hex) + #expect(0b010 << 1.hex == 0b100) // -- mixed types - XCTAssertEqual(UInt8(0b010).hex >> 1, UInt8(0b001).hex) - XCTAssertEqual(0b010.hex >> UInt8(1), 0b001.hex) - XCTAssertEqual(UInt8(0b010).hex >> 1.hex, UInt8(0b001).hex) - XCTAssertEqual(0b010.hex >> UInt8(1).hex, 0b001.hex) - XCTAssertEqual(UInt8(0b010) >> 1.hex, 0b001) - XCTAssertEqual(0b010 >> UInt8(1), 0b001) + #expect(UInt8(0b010).hex >> 1 == UInt8(0b001).hex) + #expect(0b010.hex >> UInt8(1) == 0b001.hex) + #expect(UInt8(0b010).hex >> 1.hex == UInt8(0b001).hex) + #expect(0b010.hex >> UInt8(1).hex == 0b001.hex) + #expect(UInt8(0b010) >> 1.hex == 0b001) + #expect(0b010 >> UInt8(1) == 0b001) - XCTAssertEqual(UInt8(0b010).hex << 1, UInt8(0b100).hex) - XCTAssertEqual(0b010.hex << UInt8(1), 0b100.hex) - XCTAssertEqual(UInt8(0b010).hex << 1.hex, UInt8(0b100).hex) - XCTAssertEqual(0b010.hex << UInt8(1).hex, 0b100.hex) - XCTAssertEqual(UInt8(0b010) << 1.hex, UInt8(0b100)) - XCTAssertEqual(0b010 << UInt8(1).hex, 0b100) + #expect(UInt8(0b010).hex << 1 == UInt8(0b100).hex) + #expect(0b010.hex << UInt8(1) == 0b100.hex) + #expect(UInt8(0b010).hex << 1.hex == UInt8(0b100).hex) + #expect(0b010.hex << UInt8(1).hex == 0b100.hex) + #expect(UInt8(0b010) << 1.hex == UInt8(0b100)) + #expect(0b010 << UInt8(1).hex == 0b100) // Bitwise AND // & operator only supports integers of the same type - XCTAssertEqual(0b11111111.hex & 0b10001000.hex, 0b10001000.hex) - XCTAssertEqual(0b11111111.hex & 0b10001000, 0b10001000.hex) - XCTAssertEqual(0b11111111 & 0b10001000.hex, 0b10001000) + #expect(0b11111111.hex & 0b10001000.hex == 0b10001000.hex) + #expect(0b11111111.hex & 0b10001000 == 0b10001000.hex) + #expect(0b11111111 & 0b10001000.hex == 0b10001000) - XCTAssertEqual( - UInt8(0b11111111).hex & UInt8(0b10001000).hex, + #expect( + UInt8(0b11111111).hex & UInt8(0b10001000).hex == UInt8(0b10001000).hex ) } diff --git a/Tests/SwiftRadixTests/Radix/Radix Protocol Adoptions Tests.swift b/Tests/SwiftRadixTests/Radix/Radix Protocol Adoptions Tests.swift index 98a78c4..568220b 100644 --- a/Tests/SwiftRadixTests/Radix/Radix Protocol Adoptions Tests.swift +++ b/Tests/SwiftRadixTests/Radix/Radix Protocol Adoptions Tests.swift @@ -5,42 +5,42 @@ // import SwiftRadix -import XCTest +import Testing -final class RadixProtocolAdoptionsTests: XCTestCase { - func testRadix_CustomStringConvertible() { +@Suite struct RadixProtocolAdoptionsTests { + @Test func radix_CustomStringConvertible() { // CustomStringConvertible // binary - XCTAssertEqual( - String(describing: 1.binary), + #expect( + String(describing: 1.binary) == "0b1" ) - XCTAssertEqual( - 1.binary.description, + #expect( + 1.binary.description == "0b1" ) // hex - XCTAssertEqual( - String(describing: 1.hex), + #expect( + String(describing: 1.hex) == "0x1" ) - XCTAssertEqual( - 1.hex.description, + #expect( + 1.hex.description == "0x1" ) // octal - XCTAssertEqual( - String(describing: 1.octal), + #expect( + String(describing: 1.octal) == "0o1" ) - XCTAssertEqual( - 1.octal.description, + #expect( + 1.octal.description == "0o1" ) @@ -48,34 +48,34 @@ final class RadixProtocolAdoptionsTests: XCTestCase { // binary - XCTAssertEqual( - 1.binary.debugDescription, + #expect( + 1.binary.debugDescription == "Radix(0b1)" ) // hex - XCTAssertEqual( - 1.hex.debugDescription, + #expect( + 1.hex.debugDescription == "Radix(0x1)" ) // octal - XCTAssertEqual( - 1.octal.debugDescription, + #expect( + 1.octal.debugDescription == "Radix(0o1)" ) } - func testRadix_Hashable() { + @Test func radix_Hashable() { // Dictionary - [Key : Hashable] var dict: [String: Radix] = [:] dict.updateValue(1.hex, forKey: "value1") - XCTAssertEqual(dict["value1"]!.value, 1) + #expect(dict["value1"]!.value == 1) // Set - Hashable @@ -83,10 +83,10 @@ final class RadixProtocolAdoptionsTests: XCTestCase { set.update(with: 1.hex) - XCTAssertEqual(set.count, 1) // should recognize the dupe was not added + #expect(set.count == 1) // should recognize the dupe was not added set.update(with: 2.hex) - XCTAssertEqual(set.count, 2) + #expect(set.count == 2) } } diff --git a/Tests/SwiftRadixTests/Radix/Radix Strings Tests.swift b/Tests/SwiftRadixTests/Radix/Radix Strings Tests.swift index e18f4bd..f0f3f63 100644 --- a/Tests/SwiftRadixTests/Radix/Radix Strings Tests.swift +++ b/Tests/SwiftRadixTests/Radix/Radix Strings Tests.swift @@ -5,89 +5,89 @@ // import SwiftRadix -import XCTest +import Testing -final class RadixStringsTests: XCTestCase { - func testRadix_stringValue_Get() { +@Suite struct RadixStringsTests { + @Test func radix_stringValue_Get() { // binary - XCTAssertEqual(0b0.binary.stringValue, "0") - XCTAssertEqual(0b11001100.binary.stringValue, "11001100") + #expect(0b0.binary.stringValue == "0") + #expect(0b11001100.binary.stringValue == "11001100") // hex - XCTAssertEqual(0x00.hex.stringValue, "0") - XCTAssertEqual(0xFF.hex.stringValue, "FF") + #expect(0x00.hex.stringValue == "0") + #expect(0xFF.hex.stringValue == "FF") // octal - XCTAssertEqual(0x000.octal.stringValue, "0") - XCTAssertEqual(0o123.octal.stringValue, "123") + #expect(0x000.octal.stringValue == "0") + #expect(0o123.octal.stringValue == "123") } - func testRadix_stringValue_Get_Extents() { + @Test func radix_stringValue_Get_Extents() { // binary - XCTAssertEqual( - UInt.max.binary.stringValue, + #expect( + UInt.max.binary.stringValue == "1111111111111111111111111111111111111111111111111111111111111111" ) // hex - XCTAssertEqual( - UInt.max.hex.stringValue, + #expect( + UInt.max.hex.stringValue == "FFFFFFFFFFFFFFFF" ) // octal - XCTAssertEqual( - UInt.max.octal.stringValue, + #expect( + UInt.max.octal.stringValue == "1777777777777777777777" ) } - func testRadix_stringValue_Set() { + @Test func radix_stringValue_Set() { // binary var source1 = 0b0.binary - source1.stringValue = "11001100" // no prefix - XCTAssertEqual(source1.value, 0b11001100) + source1.stringValue = "11001100" // no prefix + #expect(source1.value == 0b11001100) - source1.stringValue = "0b00110011" // with prefix - XCTAssertEqual(source1.value, 0b00110011) + source1.stringValue = "0b00110011" // with prefix + #expect(source1.value == 0b00110011) // hex var source2 = 0x00.hex - source2.stringValue = "FF" // no prefix - XCTAssertEqual(source2.value, 0xFF) + source2.stringValue = "FF" // no prefix + #expect(source2.value == 0xFF) - source2.stringValue = "0xFFFF" // with prefix - XCTAssertEqual(source2.value, 0xFFFF) + source2.stringValue = "0xFFFF" // with prefix + #expect(source2.value == 0xFFFF) // octal var source3 = 0o0.octal - source3.stringValue = "123" // no prefix - XCTAssertEqual(source3.value, 0o123) + source3.stringValue = "123" // no prefix + #expect(source3.value == 0o123) - source3.stringValue = "0o1234" // with prefix - XCTAssertEqual(source3.value, 0o1234) + source3.stringValue = "0o1234" // with prefix + #expect(source3.value == 0o1234) } - func testRadix_stringValue_Set_Extents() { + @Test func radix_stringValue_Set_Extents() { // binary var source1 = UInt(0b0).binary source1.stringValue = "1111111111111111111111111111111111111111111111111111111111111111" - XCTAssertEqual(source1.value, UInt.max) + #expect(source1.value == UInt.max) // hex @@ -95,7 +95,7 @@ final class RadixStringsTests: XCTestCase { source2.stringValue = "FFFFFFFFFFFFFFFF" - XCTAssertEqual(source2.value, UInt.max) + #expect(source2.value == UInt.max) // octal @@ -103,17 +103,17 @@ final class RadixStringsTests: XCTestCase { source3.stringValue = "1777777777777777777777" - XCTAssertEqual(source3.value, UInt.max) + #expect(source3.value == UInt.max) } - func testRadix_stringValue_Set_Extents_EdgeCases() { + @Test func radix_stringValue_Set_Extents_EdgeCases() { // binary var source1 = 0b0.binary source1.stringValue = "1111111111111111111111111111111111111111111111111111111111111111" - XCTAssertEqual(source1.value, 0) // string overflowed Int, set silently fails + #expect(source1.value == 0) // string overflowed Int, set silently fails // hex @@ -121,7 +121,7 @@ final class RadixStringsTests: XCTestCase { source2.stringValue = "FFFFFFFFFFFFFFFF" - XCTAssertEqual(source2.value, 0) // string overflowed Int, set silently fails + #expect(source2.value == 0) // string overflowed Int, set silently fails // octal @@ -129,277 +129,277 @@ final class RadixStringsTests: XCTestCase { source3.stringValue = "1777777777777777777777" - XCTAssertEqual(source3.value, 0) // string overflowed Int, set silently fails + #expect(source3.value == 0) // string overflowed Int, set silently fails } - func testRadix_stringValue_Prefix() { + @Test func radix_stringValue_Prefix() { // binary - XCTAssertEqual(0b0.binary.stringValue(prefix: true), "0b0") - XCTAssertEqual(0b0.binary.stringValue(prefix: false), "0") + #expect(0b0.binary.stringValue(prefix: true) == "0b0") + #expect(0b0.binary.stringValue(prefix: false) == "0") // hex // uppercase - XCTAssertEqual(0b0.hex.stringValue(prefix: true), "0x0") - XCTAssertEqual(0b0.hex.stringValue(prefix: false), "0") + #expect(0b0.hex.stringValue(prefix: true) == "0x0") + #expect(0b0.hex.stringValue(prefix: false) == "0") // lowercase - XCTAssertEqual(0xF.hex.stringValue(prefix: true, uppercase: false), "0xf") - XCTAssertEqual(0xF.hex.stringValue(prefix: false, uppercase: false), "f") + #expect(0xF.hex.stringValue(prefix: true, uppercase: false) == "0xf") + #expect(0xF.hex.stringValue(prefix: false, uppercase: false) == "f") // octal - XCTAssertEqual(0o0.octal.stringValue(prefix: true), "0o0") - XCTAssertEqual(0o0.octal.stringValue(prefix: false), "0") + #expect(0o0.octal.stringValue(prefix: true) == "0o0") + #expect(0o0.octal.stringValue(prefix: false) == "0") } - func testRadix_stringValue_PadTo() { + @Test func radix_stringValue_PadTo() { // binary let source1 = 0b00000111.binary - XCTAssertEqual(source1.stringValue(padTo: 0), "111") - XCTAssertEqual(source1.stringValue(padTo: 1), "111") - XCTAssertEqual(source1.stringValue(padTo: 2), "111") - XCTAssertEqual(source1.stringValue(padTo: 6), "000111") + #expect(source1.stringValue(padTo: 0) == "111") + #expect(source1.stringValue(padTo: 1) == "111") + #expect(source1.stringValue(padTo: 2) == "111") + #expect(source1.stringValue(padTo: 6) == "000111") - XCTAssertEqual(source1.stringValue(padTo: 2, prefix: true), "0b111") - XCTAssertEqual(source1.stringValue(padTo: 6, prefix: true), "0b000111") + #expect(source1.stringValue(padTo: 2, prefix: true) == "0b111") + #expect(source1.stringValue(padTo: 6, prefix: true) == "0b000111") // edge cases - XCTAssertEqual(source1.stringValue(padTo: -1), "111") + #expect(source1.stringValue(padTo: -1) == "111") // hex let source2 = 0x0F.hex // uppercase - XCTAssertEqual(source2.stringValue(padTo: 0), "F") - XCTAssertEqual(source2.stringValue(padTo: 1), "F") - XCTAssertEqual(source2.stringValue(padTo: 2), "0F") - XCTAssertEqual(source2.stringValue(padTo: 6), "00000F") - XCTAssertEqual(source2.stringValue(padTo: 2, prefix: true), "0x0F") + #expect(source2.stringValue(padTo: 0) == "F") + #expect(source2.stringValue(padTo: 1) == "F") + #expect(source2.stringValue(padTo: 2) == "0F") + #expect(source2.stringValue(padTo: 6) == "00000F") + #expect(source2.stringValue(padTo: 2, prefix: true) == "0x0F") // lowercase - XCTAssertEqual(source2.stringValue(padTo: 0, uppercase: false), "f") - XCTAssertEqual(source2.stringValue(padTo: 1, uppercase: false), "f") - XCTAssertEqual(source2.stringValue(padTo: 2, uppercase: false), "0f") - XCTAssertEqual(source2.stringValue(padTo: 6, uppercase: false), "00000f") - XCTAssertEqual(source2.stringValue(padTo: 2, prefix: true, uppercase: false), "0x0f") + #expect(source2.stringValue(padTo: 0, uppercase: false) == "f") + #expect(source2.stringValue(padTo: 1, uppercase: false) == "f") + #expect(source2.stringValue(padTo: 2, uppercase: false) == "0f") + #expect(source2.stringValue(padTo: 6, uppercase: false) == "00000f") + #expect(source2.stringValue(padTo: 2, prefix: true, uppercase: false) == "0x0f") // edge cases - XCTAssertEqual(source2.stringValue(padTo: -1), "F") + #expect(source2.stringValue(padTo: -1) == "F") // octal let source3 = 0o17.octal - XCTAssertEqual(source3.stringValue(padTo: 0), "17") - XCTAssertEqual(source3.stringValue(padTo: 1), "17") - XCTAssertEqual(source3.stringValue(padTo: 2), "17") - XCTAssertEqual(source3.stringValue(padTo: 6), "000017") + #expect(source3.stringValue(padTo: 0) == "17") + #expect(source3.stringValue(padTo: 1) == "17") + #expect(source3.stringValue(padTo: 2) == "17") + #expect(source3.stringValue(padTo: 6) == "000017") - XCTAssertEqual(source3.stringValue(padTo: 2, prefix: true), "0o17") + #expect(source3.stringValue(padTo: 2, prefix: true) == "0o17") // edge cases - XCTAssertEqual(source3.stringValue(padTo: -1), "17") + #expect(source3.stringValue(padTo: -1) == "17") } - func testRadix_stringValue_PadTo_EdgeCases() { + @Test func radix_stringValue_PadTo_EdgeCases() { // ensure padding of 0 or a negative value defaults to an internal padding of 1 // binary - XCTAssertEqual(0b0.binary.stringValue(padTo: -1), "0") - XCTAssertEqual(0b0.binary.stringValue(padTo: 0), "0") + #expect(0b0.binary.stringValue(padTo: -1) == "0") + #expect(0b0.binary.stringValue(padTo: 0) == "0") // hex - XCTAssertEqual(0x0.hex.stringValue(padTo: -1), "0") - XCTAssertEqual(0x0.hex.stringValue(padTo: 0), "0") + #expect(0x0.hex.stringValue(padTo: -1) == "0") + #expect(0x0.hex.stringValue(padTo: 0) == "0") // octal - XCTAssertEqual(0o0.hex.stringValue(padTo: -1), "0") - XCTAssertEqual(0o0.hex.stringValue(padTo: 0), "0") + #expect(0o0.hex.stringValue(padTo: -1) == "0") + #expect(0o0.hex.stringValue(padTo: 0) == "0") } - func testRadix_stringValue_PadTo_SplitEvery() { + @Test func radix_stringValue_PadTo_SplitEvery() { // binary let source1 = 0b00000111.binary - XCTAssertEqual(source1.stringValue(padTo: 0, splitEvery: 0), "111") - XCTAssertEqual(source1.stringValue(padTo: 1, splitEvery: 1), "1 1 1") - XCTAssertEqual(source1.stringValue(padTo: 1, splitEvery: 2), "1 11") - XCTAssertEqual(source1.stringValue(padTo: 2, splitEvery: 2), "1 11") - XCTAssertEqual(source1.stringValue(padTo: 4, splitEvery: 3), "0 111") + #expect(source1.stringValue(padTo: 0, splitEvery: 0) == "111") + #expect(source1.stringValue(padTo: 1, splitEvery: 1) == "1 1 1") + #expect(source1.stringValue(padTo: 1, splitEvery: 2) == "1 11") + #expect(source1.stringValue(padTo: 2, splitEvery: 2) == "1 11") + #expect(source1.stringValue(padTo: 4, splitEvery: 3) == "0 111") // prefix treats it as a Swift Integer Literal, inserting underscores for splits - XCTAssertEqual(source1.stringValue(padTo: 8, splitEvery: 2, prefix: true), "0b00_00_01_11") + #expect(source1.stringValue(padTo: 8, splitEvery: 2, prefix: true) == "0b00_00_01_11") // edge cases - XCTAssertEqual(source1.stringValue(padTo: 2, splitEvery: -1), "111") + #expect(source1.stringValue(padTo: 2, splitEvery: -1) == "111") // hex let source2 = 0xF0F.hex // uppercase - XCTAssertEqual(source2.stringValue(padTo: 0, splitEvery: 0), "F0F") - XCTAssertEqual(source2.stringValue(padTo: 1, splitEvery: 1), "F 0 F") - XCTAssertEqual(source2.stringValue(padTo: 2, splitEvery: 2), "F 0F") - XCTAssertEqual(source2.stringValue(padTo: 8, splitEvery: 3), "00 000 F0F") + #expect(source2.stringValue(padTo: 0, splitEvery: 0) == "F0F") + #expect(source2.stringValue(padTo: 1, splitEvery: 1) == "F 0 F") + #expect(source2.stringValue(padTo: 2, splitEvery: 2) == "F 0F") + #expect(source2.stringValue(padTo: 8, splitEvery: 3) == "00 000 F0F") // (prefix treats it as a Swift Integer Literal, inserting underscores for splits) - XCTAssertEqual(source2.stringValue(padTo: 8, splitEvery: 2, prefix: true), "0x00_00_0F_0F") + #expect(source2.stringValue(padTo: 8, splitEvery: 2, prefix: true) == "0x00_00_0F_0F") // lowercase - XCTAssertEqual(source2.stringValue(padTo: 0, splitEvery: 0, uppercase: false), "f0f") - XCTAssertEqual(source2.stringValue(padTo: 1, splitEvery: 1, uppercase: false), "f 0 f") - XCTAssertEqual(source2.stringValue(padTo: 2, splitEvery: 2, uppercase: false), "f 0f") - XCTAssertEqual(source2.stringValue(padTo: 8, splitEvery: 3, uppercase: false), "00 000 f0f") + #expect(source2.stringValue(padTo: 0, splitEvery: 0, uppercase: false) == "f0f") + #expect(source2.stringValue(padTo: 1, splitEvery: 1, uppercase: false) == "f 0 f") + #expect(source2.stringValue(padTo: 2, splitEvery: 2, uppercase: false) == "f 0f") + #expect(source2.stringValue(padTo: 8, splitEvery: 3, uppercase: false) == "00 000 f0f") // (prefix treats it as a Swift Integer Literal, inserting underscores for splits) - XCTAssertEqual( - source2.stringValue(padTo: 8, splitEvery: 2, prefix: true, uppercase: false), + #expect( + source2.stringValue(padTo: 8, splitEvery: 2, prefix: true, uppercase: false) == "0x00_00_0f_0f" ) // edge cases - XCTAssertEqual(source2.stringValue(padTo: 2, splitEvery: -1), "F0F") + #expect(source2.stringValue(padTo: 2, splitEvery: -1) == "F0F") // octal let source3 = 0o7.octal - XCTAssertEqual(source3.stringValue(padTo: 0, splitEvery: 0), "7") - XCTAssertEqual(source3.stringValue(padTo: 1, splitEvery: 1), "7") - XCTAssertEqual(source3.stringValue(padTo: 2, splitEvery: 2), "07") - XCTAssertEqual(source3.stringValue(padTo: 4, splitEvery: 3), "0 007") + #expect(source3.stringValue(padTo: 0, splitEvery: 0) == "7") + #expect(source3.stringValue(padTo: 1, splitEvery: 1) == "7") + #expect(source3.stringValue(padTo: 2, splitEvery: 2) == "07") + #expect(source3.stringValue(padTo: 4, splitEvery: 3) == "0 007") // prefix treats it as a Swift Integer Literal, inserting underscores for splits - XCTAssertEqual(source3.stringValue(padTo: 2, splitEvery: 2, prefix: true), "0o07") + #expect(source3.stringValue(padTo: 2, splitEvery: 2, prefix: true) == "0o07") // edge cases - XCTAssertEqual(source3.stringValue(padTo: 2, splitEvery: -1), "07") + #expect(source3.stringValue(padTo: 2, splitEvery: -1) == "07") } - func testRadix_stringValue_PadToEvery() { + @Test func radix_stringValue_PadToEvery() { // binary let source1 = 0b00011111.binary - XCTAssertEqual(source1.stringValue(padToEvery: 0), "11111") - XCTAssertEqual(source1.stringValue(padToEvery: 1), "11111") - XCTAssertEqual(source1.stringValue(padToEvery: 2), "011111") - XCTAssertEqual(source1.stringValue(padToEvery: 4), "00011111") + #expect(source1.stringValue(padToEvery: 0) == "11111") + #expect(source1.stringValue(padToEvery: 1) == "11111") + #expect(source1.stringValue(padToEvery: 2) == "011111") + #expect(source1.stringValue(padToEvery: 4) == "00011111") - XCTAssertEqual(source1.stringValue(padToEvery: 2, prefix: true), "0b011111") + #expect(source1.stringValue(padToEvery: 2, prefix: true) == "0b011111") // edge cases - XCTAssertEqual(source1.stringValue(padToEvery: -1), "11111") + #expect(source1.stringValue(padToEvery: -1) == "11111") // hex let source2 = 0xFFF.hex // uppercase - XCTAssertEqual(source2.stringValue(padToEvery: 0), "FFF") - XCTAssertEqual(source2.stringValue(padToEvery: 1), "FFF") - XCTAssertEqual(source2.stringValue(padToEvery: 2), "0FFF") - XCTAssertEqual(source2.stringValue(padToEvery: 6), "000FFF") - XCTAssertEqual(source2.stringValue(padToEvery: 2, prefix: true), "0x0FFF") + #expect(source2.stringValue(padToEvery: 0) == "FFF") + #expect(source2.stringValue(padToEvery: 1) == "FFF") + #expect(source2.stringValue(padToEvery: 2) == "0FFF") + #expect(source2.stringValue(padToEvery: 6) == "000FFF") + #expect(source2.stringValue(padToEvery: 2, prefix: true) == "0x0FFF") // lowercase - XCTAssertEqual(source2.stringValue(padToEvery: 0, uppercase: false), "fff") - XCTAssertEqual(source2.stringValue(padToEvery: 1, uppercase: false), "fff") - XCTAssertEqual(source2.stringValue(padToEvery: 2, uppercase: false), "0fff") - XCTAssertEqual(source2.stringValue(padToEvery: 6, uppercase: false), "000fff") - XCTAssertEqual(source2.stringValue(padToEvery: 2, prefix: true, uppercase: false), "0x0fff") + #expect(source2.stringValue(padToEvery: 0, uppercase: false) == "fff") + #expect(source2.stringValue(padToEvery: 1, uppercase: false) == "fff") + #expect(source2.stringValue(padToEvery: 2, uppercase: false) == "0fff") + #expect(source2.stringValue(padToEvery: 6, uppercase: false) == "000fff") + #expect(source2.stringValue(padToEvery: 2, prefix: true, uppercase: false) == "0x0fff") // edge cases - XCTAssertEqual(source2.stringValue(padToEvery: -1), "FFF") + #expect(source2.stringValue(padToEvery: -1) == "FFF") // octal let source3 = 0o123456.octal - XCTAssertEqual(source3.stringValue(padToEvery: 0), "123456") - XCTAssertEqual(source3.stringValue(padToEvery: 1), "123456") - XCTAssertEqual(source3.stringValue(padToEvery: 2), "123456") - XCTAssertEqual(source3.stringValue(padToEvery: 4), "00123456") + #expect(source3.stringValue(padToEvery: 0) == "123456") + #expect(source3.stringValue(padToEvery: 1) == "123456") + #expect(source3.stringValue(padToEvery: 2) == "123456") + #expect(source3.stringValue(padToEvery: 4) == "00123456") - XCTAssertEqual(source3.stringValue(padToEvery: 2, prefix: true), "0o123456") + #expect(source3.stringValue(padToEvery: 2, prefix: true) == "0o123456") // edge cases - XCTAssertEqual(source3.stringValue(padToEvery: -1), "123456") + #expect(source3.stringValue(padToEvery: -1) == "123456") } - func testRadix_stringValue_PadToEvery_SplitEvery() { + @Test func radix_stringValue_PadToEvery_SplitEvery() { // binary let source1 = 0b00011111.binary - XCTAssertEqual(source1.stringValue(padToEvery: 0, splitEvery: 0), "11111") - XCTAssertEqual(source1.stringValue(padToEvery: 1, splitEvery: 1), "1 1 1 1 1") - XCTAssertEqual(source1.stringValue(padToEvery: 1, splitEvery: 2), "1 11 11") - XCTAssertEqual(source1.stringValue(padToEvery: 2, splitEvery: 2), "01 11 11") - XCTAssertEqual(source1.stringValue(padToEvery: 4, splitEvery: 3), "00 011 111") + #expect(source1.stringValue(padToEvery: 0, splitEvery: 0) == "11111") + #expect(source1.stringValue(padToEvery: 1, splitEvery: 1) == "1 1 1 1 1") + #expect(source1.stringValue(padToEvery: 1, splitEvery: 2) == "1 11 11") + #expect(source1.stringValue(padToEvery: 2, splitEvery: 2) == "01 11 11") + #expect(source1.stringValue(padToEvery: 4, splitEvery: 3) == "00 011 111") // prefix treats it as a Swift Integer Literal, inserting underscores for splits - XCTAssertEqual( - source1.stringValue(padToEvery: 2, splitEvery: 2, prefix: true), + #expect( + source1.stringValue(padToEvery: 2, splitEvery: 2, prefix: true) == "0b01_11_11" ) // edge cases - XCTAssertEqual(source1.stringValue(padToEvery: 2, splitEvery: -1), "011111") + #expect(source1.stringValue(padToEvery: 2, splitEvery: -1) == "011111") // hex let source2 = 0xFFF.hex // uppercase - XCTAssertEqual(source2.stringValue(padToEvery: 0, splitEvery: 0), "FFF") - XCTAssertEqual(source2.stringValue(padToEvery: 1, splitEvery: 1), "F F F") - XCTAssertEqual(source2.stringValue(padToEvery: 2, splitEvery: 2), "0F FF") - XCTAssertEqual(source2.stringValue(padToEvery: 8, splitEvery: 3), "00 000 FFF") + #expect(source2.stringValue(padToEvery: 0, splitEvery: 0) == "FFF") + #expect(source2.stringValue(padToEvery: 1, splitEvery: 1) == "F F F") + #expect(source2.stringValue(padToEvery: 2, splitEvery: 2) == "0F FF") + #expect(source2.stringValue(padToEvery: 8, splitEvery: 3) == "00 000 FFF") // (prefix treats it as a Swift Integer Literal, inserting underscores for splits) - XCTAssertEqual(source2.stringValue(padToEvery: 2, splitEvery: 2, prefix: true), "0x0F_FF") + #expect(source2.stringValue(padToEvery: 2, splitEvery: 2, prefix: true) == "0x0F_FF") // lowercase - XCTAssertEqual(source2.stringValue(padToEvery: 0, splitEvery: 0, uppercase: false), "fff") - XCTAssertEqual(source2.stringValue(padToEvery: 1, splitEvery: 1, uppercase: false), "f f f") - XCTAssertEqual(source2.stringValue(padToEvery: 2, splitEvery: 2, uppercase: false), "0f ff") - XCTAssertEqual( - source2.stringValue(padToEvery: 8, splitEvery: 3, uppercase: false), + #expect(source2.stringValue(padToEvery: 0, splitEvery: 0, uppercase: false) == "fff") + #expect(source2.stringValue(padToEvery: 1, splitEvery: 1, uppercase: false) == "f f f") + #expect(source2.stringValue(padToEvery: 2, splitEvery: 2, uppercase: false) == "0f ff") + #expect( + source2.stringValue(padToEvery: 8, splitEvery: 3, uppercase: false) == "00 000 fff" ) // (prefix treats it as a Swift Integer Literal, inserting underscores for splits) - XCTAssertEqual( - source2.stringValue(padToEvery: 2, splitEvery: 2, prefix: true, uppercase: false), + #expect( + source2.stringValue(padToEvery: 2, splitEvery: 2, prefix: true, uppercase: false) == "0x0f_ff" ) // edge cases - XCTAssertEqual(source2.stringValue(padToEvery: 2, splitEvery: -1), "0FFF") + #expect(source2.stringValue(padToEvery: 2, splitEvery: -1) == "0FFF") // octal let source3 = 0o123456.octal - XCTAssertEqual(source3.stringValue(padToEvery: 0, splitEvery: 0), "123456") - XCTAssertEqual(source3.stringValue(padToEvery: 1, splitEvery: 1), "1 2 3 4 5 6") - XCTAssertEqual(source3.stringValue(padToEvery: 2, splitEvery: 2), "12 34 56") - XCTAssertEqual(source3.stringValue(padToEvery: 4, splitEvery: 3), "00 123 456") + #expect(source3.stringValue(padToEvery: 0, splitEvery: 0) == "123456") + #expect(source3.stringValue(padToEvery: 1, splitEvery: 1) == "1 2 3 4 5 6") + #expect(source3.stringValue(padToEvery: 2, splitEvery: 2) == "12 34 56") + #expect(source3.stringValue(padToEvery: 4, splitEvery: 3) == "00 123 456") // prefix treats it as a Swift Integer Literal, inserting underscores for splits - XCTAssertEqual( - source3.stringValue(padToEvery: 2, splitEvery: 2, prefix: true), + #expect( + source3.stringValue(padToEvery: 2, splitEvery: 2, prefix: true) == "0o12_34_56" ) // edge cases - XCTAssertEqual(source3.stringValue(padToEvery: 2, splitEvery: -1), "123456") + #expect(source3.stringValue(padToEvery: 2, splitEvery: -1) == "123456") } } diff --git a/Tests/SwiftRadixTests/Radix/Radix Tests.swift b/Tests/SwiftRadixTests/Radix/Radix Tests.swift index 8740c81..7c8fce8 100644 --- a/Tests/SwiftRadixTests/Radix/Radix Tests.swift +++ b/Tests/SwiftRadixTests/Radix/Radix Tests.swift @@ -5,47 +5,47 @@ // import SwiftRadix -import XCTest +import Testing -final class RadixTests: XCTestCase { - func testRadix_Init_Integer() { +@Suite struct RadixTests { + @Test func radix_Init_Integer() { // basic init test, to check if it accepts a variety of integer types and radices // Int let radix1 = Radix(0xFF, base: 16)! - XCTAssertEqual(radix1.value.bitWidth, Int.bitWidth) - XCTAssertEqual(radix1.value, 0xFF) - XCTAssertEqual(radix1.base, 16) + #expect(radix1.value.bitWidth == Int.bitWidth) + #expect(radix1.value == 0xFF) + #expect(radix1.base == 16) // UInt8 let radix2 = Radix(UInt8(0xFF), base: 8)! - XCTAssertEqual(radix2.value.bitWidth, UInt8.bitWidth) - XCTAssertEqual(radix2.value, 0xFF) - XCTAssertEqual(radix2.base, 8) + #expect(radix2.value.bitWidth == UInt8.bitWidth) + #expect(radix2.value == 0xFF) + #expect(radix2.base == 8) } - func testRadix_Init_String() { + @Test func radix_Init_String() { // basic init test // Int let radix1 = Radix("0xFF", base: 16)! - XCTAssertEqual(radix1.value.bitWidth, Int.bitWidth) - XCTAssertEqual(radix1.value, 0xFF) - XCTAssertEqual(radix1.base, 16) + #expect(radix1.value.bitWidth == Int.bitWidth) + #expect(radix1.value == 0xFF) + #expect(radix1.base == 16) // UInt8 let radix2 = Radix("0xFF", base: 16) - XCTAssertEqual(radix2?.value.bitWidth, UInt8.bitWidth) - XCTAssertEqual(radix2?.value, 0xFF) - XCTAssertEqual(radix2?.base, 16) + #expect(radix2?.value.bitWidth == UInt8.bitWidth) + #expect(radix2?.value == 0xFF) + #expect(radix2?.base == 16) // edge cases @@ -53,424 +53,424 @@ final class RadixTests: XCTestCase { let radix3 = Radix("", base: 16) - XCTAssertNil(radix3) + #expect(radix3 == nil) } - func testRadix_Init_Integer_InvalidRadix() { + @Test func radix_Init_Integer_InvalidRadix() { // invalid radix (outside 2...36) - XCTAssertNil(Radix(123, base: -1)) - XCTAssertNil(Radix(123, base: 0)) - XCTAssertNil(Radix(123, base: 1)) - XCTAssertNil(Radix(123, base: 37)) + #expect(Radix(123, base: -1) == nil) + #expect(Radix(123, base: 0) == nil) + #expect(Radix(123, base: 1) == nil) + #expect(Radix(123, base: 37) == nil) } - func testRadix_Init_String_InvalidRadix() { + @Test func radix_Init_String_InvalidRadix() { // invalid radix (outside 2...36) - XCTAssertNil(Radix("1", base: -1)) - XCTAssertNil(Radix("1", base: 0)) - XCTAssertNil(Radix("1", base: 1)) - XCTAssertNil(Radix("1", base: 37)) + #expect(Radix("1", base: -1) == nil) + #expect(Radix("1", base: 0) == nil) + #expect(Radix("1", base: 1) == nil) + #expect(Radix("1", base: 37) == nil) } - func testRadix_Init_Integer_NonStandardRadix() { + @Test func radix_Init_Integer_NonStandardRadix() { // base-2 is binary; skip testing it here let radix3 = Radix(123, base: 3)! - XCTAssertEqual(radix3.value, 123) - XCTAssertEqual(radix3.base, 3) - XCTAssertEqual(radix3.stringValue, "11120") + #expect(radix3.value == 123) + #expect(radix3.base == 3) + #expect(radix3.stringValue == "11120") let radix4 = Radix(123, base: 4)! - XCTAssertEqual(radix4.value, 123) - XCTAssertEqual(radix4.base, 4) - XCTAssertEqual(radix4.stringValue, "1323") + #expect(radix4.value == 123) + #expect(radix4.base == 4) + #expect(radix4.stringValue == "1323") let radix5 = Radix(123, base: 5)! - XCTAssertEqual(radix5.value, 123) - XCTAssertEqual(radix5.base, 5) - XCTAssertEqual(radix5.stringValue, "443") + #expect(radix5.value == 123) + #expect(radix5.base == 5) + #expect(radix5.stringValue == "443") let radix6 = Radix(123, base: 6)! - XCTAssertEqual(radix6.value, 123) - XCTAssertEqual(radix6.base, 6) - XCTAssertEqual(radix6.stringValue, "323") + #expect(radix6.value == 123) + #expect(radix6.base == 6) + #expect(radix6.stringValue == "323") let radix7 = Radix(123, base: 7)! - XCTAssertEqual(radix7.value, 123) - XCTAssertEqual(radix7.base, 7) - XCTAssertEqual(radix7.stringValue, "234") + #expect(radix7.value == 123) + #expect(radix7.base == 7) + #expect(radix7.stringValue == "234") // base-8 is octal; skip testing it here let radix9 = Radix(123, base: 9)! - XCTAssertEqual(radix9.value, 123) - XCTAssertEqual(radix9.base, 9) - XCTAssertEqual(radix9.stringValue, "146") + #expect(radix9.value == 123) + #expect(radix9.base == 9) + #expect(radix9.stringValue == "146") let radix10 = Radix(123, base: 10)! - XCTAssertEqual(radix10.value, 123) - XCTAssertEqual(radix10.base, 10) - XCTAssertEqual(radix10.stringValue, "123") + #expect(radix10.value == 123) + #expect(radix10.base == 10) + #expect(radix10.stringValue == "123") let radix11 = Radix(123, base: 11)! - XCTAssertEqual(radix11.value, 123) - XCTAssertEqual(radix11.base, 11) - XCTAssertEqual(radix11.stringValue, "102") + #expect(radix11.value == 123) + #expect(radix11.base == 11) + #expect(radix11.stringValue == "102") let radix12 = Radix(123, base: 12)! - XCTAssertEqual(radix12.value, 123) - XCTAssertEqual(radix12.base, 12) - XCTAssertEqual(radix12.stringValue, "A3") + #expect(radix12.value == 123) + #expect(radix12.base == 12) + #expect(radix12.stringValue == "A3") let radix13 = Radix(123, base: 13)! - XCTAssertEqual(radix13.value, 123) - XCTAssertEqual(radix13.base, 13) - XCTAssertEqual(radix13.stringValue, "96") + #expect(radix13.value == 123) + #expect(radix13.base == 13) + #expect(radix13.stringValue == "96") let radix14 = Radix(123, base: 14)! - XCTAssertEqual(radix14.value, 123) - XCTAssertEqual(radix14.base, 14) - XCTAssertEqual(radix14.stringValue, "8B") + #expect(radix14.value == 123) + #expect(radix14.base == 14) + #expect(radix14.stringValue == "8B") let radix15 = Radix(123, base: 15)! - XCTAssertEqual(radix15.value, 123) - XCTAssertEqual(radix15.base, 15) - XCTAssertEqual(radix15.stringValue, "83") + #expect(radix15.value == 123) + #expect(radix15.base == 15) + #expect(radix15.stringValue == "83") // base-16 is hex; skip testing it here let radix17 = Radix(123, base: 17)! - XCTAssertEqual(radix17.value, 123) - XCTAssertEqual(radix17.base, 17) - XCTAssertEqual(radix17.stringValue, "74") + #expect(radix17.value == 123) + #expect(radix17.base == 17) + #expect(radix17.stringValue == "74") let radix18 = Radix(123, base: 18)! - XCTAssertEqual(radix18.value, 123) - XCTAssertEqual(radix18.base, 18) - XCTAssertEqual(radix18.stringValue, "6F") + #expect(radix18.value == 123) + #expect(radix18.base == 18) + #expect(radix18.stringValue == "6F") let radix19 = Radix(123, base: 19)! - XCTAssertEqual(radix19.value, 123) - XCTAssertEqual(radix19.base, 19) - XCTAssertEqual(radix19.stringValue, "69") + #expect(radix19.value == 123) + #expect(radix19.base == 19) + #expect(radix19.stringValue == "69") let radix20 = Radix(123, base: 20)! - XCTAssertEqual(radix20.value, 123) - XCTAssertEqual(radix20.base, 20) - XCTAssertEqual(radix20.stringValue, "63") + #expect(radix20.value == 123) + #expect(radix20.base == 20) + #expect(radix20.stringValue == "63") let radix21 = Radix(123, base: 21)! - XCTAssertEqual(radix21.value, 123) - XCTAssertEqual(radix21.base, 21) - XCTAssertEqual(radix21.stringValue, "5I") + #expect(radix21.value == 123) + #expect(radix21.base == 21) + #expect(radix21.stringValue == "5I") let radix22 = Radix(123, base: 22)! - XCTAssertEqual(radix22.value, 123) - XCTAssertEqual(radix22.base, 22) - XCTAssertEqual(radix22.stringValue, "5D") + #expect(radix22.value == 123) + #expect(radix22.base == 22) + #expect(radix22.stringValue == "5D") let radix23 = Radix(123, base: 23)! - XCTAssertEqual(radix23.value, 123) - XCTAssertEqual(radix23.base, 23) - XCTAssertEqual(radix23.stringValue, "58") + #expect(radix23.value == 123) + #expect(radix23.base == 23) + #expect(radix23.stringValue == "58") let radix24 = Radix(123, base: 24)! - XCTAssertEqual(radix24.value, 123) - XCTAssertEqual(radix24.base, 24) - XCTAssertEqual(radix24.stringValue, "53") + #expect(radix24.value == 123) + #expect(radix24.base == 24) + #expect(radix24.stringValue == "53") let radix25 = Radix(123, base: 25)! - XCTAssertEqual(radix25.value, 123) - XCTAssertEqual(radix25.base, 25) - XCTAssertEqual(radix25.stringValue, "4N") + #expect(radix25.value == 123) + #expect(radix25.base == 25) + #expect(radix25.stringValue == "4N") let radix26 = Radix(123, base: 26)! - XCTAssertEqual(radix26.value, 123) - XCTAssertEqual(radix26.base, 26) - XCTAssertEqual(radix26.stringValue, "4J") + #expect(radix26.value == 123) + #expect(radix26.base == 26) + #expect(radix26.stringValue == "4J") let radix27 = Radix(123, base: 27)! - XCTAssertEqual(radix27.value, 123) - XCTAssertEqual(radix27.base, 27) - XCTAssertEqual(radix27.stringValue, "4F") + #expect(radix27.value == 123) + #expect(radix27.base == 27) + #expect(radix27.stringValue == "4F") let radix28 = Radix(123, base: 28)! - XCTAssertEqual(radix28.value, 123) - XCTAssertEqual(radix28.base, 28) - XCTAssertEqual(radix28.stringValue, "4B") + #expect(radix28.value == 123) + #expect(radix28.base == 28) + #expect(radix28.stringValue == "4B") let radix29 = Radix(123, base: 29)! - XCTAssertEqual(radix29.value, 123) - XCTAssertEqual(radix29.base, 29) - XCTAssertEqual(radix29.stringValue, "47") + #expect(radix29.value == 123) + #expect(radix29.base == 29) + #expect(radix29.stringValue == "47") let radix30 = Radix(123, base: 30)! - XCTAssertEqual(radix30.value, 123) - XCTAssertEqual(radix30.base, 30) - XCTAssertEqual(radix30.stringValue, "43") + #expect(radix30.value == 123) + #expect(radix30.base == 30) + #expect(radix30.stringValue == "43") let radix31 = Radix(123, base: 31)! - XCTAssertEqual(radix31.value, 123) - XCTAssertEqual(radix31.base, 31) - XCTAssertEqual(radix31.stringValue, "3U") + #expect(radix31.value == 123) + #expect(radix31.base == 31) + #expect(radix31.stringValue == "3U") let radix32 = Radix(123, base: 32)! - XCTAssertEqual(radix32.value, 123) - XCTAssertEqual(radix32.base, 32) - XCTAssertEqual(radix32.stringValue, "3R") + #expect(radix32.value == 123) + #expect(radix32.base == 32) + #expect(radix32.stringValue == "3R") let radix33 = Radix(123, base: 33)! - XCTAssertEqual(radix33.value, 123) - XCTAssertEqual(radix33.base, 33) - XCTAssertEqual(radix33.stringValue, "3O") + #expect(radix33.value == 123) + #expect(radix33.base == 33) + #expect(radix33.stringValue == "3O") let radix34 = Radix(123, base: 34)! - XCTAssertEqual(radix34.value, 123) - XCTAssertEqual(radix34.base, 34) - XCTAssertEqual(radix34.stringValue, "3L") + #expect(radix34.value == 123) + #expect(radix34.base == 34) + #expect(radix34.stringValue == "3L") let radix35 = Radix(123, base: 35)! - XCTAssertEqual(radix35.value, 123) - XCTAssertEqual(radix35.base, 35) - XCTAssertEqual(radix35.stringValue, "3I") + #expect(radix35.value == 123) + #expect(radix35.base == 35) + #expect(radix35.stringValue == "3I") let radix36 = Radix(123, base: 36)! - XCTAssertEqual(radix36.value, 123) - XCTAssertEqual(radix36.base, 36) - XCTAssertEqual(radix36.stringValue, "3F") + #expect(radix36.value == 123) + #expect(radix36.base == 36) + #expect(radix36.stringValue == "3F") } - func testRadix_Init_String_NonStandardRadix() { + @Test func radix_Init_String_NonStandardRadix() { // base-2 is binary; skip testing it here let radix3 = Radix("11120", base: 3) - XCTAssertNotNil(radix3) - XCTAssertEqual(radix3?.value, 123) - XCTAssertEqual(radix3?.base, 3) + #expect(radix3 != nil) + #expect(radix3?.value == 123) + #expect(radix3?.base == 3) let radix4 = Radix("1323", base: 4) - XCTAssertNotNil(radix4) - XCTAssertEqual(radix4?.value, 123) - XCTAssertEqual(radix4?.base, 4) + #expect(radix4 != nil) + #expect(radix4?.value == 123) + #expect(radix4?.base == 4) let radix5 = Radix("443", base: 5) - XCTAssertNotNil(radix5) - XCTAssertEqual(radix5?.value, 123) - XCTAssertEqual(radix5?.base, 5) + #expect(radix5 != nil) + #expect(radix5?.value == 123) + #expect(radix5?.base == 5) let radix6 = Radix("323", base: 6) - XCTAssertNotNil(radix6) - XCTAssertEqual(radix6?.value, 123) - XCTAssertEqual(radix6?.base, 6) + #expect(radix6 != nil) + #expect(radix6?.value == 123) + #expect(radix6?.base == 6) let radix7 = Radix("234", base: 7) - XCTAssertNotNil(radix7) - XCTAssertEqual(radix7?.value, 123) - XCTAssertEqual(radix7?.base, 7) + #expect(radix7 != nil) + #expect(radix7?.value == 123) + #expect(radix7?.base == 7) // base-8 is octal; skip testing it here let radix9 = Radix("146", base: 9) - XCTAssertNotNil(radix9) - XCTAssertEqual(radix9?.value, 123) - XCTAssertEqual(radix9?.base, 9) + #expect(radix9 != nil) + #expect(radix9?.value == 123) + #expect(radix9?.base == 9) let radix10 = Radix("123", base: 10) - XCTAssertNotNil(radix10) - XCTAssertEqual(radix10?.value, 123) - XCTAssertEqual(radix10?.base, 10) + #expect(radix10 != nil) + #expect(radix10?.value == 123) + #expect(radix10?.base == 10) let radix11 = Radix("102", base: 11) - XCTAssertNotNil(radix11) - XCTAssertEqual(radix11?.value, 123) - XCTAssertEqual(radix11?.base, 11) + #expect(radix11 != nil) + #expect(radix11?.value == 123) + #expect(radix11?.base == 11) let radix12 = Radix("A3", base: 12) - XCTAssertNotNil(radix12) - XCTAssertEqual(radix12?.value, 123) - XCTAssertEqual(radix12?.base, 12) + #expect(radix12 != nil) + #expect(radix12?.value == 123) + #expect(radix12?.base == 12) let radix13 = Radix("96", base: 13) - XCTAssertNotNil(radix13) - XCTAssertEqual(radix13?.value, 123) - XCTAssertEqual(radix13?.base, 13) + #expect(radix13 != nil) + #expect(radix13?.value == 123) + #expect(radix13?.base == 13) let radix14 = Radix("8B", base: 14) - XCTAssertNotNil(radix14) - XCTAssertEqual(radix14?.value, 123) - XCTAssertEqual(radix14?.base, 14) + #expect(radix14 != nil) + #expect(radix14?.value == 123) + #expect(radix14?.base == 14) let radix15 = Radix("83", base: 15) // base-16 is hex; skip testing it here - XCTAssertNotNil(radix15) - XCTAssertEqual(radix15?.value, 123) - XCTAssertEqual(radix15?.base, 15) + #expect(radix15 != nil) + #expect(radix15?.value == 123) + #expect(radix15?.base == 15) let radix17 = Radix("74", base: 17) - XCTAssertNotNil(radix17) - XCTAssertEqual(radix17?.value, 123) - XCTAssertEqual(radix17?.base, 17) + #expect(radix17 != nil) + #expect(radix17?.value == 123) + #expect(radix17?.base == 17) let radix18 = Radix("6F", base: 18) - XCTAssertNotNil(radix18) - XCTAssertEqual(radix18?.value, 123) - XCTAssertEqual(radix18?.base, 18) + #expect(radix18 != nil) + #expect(radix18?.value == 123) + #expect(radix18?.base == 18) let radix19 = Radix("69", base: 19) - XCTAssertNotNil(radix19) - XCTAssertEqual(radix19?.value, 123) - XCTAssertEqual(radix19?.base, 19) + #expect(radix19 != nil) + #expect(radix19?.value == 123) + #expect(radix19?.base == 19) let radix20 = Radix("63", base: 20) - XCTAssertNotNil(radix20) - XCTAssertEqual(radix20?.value, 123) - XCTAssertEqual(radix20?.base, 20) + #expect(radix20 != nil) + #expect(radix20?.value == 123) + #expect(radix20?.base == 20) let radix21 = Radix("5I", base: 21) - XCTAssertNotNil(radix21) - XCTAssertEqual(radix21?.value, 123) - XCTAssertEqual(radix21?.base, 21) + #expect(radix21 != nil) + #expect(radix21?.value == 123) + #expect(radix21?.base == 21) let radix22 = Radix("5D", base: 22) - XCTAssertNotNil(radix22) - XCTAssertEqual(radix22?.value, 123) - XCTAssertEqual(radix22?.base, 22) + #expect(radix22 != nil) + #expect(radix22?.value == 123) + #expect(radix22?.base == 22) let radix23 = Radix("58", base: 23) - XCTAssertNotNil(radix23) - XCTAssertEqual(radix23?.value, 123) - XCTAssertEqual(radix23?.base, 23) + #expect(radix23 != nil) + #expect(radix23?.value == 123) + #expect(radix23?.base == 23) let radix24 = Radix("53", base: 24) - XCTAssertNotNil(radix24) - XCTAssertEqual(radix24?.value, 123) - XCTAssertEqual(radix24?.base, 24) + #expect(radix24 != nil) + #expect(radix24?.value == 123) + #expect(radix24?.base == 24) let radix25 = Radix("4N", base: 25) - XCTAssertNotNil(radix25) - XCTAssertEqual(radix25?.value, 123) - XCTAssertEqual(radix25?.base, 25) + #expect(radix25 != nil) + #expect(radix25?.value == 123) + #expect(radix25?.base == 25) let radix26 = Radix("4J", base: 26) - XCTAssertNotNil(radix26) - XCTAssertEqual(radix26?.value, 123) - XCTAssertEqual(radix26?.base, 26) + #expect(radix26 != nil) + #expect(radix26?.value == 123) + #expect(radix26?.base == 26) let radix27 = Radix("4F", base: 27) - XCTAssertNotNil(radix27) - XCTAssertEqual(radix27?.value, 123) - XCTAssertEqual(radix27?.base, 27) + #expect(radix27 != nil) + #expect(radix27?.value == 123) + #expect(radix27?.base == 27) let radix28 = Radix("4B", base: 28) - XCTAssertNotNil(radix28) - XCTAssertEqual(radix28?.value, 123) - XCTAssertEqual(radix28?.base, 28) + #expect(radix28 != nil) + #expect(radix28?.value == 123) + #expect(radix28?.base == 28) let radix29 = Radix("47", base: 29) - XCTAssertNotNil(radix29) - XCTAssertEqual(radix29?.value, 123) - XCTAssertEqual(radix29?.base, 29) + #expect(radix29 != nil) + #expect(radix29?.value == 123) + #expect(radix29?.base == 29) let radix30 = Radix("43", base: 30) - XCTAssertNotNil(radix30) - XCTAssertEqual(radix30?.value, 123) - XCTAssertEqual(radix30?.base, 30) + #expect(radix30 != nil) + #expect(radix30?.value == 123) + #expect(radix30?.base == 30) let radix31 = Radix("3U", base: 31) - XCTAssertNotNil(radix31) - XCTAssertEqual(radix31?.value, 123) - XCTAssertEqual(radix31?.base, 31) + #expect(radix31 != nil) + #expect(radix31?.value == 123) + #expect(radix31?.base == 31) let radix32 = Radix("3R", base: 32) - XCTAssertNotNil(radix32) - XCTAssertEqual(radix32?.value, 123) - XCTAssertEqual(radix32?.base, 32) + #expect(radix32 != nil) + #expect(radix32?.value == 123) + #expect(radix32?.base == 32) let radix33 = Radix("3O", base: 33) - XCTAssertNotNil(radix33) - XCTAssertEqual(radix33?.value, 123) - XCTAssertEqual(radix33?.base, 33) + #expect(radix33 != nil) + #expect(radix33?.value == 123) + #expect(radix33?.base == 33) let radix34 = Radix("3L", base: 34) - XCTAssertNotNil(radix34) - XCTAssertEqual(radix34?.value, 123) - XCTAssertEqual(radix34?.base, 34) + #expect(radix34 != nil) + #expect(radix34?.value == 123) + #expect(radix34?.base == 34) let radix35 = Radix("3I", base: 35) - XCTAssertNotNil(radix35) - XCTAssertEqual(radix35?.value, 123) - XCTAssertEqual(radix35?.base, 35) + #expect(radix35 != nil) + #expect(radix35?.value == 123) + #expect(radix35?.base == 35) let radix36 = Radix("3F", base: 36) - XCTAssertNotNil(radix36) - XCTAssertEqual(radix36?.value, 123) - XCTAssertEqual(radix36?.base, 36) + #expect(radix36 != nil) + #expect(radix36?.value == 123) + #expect(radix36?.base == 36) } } diff --git a/Tests/SwiftRadixTests/Radix/Radix Type Extensions Tests.swift b/Tests/SwiftRadixTests/Radix/Radix Type Extensions Tests.swift index 1fa5b15..e34bfd7 100644 --- a/Tests/SwiftRadixTests/Radix/Radix Type Extensions Tests.swift +++ b/Tests/SwiftRadixTests/Radix/Radix Type Extensions Tests.swift @@ -4,84 +4,85 @@ // © 2020-2024 Steffan Andrews • Licensed under MIT License // +import Foundation import SwiftRadix -import XCTest +import Testing -final class RadixTypeExtensionsTests: XCTestCase { - func testRadix_TypeExtensions_BinaryInteger() { +@Suite struct RadixTypeExtensionsTests { + @Test func radix_TypeExtensions_BinaryInteger() { let validString = "1100" - XCTAssertEqual(0b1100.radix(base: 2)?.stringValue, validString) - XCTAssertEqual(UInt(0b1100).radix(base: 2)?.stringValue, validString) - XCTAssertEqual(Int8(0b1100).radix(base: 2)?.stringValue, validString) - XCTAssertEqual(UInt8(0b1100).radix(base: 2)?.stringValue, validString) - XCTAssertEqual(Int16(0b1100).radix(base: 2)?.stringValue, validString) - XCTAssertEqual(UInt16(0b1100).radix(base: 2)?.stringValue, validString) - XCTAssertEqual(Int32(0b1100).radix(base: 2)?.stringValue, validString) - XCTAssertEqual(UInt32(0b1100).radix(base: 2)?.stringValue, validString) - XCTAssertEqual(Int64(0b1100).radix(base: 2)?.stringValue, validString) - XCTAssertEqual(UInt64(0b1100).radix(base: 2)?.stringValue, validString) + #expect(0b1100.radix(base: 2)?.stringValue == validString) + #expect(UInt(0b1100).radix(base: 2)?.stringValue == validString) + #expect(Int8(0b1100).radix(base: 2)?.stringValue == validString) + #expect(UInt8(0b1100).radix(base: 2)?.stringValue == validString) + #expect(Int16(0b1100).radix(base: 2)?.stringValue == validString) + #expect(UInt16(0b1100).radix(base: 2)?.stringValue == validString) + #expect(Int32(0b1100).radix(base: 2)?.stringValue == validString) + #expect(UInt32(0b1100).radix(base: 2)?.stringValue == validString) + #expect(Int64(0b1100).radix(base: 2)?.stringValue == validString) + #expect(UInt64(0b1100).radix(base: 2)?.stringValue == validString) } - func testRadix_TypeExtensions_String() { + @Test func radix_TypeExtensions_String() { let validValue = 0b1100 let radix1 = "0b1100".radix(base: 2) // Int default - XCTAssertNotNil(radix1) + #expect(radix1 != nil) - XCTAssertEqual(radix1?.value, Int(validValue)) + #expect(radix1?.value == Int(validValue)) let radix2 = "1100".radix(base: 2) // Int default - XCTAssertNotNil(radix2) + #expect(radix2 != nil) - XCTAssertEqual(radix2?.value, Int(validValue)) + #expect(radix2?.value == Int(validValue)) let radix3 = "1100".radix(base: 2, as: Int32.self) - XCTAssertNotNil(radix3) + #expect(radix3 != nil) - XCTAssertEqual(radix3?.value, Int32(validValue)) + #expect(radix3?.value == Int32(validValue)) } - func testRadix_TypeExtensions_StringArray() { + @Test func radix_TypeExtensions_StringArray() { let source = ["0000", "0b1111"] let radixArray1 = source.radix(base: 2) // Int default - XCTAssertEqual(radixArray1.count, 2) + #expect(radixArray1.count == 2) - XCTAssertEqual(radixArray1[0]?.value, 0b0000) - XCTAssertEqual(radixArray1[1]?.value, 0b1111) + #expect(radixArray1[0]?.value == 0b0000) + #expect(radixArray1[1]?.value == 0b1111) let radixArray2 = source.radix(base: 2, as: Int32.self) - XCTAssertEqual(radixArray2.count, 2) + #expect(radixArray2.count == 2) - XCTAssertEqual(radixArray2[0]?.value, Int32(0b0000)) - XCTAssertEqual(radixArray2[1]?.value, Int32(0b1111)) + #expect(radixArray2[0]?.value == Int32(0b0000)) + #expect(radixArray2[1]?.value == Int32(0b1111)) } - func testRadix_TypeExtensions_BinIntCollection() { + @Test func radix_TypeExtensions_BinIntCollection() { let source = [0b0000, 0b1111] let radixArray = source.radix(base: 2) - XCTAssertEqual(radixArray?.count, 2) + #expect(radixArray?.count == 2) - XCTAssertEqual(radixArray?[0].value, 0b0000) - XCTAssertEqual(radixArray?[1].value, 0b1111) + #expect(radixArray?[0].value == 0b0000) + #expect(radixArray?[1].value == 0b1111) } - func testRadix_TypeExtensions_Data() { + @Test func radix_TypeExtensions_Data() { let source = Data([0b0000, 0b1111]) let radixArray = source.radix(base: 2) - XCTAssertEqual(radixArray?.count, 2) + #expect(radixArray?.count == 2) - XCTAssertEqual(radixArray?[0].value, 0b0000) - XCTAssertEqual(radixArray?[1].value, 0b1111) + #expect(radixArray?[0].value == 0b0000) + #expect(radixArray?[1].value == 0b1111) } }