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_bitwise_and(): void {
17    assert new BigInt(10).operatorBitwiseAnd(new BigInt(2)) == (2n);
18    assert new BigInt(256).operatorBitwiseAnd(new BigInt(1)) == (0n);
19    assert new BigInt(3124378143267041203423n).operatorBitwiseAnd(new BigInt(43621978)) == (41948250n);
20    assert new BigInt(256).operatorBitwiseAnd(new BigInt(256)) == (256n);
21    assert new BigInt(12345678).operatorBitwiseAnd(new BigInt(1234)) == (66n);
22}
23
24function test_bitwise_or(): void {
25    assert new BigInt(10).operatorBitwiseOr(new BigInt(2)) == (10n);
26    assert new BigInt(256).operatorBitwiseOr(new BigInt(1)) == (257n);
27    assert new BigInt(256).operatorBitwiseOr(new BigInt(256)) == (256n);
28    assert new BigInt(3124378143267041203423n).operatorBitwiseOr(new BigInt(43621978)) == (3124378143267042877151n);
29    assert new BigInt(12345678).operatorBitwiseOr(new BigInt(1234)) == (12346846n);
30}
31
32function test_bitwise_xor(): void {
33    assert new BigInt(10).operatorBitwiseXor(new BigInt(2)) == (8n);
34    assert new BigInt(256).operatorBitwiseXor(new BigInt(1)) == (257n);
35    assert new BigInt(256).operatorBitwiseXor(new BigInt(256)) == (0n);
36    assert new BigInt(3124378143267041203423n).operatorBitwiseXor(new BigInt(43621978)) == (3124378143267000928901n);
37    assert new BigInt(12345678).operatorBitwiseXor(new BigInt(1234)) == (12346780n);
38}
39
40function test_bitwise(): void {
41    const a = 123456789123456789123456789123456789123456789123456789n
42    let b = 123456790n
43    const zero = 0n
44
45    assert ~zero == -1n
46    assert ~a == -123456789123456789123456789123456789123456789123456790n
47}
48
49function main(): void {
50    test_bitwise_and()
51    test_bitwise_or()
52    test_bitwise_xor()
53    test_bitwise()
54}
55