Skip to content

Commit

Permalink
tests n' cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
oscbyspro committed Mar 11, 2023
1 parent 34c29d1 commit e6d240b
Show file tree
Hide file tree
Showing 8 changed files with 421 additions and 259 deletions.
30 changes: 15 additions & 15 deletions Tests/ANKFullWidthKitTests/192+Addition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ final class Int192TestsOnAddition: XCTestCase {
}

func testAddingReportingOverflow() {
XCTAssert(T.min.addingReportingOverflow(T( 1)) == (T.min + 1, false) as (T, Bool))
XCTAssert(T.max.addingReportingOverflow(T( 1)) == (T.min, true ) as (T, Bool))
XCTAssert(T.min.addingReportingOverflow(T( 1)) == (T.min + T(1), false) as (T, Bool))
XCTAssert(T.max.addingReportingOverflow(T( 1)) == (T.min, true ) as (T, Bool))

XCTAssert(T.min.addingReportingOverflow(T(-1)) == (T.max, true ) as (T, Bool))
XCTAssert(T.max.addingReportingOverflow(T(-1)) == (T.max - 1, false) as (T, Bool))
XCTAssert(T.min.addingReportingOverflow(T(-1)) == (T.max, true ) as (T, Bool))
XCTAssert(T.max.addingReportingOverflow(T(-1)) == (T.max - T(1), false) as (T, Bool))
}

//=------------------------------------------------------------------------=
Expand Down Expand Up @@ -109,19 +109,19 @@ final class Int192TestsOnAddition: XCTestCase {
}

func testAddingDigitWrappingAround() {
XCTAssertEqual(T.min &+ Int( 1), T.min + T(1))
XCTAssertEqual(T.min &+ Int( 1), T.min + Int(1))
XCTAssertEqual(T.max &+ Int( 1), T.min)

XCTAssertEqual(T.min &+ Int(-1), T.max)
XCTAssertEqual(T.max &+ Int(-1), T.max - T(1))
XCTAssertEqual(T.max &+ Int(-1), T.max - Int(1))
}

func testAddingDigitReportingOverflow() {
XCTAssert(T.min.addingReportingOverflow(Int( 1)) == (T.min + 1, false) as (T, Bool))
XCTAssert(T.max.addingReportingOverflow(Int( 1)) == (T.min, true ) as (T, Bool))
XCTAssert(T.min.addingReportingOverflow(Int( 1)) == (T.min + Int(1), false) as (T, Bool))
XCTAssert(T.max.addingReportingOverflow(Int( 1)) == (T.min, true ) as (T, Bool))

XCTAssert(T.min.addingReportingOverflow(Int(-1)) == (T.max, true ) as (T, Bool))
XCTAssert(T.max.addingReportingOverflow(Int(-1)) == (T.max - 1, false) as (T, Bool))
XCTAssert(T.min.addingReportingOverflow(Int(-1)) == (T.max, true ) as (T, Bool))
XCTAssert(T.max.addingReportingOverflow(Int(-1)) == (T.max - Int(1), false) as (T, Bool))
}

//=------------------------------------------------------------------------=
Expand Down Expand Up @@ -173,8 +173,8 @@ final class UInt192TestsOnAddition: XCTestCase {
}

func testAddingReportingOverflow() {
XCTAssert(T.min.addingReportingOverflow(T(1)) == (T.min + (1 as UInt), false) as (T, Bool))
XCTAssert(T.max.addingReportingOverflow(T(1)) == (T.min, true ) as (T, Bool))
XCTAssert(T.min.addingReportingOverflow(T(1)) == (T.min + T(1), false) as (T, Bool))
XCTAssert(T.max.addingReportingOverflow(T(1)) == (T.min, true ) as (T, Bool))
}

//=------------------------------------------------------------------------=
Expand All @@ -196,13 +196,13 @@ final class UInt192TestsOnAddition: XCTestCase {
}

func testAddingDigitWrappingAround() {
XCTAssertEqual(T.min &+ UInt(1), T.min + T(1))
XCTAssertEqual(T.min &+ UInt(1), T.min + UInt(1))
XCTAssertEqual(T.max &+ UInt(1), T.min)
}

func testAddingDigitReportingOverflow() {
XCTAssert(T.min.addingReportingOverflow(UInt(1)) == (T.min + (1 as UInt), false) as (T, Bool))
XCTAssert(T.max.addingReportingOverflow(UInt(1)) == (T.min, true ) as (T, Bool))
XCTAssert(T.min.addingReportingOverflow(UInt(1)) == (T.min + UInt(1), false) as (T, Bool))
XCTAssert(T.max.addingReportingOverflow(UInt(1)) == (T.min, true ) as (T, Bool))
}

//=------------------------------------------------------------------------=
Expand Down
36 changes: 20 additions & 16 deletions Tests/ANKFullWidthKitTests/192+Endianness.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ final class Int192TestsOnEndianness: XCTestCase {
//=------------------------------------------------------------------------=

func testBigEndian() {
let base = T(x64: X(1, 2, 3))
let baseBigEndian = T(x64: X(b3, b2, b1))
XCTAssertEqual(base.bigEndian, baseBigEndian)
XCTAssertEqual(T(bigEndian: baseBigEndian), base)
XCTAssertEqual(T(x64: X(01 ,02, 03)).bigEndian, T(x64: X(b3, b2, b1)))
XCTAssertEqual(T(x64: X(b3, b2, b1)).bigEndian, T(x64: X(01, 02, 03)))

XCTAssertEqual(T(bigEndian: T(x64: X(01, 02, 03))), T(x64: X(b3, b2, b1)))
XCTAssertEqual(T(bigEndian: T(x64: X(b3, b2, b1))), T(x64: X(01, 02, 03)))
}

func testLittleEndian() {
let base = T(x64: X(1, 2, 3))
let baseLittleEndian = T(x64: X(l1, l2, l3))
XCTAssertEqual(base.littleEndian, baseLittleEndian)
XCTAssertEqual(T(littleEndian: baseLittleEndian), base)
XCTAssertEqual(T(x64: X(01, 02, 03)).littleEndian, T(x64: X(l1, l2, l3)))
XCTAssertEqual(T(x64: X(l1, l2, l3)).littleEndian, T(x64: X(01, 02, 03)))

XCTAssertEqual(T(littleEndian: T(x64: X(01, 02, 03))), T(x64: X(l1, l2, l3)))
XCTAssertEqual(T(littleEndian: T(x64: X(l1, l2, l3))), T(x64: X(01, 02, 03)))
}
}

Expand Down Expand Up @@ -79,17 +81,19 @@ final class UInt192TestsOnEndianness: XCTestCase {
//=------------------------------------------------------------------------=

func testBigEndian() {
let base = T(x64: X(1, 2, 3))
let baseBigEndian = T(x64: X(b3, b2, b1))
XCTAssertEqual(base.bigEndian, baseBigEndian)
XCTAssertEqual(T(bigEndian: baseBigEndian), base)
XCTAssertEqual(T(x64: X(01 ,02, 03)).bigEndian, T(x64: X(b3, b2, b1)))
XCTAssertEqual(T(x64: X(b3, b2, b1)).bigEndian, T(x64: X(01, 02, 03)))

XCTAssertEqual(T(bigEndian: T(x64: X(01, 02, 03))), T(x64: X(b3, b2, b1)))
XCTAssertEqual(T(bigEndian: T(x64: X(b3, b2, b1))), T(x64: X(01, 02, 03)))
}

func testLittleEndian() {
let base = T(x64: X(1, 2, 3))
let baseLittleEndian = T(x64: X(l1, l2, l3))
XCTAssertEqual(base.littleEndian, baseLittleEndian)
XCTAssertEqual(T(littleEndian: baseLittleEndian), base)
XCTAssertEqual(T(x64: X(01, 02, 03)).littleEndian, T(x64: X(l1, l2, l3)))
XCTAssertEqual(T(x64: X(l1, l2, l3)).littleEndian, T(x64: X(01, 02, 03)))

XCTAssertEqual(T(littleEndian: T(x64: X(01, 02, 03))), T(x64: X(l1, l2, l3)))
XCTAssertEqual(T(littleEndian: T(x64: X(l1, l2, l3))), T(x64: X(01, 02, 03)))
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/ANKFullWidthKitTests/192+Negation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ final class Int192TestsOnNegation: XCTestCase {
}

func testNegatedReportingOverflow() {
XCTAssert(T.min.negatedReportingOverflow() == (T(x64: X(0, 0, ~0 << 63)), true ) as (T, Bool))
XCTAssert(T.max.negatedReportingOverflow() == (T(x64: X(1, 0, ~0 << 63)), false) as (T, Bool))
XCTAssert(T.min.negatedReportingOverflow() == (T.min, true ) as (T, Bool))
XCTAssert(T.max.negatedReportingOverflow() == (T.min + T(1), false) as (T, Bool))
}
}

Expand Down
Loading

0 comments on commit e6d240b

Please sign in to comment.