Skip to content

Commit

Permalink
Some miscellaneous tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
oscbyspro committed Nov 2, 2023
1 parent a847269 commit 6b51245
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 33 deletions.
20 changes: 15 additions & 5 deletions Tests/NBKCoreKitTests/Private/NBKIntegerDescription+Encoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ final class NBKIntegerDescriptionTestsOnEncoding: XCTestCase {
//=------------------------------------------------------------------------=

func testEncodingEmptyCollectionsReturnsZero() {
let empty = [UInt]()
let words = [] as [UInt]
for radix in 2 ... 36 {
NBKAssertSignMagnitude(.plus, empty, radix, false, "0")
NBKAssertSignMagnitude(.plus, empty, radix, true, "0")
NBKAssertSignMagnitude(.minus, empty, radix, false, "0")
NBKAssertSignMagnitude(.minus, empty, radix, true, "0")
NBKAssertSignMagnitude(.plus, words, radix, false, "0")
NBKAssertSignMagnitude(.plus, words, radix, true, "0")
NBKAssertSignMagnitude(.minus, words, radix, false, "0")
NBKAssertSignMagnitude(.minus, words, radix, true, "0")
}
}

func testSignExtendingDoesNotChangeTheResult() {
let words = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0] as [UInt]
for radix in 2 ... 36 {
NBKAssertSignMagnitude(.plus, words, radix, false, "1")
NBKAssertSignMagnitude(.plus, words, radix, true, "1")
NBKAssertSignMagnitude(.minus, words, radix, false, "-1")
NBKAssertSignMagnitude(.minus, words, radix, true, "-1")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,57 @@ final class NBKProperBinaryIntegerTestsOnModularMultiplicativeInverse: XCTestCas
//=------------------------------------------------------------------------=
// MARK: Tests
//=------------------------------------------------------------------------=

func testSomeSmallPrimes() {
NBKAssertModularMultiplicativeInverse( 2 as Int, 31 as Int, 16 as Int) // primes: 1, 11
NBKAssertModularMultiplicativeInverse( 3 as Int, 79 as Int, 53 as Int) // primes: 2, 22
NBKAssertModularMultiplicativeInverse( 5 as Int, 137 as Int, 55 as Int) // primes: 3, 33
NBKAssertModularMultiplicativeInverse( 7 as Int, 193 as Int, 138 as Int) // primes: 4, 44
NBKAssertModularMultiplicativeInverse( 11 as Int, 257 as Int, 187 as Int) // primes: 5, 55
NBKAssertModularMultiplicativeInverse( 13 as Int, 317 as Int, 122 as Int) // primes: 6, 66
NBKAssertModularMultiplicativeInverse( 17 as Int, 389 as Int, 206 as Int) // primes: 7, 77
NBKAssertModularMultiplicativeInverse( 19 as Int, 457 as Int, 433 as Int) // primes: 8, 88
NBKAssertModularMultiplicativeInverse( 23 as Int, 523 as Int, 91 as Int) // primes: 9, 99
NBKAssertModularMultiplicativeInverse( 2 as Int, 31 as Int, 16 as Int?) // primes: 1, 11
NBKAssertModularMultiplicativeInverse( 3 as Int, 79 as Int, 53 as Int?) // primes: 2, 22
NBKAssertModularMultiplicativeInverse( 5 as Int, 137 as Int, 55 as Int?) // primes: 3, 33
NBKAssertModularMultiplicativeInverse( 7 as Int, 193 as Int, 138 as Int?) // primes: 4, 44
NBKAssertModularMultiplicativeInverse( 11 as Int, 257 as Int, 187 as Int?) // primes: 5, 55
NBKAssertModularMultiplicativeInverse( 13 as Int, 317 as Int, 122 as Int?) // primes: 6, 66
NBKAssertModularMultiplicativeInverse( 17 as Int, 389 as Int, 206 as Int?) // primes: 7, 77
NBKAssertModularMultiplicativeInverse( 19 as Int, 457 as Int, 433 as Int?) // primes: 8, 88
NBKAssertModularMultiplicativeInverse( 23 as Int, 523 as Int, 91 as Int?) // primes: 9, 99

NBKAssertModularMultiplicativeInverse( 2 as Int, 607 as Int, 304 as Int?) // primes: 1, 111
NBKAssertModularMultiplicativeInverse( 3 as Int, 1399 as Int, 933 as Int?) // primes: 2, 222
NBKAssertModularMultiplicativeInverse( 5 as Int, 2239 as Int, 448 as Int?) // primes: 3, 333
NBKAssertModularMultiplicativeInverse( 7 as Int, 3119 as Int, 2228 as Int?) // primes: 4, 444
NBKAssertModularMultiplicativeInverse( 11 as Int, 4019 as Int, 2923 as Int?) // primes: 5, 555
NBKAssertModularMultiplicativeInverse( 13 as Int, 4973 as Int, 4208 as Int?) // primes: 6, 666
NBKAssertModularMultiplicativeInverse( 17 as Int, 5903 as Int, 1389 as Int?) // primes: 7, 777
NBKAssertModularMultiplicativeInverse( 19 as Int, 6907 as Int, 6180 as Int?) // primes: 8, 888
NBKAssertModularMultiplicativeInverse( 23 as Int, 7907 as Int, 4813 as Int?) // primes: 9, 999

NBKAssertModularMultiplicativeInverse( 2 as Int, 607 as Int, 304 as Int) // primes: 1, 111
NBKAssertModularMultiplicativeInverse( 3 as Int, 1399 as Int, 933 as Int) // primes: 2, 222
NBKAssertModularMultiplicativeInverse( 5 as Int, 2239 as Int, 448 as Int) // primes: 3, 333
NBKAssertModularMultiplicativeInverse( 7 as Int, 3119 as Int, 2228 as Int) // primes: 4, 444
NBKAssertModularMultiplicativeInverse( 11 as Int, 4019 as Int, 2923 as Int) // primes: 5, 555
NBKAssertModularMultiplicativeInverse( 13 as Int, 4973 as Int, 4208 as Int) // primes: 6, 666
NBKAssertModularMultiplicativeInverse( 17 as Int, 5903 as Int, 1389 as Int) // primes: 7, 777
NBKAssertModularMultiplicativeInverse( 19 as Int, 6907 as Int, 6180 as Int) // primes: 8, 888
NBKAssertModularMultiplicativeInverse( 23 as Int, 7907 as Int, 4813 as Int) // primes: 9, 999
NBKAssertModularMultiplicativeInverse( 31 as Int, 607 as Int, 235 as Int?) // primes: 11, 111
NBKAssertModularMultiplicativeInverse( 79 as Int, 1399 as Int, 974 as Int?) // primes: 22, 222
NBKAssertModularMultiplicativeInverse(137 as Int, 2239 as Int, 1667 as Int?) // primes: 33, 333
NBKAssertModularMultiplicativeInverse(193 as Int, 3119 as Int, 905 as Int?) // primes: 44, 444
NBKAssertModularMultiplicativeInverse(257 as Int, 4019 as Int, 2377 as Int?) // primes: 55, 555
NBKAssertModularMultiplicativeInverse(317 as Int, 4973 as Int, 4722 as Int?) // primes: 66, 666
NBKAssertModularMultiplicativeInverse(389 as Int, 5903 as Int, 2170 as Int?) // primes: 77, 777
NBKAssertModularMultiplicativeInverse(457 as Int, 6907 as Int, 4383 as Int?) // primes: 88, 888
NBKAssertModularMultiplicativeInverse(523 as Int, 7907 as Int, 2933 as Int?) // primes: 99, 999
}

func testSomeSmallPowersOf2() {
NBKAssertModularMultiplicativeInverse( 0 as Int, 256 as Int, nil as Int?)
NBKAssertModularMultiplicativeInverse( 1 as Int, 256 as Int, 1 as Int?)
NBKAssertModularMultiplicativeInverse( 2 as Int, 256 as Int, nil as Int?)
NBKAssertModularMultiplicativeInverse( 3 as Int, 256 as Int, 171 as Int?)
NBKAssertModularMultiplicativeInverse( 4 as Int, 256 as Int, nil as Int?)
NBKAssertModularMultiplicativeInverse( 5 as Int, 256 as Int, 205 as Int?)
NBKAssertModularMultiplicativeInverse( 6 as Int, 256 as Int, nil as Int?)
NBKAssertModularMultiplicativeInverse( 7 as Int, 256 as Int, 183 as Int?)

NBKAssertModularMultiplicativeInverse( 31 as Int, 607 as Int, 235 as Int) // primes: 11, 111
NBKAssertModularMultiplicativeInverse( 79 as Int, 1399 as Int, 974 as Int) // primes: 22, 222
NBKAssertModularMultiplicativeInverse(137 as Int, 2239 as Int, 1667 as Int) // primes: 33, 333
NBKAssertModularMultiplicativeInverse(193 as Int, 3119 as Int, 905 as Int) // primes: 44, 444
NBKAssertModularMultiplicativeInverse(257 as Int, 4019 as Int, 2377 as Int) // primes: 55, 555
NBKAssertModularMultiplicativeInverse(317 as Int, 4973 as Int, 4722 as Int) // primes: 66, 666
NBKAssertModularMultiplicativeInverse(389 as Int, 5903 as Int, 2170 as Int) // primes: 77, 777
NBKAssertModularMultiplicativeInverse(457 as Int, 6907 as Int, 4383 as Int) // primes: 88, 888
NBKAssertModularMultiplicativeInverse(523 as Int, 7907 as Int, 2933 as Int) // primes: 99, 999
NBKAssertModularMultiplicativeInverse( 0 as Int, 4096 as Int, nil as Int?)
NBKAssertModularMultiplicativeInverse( 1 as Int, 4096 as Int, 1 as Int?)
NBKAssertModularMultiplicativeInverse( 2 as Int, 4096 as Int, nil as Int?)
NBKAssertModularMultiplicativeInverse( 3 as Int, 4096 as Int, 2731 as Int?)
NBKAssertModularMultiplicativeInverse( 4 as Int, 4096 as Int, nil as Int?)
NBKAssertModularMultiplicativeInverse( 5 as Int, 4096 as Int, 3277 as Int?)
NBKAssertModularMultiplicativeInverse( 6 as Int, 4096 as Int, nil as Int?)
NBKAssertModularMultiplicativeInverse( 7 as Int, 4096 as Int, 3511 as Int?)
}

//=------------------------------------------------------------------------=
Expand Down

0 comments on commit 6b51245

Please sign in to comment.