1/* 2 * Copyright (c) 2023-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16function test_plus(): void { 17 assertEQ(new BigInt(10).operatorAdd(new BigInt(20)), 30n) 18 assertEQ(new BigInt(1000).operatorAdd(new BigInt(10)), 1010n) 19 assertEQ(new BigInt(-10).operatorAdd(new BigInt(9)), -1n) 20 assertEQ(new BigInt(-10).operatorAdd(new BigInt(10)), 0n) 21 assertEQ(new BigInt(-100).operatorAdd(new BigInt(10)), -90n) 22 assertEQ(new BigInt(100).operatorAdd(new BigInt(10)), 110n) 23 assertEQ(new BigInt(65535).operatorAdd(new BigInt(65535)) , 131070n) 24 assertEQ(new BigInt(65500).operatorAdd(new BigInt(1)), (65501n)) 25 assertEQ(new BigInt(65500).operatorAdd(new BigInt(-1)), (65499n)) 26 assertEQ(new BigInt(-65500).operatorAdd(new BigInt(-1)), (-65501n)) 27 assertEQ(new BigInt(-65500).operatorAdd(new BigInt(1)), (-65499n)) 28 assertEQ(new BigInt(-65500).operatorAdd(new BigInt(100000)), (34500n)) 29 assertEQ(new BigInt(100).operatorAdd(new BigInt(0)), (100n)) 30 assertEQ(new BigInt(-100).operatorAdd(new BigInt(0)), (-100n)) 31 assertEQ(new BigInt(-10).operatorAdd(new BigInt(-10)), (-20n)) 32} 33 34function test_addition_1(): void { 35 const a = 97567789101304567800013210071n 36 const b = -533923234343411557221n 37 const c = 0n; 38 39 /* Minus testing (-) */ 40 assertEQ(-a, -97567789101304567800013210071n) 41 assertEQ(-b, 533923234343411557221n) 42 assertEQ(-c, -0n) 43 assertEQ(-(-a), a) 44 assertEQ(-(-b), b) 45 assertEQ(-(-c), c) 46 47 /* Plus testing (+) */ 48 assertEQ(+a, a) 49 assertEQ(+b, b) 50 assertEQ(+c, 0n) 51} 52 53function test_addition_2(): void { 54 const a = 18446744073709551616n; 55 const b = 36893488147419103232n; 56 const c = -10000000000000000000n; 57 /* Addition testing (+) */ 58 assertEQ(999999999999999n + 1n, 1000000000000000n) 59 assertEQ(a + b, 55340232221128654848n) 60 assertEQ(a + a, b) 61 assertEQ(a + c, 8446744073709551616n) 62 assertEQ(a + b + b, 92233720368547758080n) 63} 64 65function main() { 66 test_plus() 67 test_addition_1() 68 test_addition_2() 69} 70