/* * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function test_unary_minus(): void { assert new BigInt(10).negate() == (-10n); assert new BigInt(1000).negate() == (-1000n); assert new BigInt(-1).negate() == (1n); assert new BigInt(-10).negate() == (10n); assert new BigInt(-100).negate() == (100n); assert new BigInt(0).negate() == (0n); } function test_unary(): void { let n = -128n assert (n == -128n) let a = 123n; assert(a == 123n); assert(a.toString() == "123"); a = -123n; assert(a == -123n); assert(a.toString() == "-123"); a = 123n assert(a == 123n); assert(a.toString() == "123"); a = -a; assert(a == -123n); assert(a.toString() == "-123"); a = -a; assert(a == 123n); assert(a.toString() == "123"); let e: bigint; assert(a == 123n); assert(a.toString() == "123"); e = -a; // Check that original value does not change assert(a == 123n); assert(a.toString() == "123"); assert(e == -123n); assert(e.toString() == "-123"); e = a; assert(e == 123n); assert(e.toString() == "123"); let b = -123n; assert(b == -123n) assert(b.toString() == "-123"); let c = -(123n); assert(c == -123n) assert(c.toString() == "-123"); // Double unary minus let d = -(-123n); assert(d == 123n); assert(d.toString() == "123"); // Triple unary minux let f = -(-(-123n)); assert(f == -123n); assert(f.toString() == "-123"); a = new BigInt(321); assert(a.toString() == "321") assert(a == 321n) b = -a; assert(a.toString() == "321") assert(a == 321n) assert(b == -321n); assert(b.toString() == "-321"); } function main() : void { test_unary() test_unary_minus() }