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_multiply(): void {
17    assert new BigInt(10).operatorMultiply(new BigInt(10)) == 100n;
18    assert new BigInt(0).operatorMultiply(new BigInt(50)) == 0n;
19    assert new BigInt(1).operatorMultiply(new BigInt(50)) == 50n;
20    assert new BigInt(50).operatorMultiply(new BigInt(5)) == 250n;
21    assert new BigInt(50).operatorMultiply(new BigInt(-5)) == -250n;
22    assert new BigInt(-1).operatorMultiply(new BigInt(-5)) == 5n;
23    assert new BigInt(0).operatorMultiply(new BigInt(0)) == 0n;
24    assert new BigInt(123).operatorMultiply(new BigInt(1)) == 123n;
25    assert new BigInt(1234).operatorMultiply(new BigInt(987)) == 1217958n;
26    assert new BigInt(3241847031247230147213740214703214721047312n).operatorMultiply(new BigInt(412343124123421347812304712431421204731024n)) == 1336753332794721625246945391107220242430725631478413717131017736872102322242538207488n;
27    assert new BigInt(-3241847031247230147213740214703214721047312n).operatorMultiply(new BigInt(-412343124123421347812304712431421204731024n)) == 1336753332794721625246945391107220242430725631478413717131017736872102322242538207488n;
28    assert new BigInt(-3241847031247230147213740214703214721047312n).operatorMultiply(new BigInt(412343124123421347812304712431421204731024n)) == -1336753332794721625246945391107220242430725631478413717131017736872102322242538207488n;
29    assert new BigInt(3241847031247230147213740214703214721047312n).operatorMultiply(new BigInt(-412343124123421347812304712431421204731024n)) == -1336753332794721625246945391107220242430725631478413717131017736872102322242538207488n;
30    assert new BigInt(256).operatorMultiply(new BigInt(256)) == 65536n;
31}
32
33function test_multiplication(): void {
34    const a = 23443495146314363289895841n
35    const b = 245000234343499329134n
36    const c = -245000234343499329134n
37
38    /* Multiplication testing (*) */
39    assert 978667632325344545n * 4534000101n == 4437279143808543031889799045n
40    assert a * b == 5743661804677708098900659843374372544236731694n
41    assert a * c == -5743661804677708098900659843374372544236731694n
42    assert a * 0n == 0n
43    assert c * 0n == 0n
44
45    /* Division testing (/) */
46    assert 39735235034886462n / 89221422n == 445355321n
47    assert a / b == 95687n
48    assert a / c == -95687n
49    assert 0n / a == 0n
50
51    let err = false;
52    try {
53        a / 0n
54    } catch (e) {
55        if (e instanceof Error) {
56            err = true
57        }
58    }
59    assert err
60
61    /* Remainder of the division (%) */
62    assert 493433405047004109n % 111114444n == 18100749n
63    assert a % b == a % c
64    assert 0n % a == 0n
65
66    err = false;
67    try {
68        a % 0n
69    } catch (e) {
70        if (e instanceof Error) {
71            err = true
72        }
73    }
74    assert err
75}
76
77function main() {
78    test_multiply()
79    test_multiplication()
80}
81
82