1/* 2 * Copyright (c) 2023-2024 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 assert new BigInt(10).operatorAdd(new BigInt(20)) == 30n; 18 assert new BigInt(1000).operatorAdd(new BigInt(10)) == 1010n; 19 assert new BigInt(-10).operatorAdd(new BigInt(9)) == -1n; 20 assert new BigInt(-10).operatorAdd(new BigInt(10)) == 0n; 21 assert new BigInt(-100).operatorAdd(new BigInt(10)) == -90n; 22 assert new BigInt(100).operatorAdd(new BigInt(10)) == 110n; 23 assert new BigInt(65535).operatorAdd(new BigInt(65535)) == 131070n; 24 assert new BigInt(65500).operatorAdd(new BigInt(1)) == (65501n); 25 assert new BigInt(65500).operatorAdd(new BigInt(-1)) == (65499n); 26 assert new BigInt(-65500).operatorAdd(new BigInt(-1)) == (-65501n); 27 assert new BigInt(-65500).operatorAdd(new BigInt(1)) == (-65499n); 28 assert new BigInt(-65500).operatorAdd(new BigInt(100000)) == (34500n); 29 assert new BigInt(100).operatorAdd(new BigInt(0)) == (100n); 30 assert new BigInt(-100).operatorAdd(new BigInt(0)) == (-100n); 31 assert 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 assert (-a == -97567789101304567800013210071n) 41 assert (-b == 533923234343411557221n) 42 assert (-c == -0n) 43 assert (-(-a) == a) 44 assert (-(-b) == b) 45 assert (-(-c) == c) 46 47 /* Plus testing (+) */ 48 assert +a == a 49 assert +b == b 50 assert +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 assert 999999999999999n + 1n == 1000000000000000n 59 assert a + b == 55340232221128654848n 60 assert a + a == b 61 assert a + c == 8446744073709551616n 62 assert a + b + b == 92233720368547758080n 63} 64 65function main() { 66 test_plus() 67 test_addition_1() 68 test_addition_2() 69} 70