-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathJavaScriptBigIntSupportTests.swift
50 lines (43 loc) · 1.69 KB
/
JavaScriptBigIntSupportTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import JavaScriptBigIntSupport
import JavaScriptKit
import XCTest
class JavaScriptBigIntSupportTests: XCTestCase {
func testBigIntSupport() {
// Test signed values
func testSignedValue(_ value: Int64, file: StaticString = #filePath, line: UInt = #line) {
let bigInt = JSBigInt(value)
XCTAssertEqual(bigInt.description, value.description, file: file, line: line)
let bigInt2 = JSBigInt(_slowBridge: value)
XCTAssertEqual(bigInt2.description, value.description, file: file, line: line)
}
// Test unsigned values
func testUnsignedValue(_ value: UInt64, file: StaticString = #filePath, line: UInt = #line) {
let bigInt = JSBigInt(unsigned: value)
XCTAssertEqual(bigInt.description, value.description, file: file, line: line)
let bigInt2 = JSBigInt(_slowBridge: value)
XCTAssertEqual(bigInt2.description, value.description, file: file, line: line)
}
// Test specific signed values
testSignedValue(0)
testSignedValue(1 << 62)
testSignedValue(-2305)
// Test random signed values
for _ in 0..<100 {
testSignedValue(.random(in: .min ... .max))
}
// Test edge signed values
testSignedValue(.min)
testSignedValue(.max)
// Test specific unsigned values
testUnsignedValue(0)
testUnsignedValue(1 << 62)
testUnsignedValue(1 << 63)
testUnsignedValue(.min)
testUnsignedValue(.max)
testUnsignedValue(~0)
// Test random unsigned values
for _ in 0..<100 {
testUnsignedValue(.random(in: .min ... .max))
}
}
}