13af6ab5fSopenharmony_ci/*
23af6ab5fSopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License.
53af6ab5fSopenharmony_ci * You may obtain a copy of the License at
63af6ab5fSopenharmony_ci *
73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
83af6ab5fSopenharmony_ci *
93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and
133af6ab5fSopenharmony_ci * limitations under the License.
143af6ab5fSopenharmony_ci */
153af6ab5fSopenharmony_ci
163af6ab5fSopenharmony_cifunction test_left_shift(): void {
173af6ab5fSopenharmony_ci    assert new BigInt(0).operatorLeftShift(new BigInt(0)) == (0n);
183af6ab5fSopenharmony_ci    assert new BigInt(0).operatorLeftShift(new BigInt(1)) == (0n);
193af6ab5fSopenharmony_ci    assert new BigInt(1).operatorLeftShift(new BigInt(0)) == (1n);
203af6ab5fSopenharmony_ci    assert new BigInt(10).operatorLeftShift(new BigInt(2)) == (40n);
213af6ab5fSopenharmony_ci    assert new BigInt(255).operatorLeftShift(new BigInt(41)) == (560750930165760n);
223af6ab5fSopenharmony_ci    assert new BigInt(65535).operatorLeftShift(new BigInt(60)) == (75556710804409716572160n);
233af6ab5fSopenharmony_ci    assert new BigInt(4294967295).operatorLeftShift(new BigInt(5)) == (137438953440n);
243af6ab5fSopenharmony_ci    assert new BigInt(18446744073709551615n).operatorLeftShift(new BigInt(6)) == (1180591620717411303360n);
253af6ab5fSopenharmony_ci    assert new BigInt(1275418875248948586535904902545412130n).operatorLeftShift(new BigInt(123)) == (13562579802667292602585801202159372574330573695725523059072421474640855040n);
263af6ab5fSopenharmony_ci    assert new BigInt(2).operatorLeftShift(new BigInt(218)) == (842498333348457493583344221469363458551160763204392890034487820288n);
273af6ab5fSopenharmony_ci    assert new BigInt(-1).operatorLeftShift(new BigInt(0)) == (-1n);
283af6ab5fSopenharmony_ci    assert new BigInt(-12).operatorLeftShift(new BigInt(4)) == (-192n);
293af6ab5fSopenharmony_ci    assert new BigInt(-255).operatorLeftShift(new BigInt(19)) == (-133693440n);
303af6ab5fSopenharmony_ci    assert new BigInt(-65535).operatorLeftShift(new BigInt(73)) == (-618960574909724398159134720n);
313af6ab5fSopenharmony_ci    assert new BigInt(-4294967295).operatorLeftShift(new BigInt(24)) == (-72057594021150720n);
323af6ab5fSopenharmony_ci    assert new BigInt(-18446744073709551615n).operatorLeftShift(new BigInt(31)) == (-39614081257132168794624491520n);
333af6ab5fSopenharmony_ci    assert new BigInt(-4095059032950818422890113130149234924134n).operatorLeftShift(new BigInt(103)) == (-41528832328721100931613913139905162112381494314462183326283215847555072n);
343af6ab5fSopenharmony_ci}
353af6ab5fSopenharmony_ci
363af6ab5fSopenharmony_cifunction test_right_shift(): void {
373af6ab5fSopenharmony_ci    assert new BigInt(-200).operatorRightShift(new BigInt(2)) == (-50n);
383af6ab5fSopenharmony_ci    assert new BigInt(-12).operatorRightShift(new BigInt(2)) == (-3n);
393af6ab5fSopenharmony_ci    assert new BigInt(-1).operatorRightShift(new BigInt(0)) == (-1n);
403af6ab5fSopenharmony_ci    assert new BigInt(0).operatorRightShift(new BigInt(0)) == (0n);
413af6ab5fSopenharmony_ci    assert new BigInt(0).operatorRightShift(new BigInt(1)) == (0n);
423af6ab5fSopenharmony_ci    assert new BigInt(1).operatorRightShift(new BigInt(0)) == (1n);
433af6ab5fSopenharmony_ci    assert new BigInt(55).operatorRightShift(new BigInt(2)) == (13n);
443af6ab5fSopenharmony_ci    assert new BigInt(-50).operatorRightShift(new BigInt(2)) == (-13n);
453af6ab5fSopenharmony_ci    assert new BigInt(255).operatorRightShift(new BigInt(4)) == (15n);
463af6ab5fSopenharmony_ci    assert new BigInt(255).operatorRightShift(new BigInt(8)) == (0n);
473af6ab5fSopenharmony_ci    assert new BigInt(65535).operatorRightShift(new BigInt(10)) == (63n);
483af6ab5fSopenharmony_ci    assert new BigInt(4294967295).operatorRightShift(new BigInt(17)) == (32767n);
493af6ab5fSopenharmony_ci    assert new BigInt(4294967295).operatorRightShift(new BigInt(48)) == (0n);
503af6ab5fSopenharmony_ci    assert new BigInt(18446744073709551615n).operatorRightShift(new BigInt(55)) == (511n);
513af6ab5fSopenharmony_ci    assert new BigInt(4930493049034092989191918392837727383823827n).operatorRightShift(new BigInt(129)) == (7244n);
523af6ab5fSopenharmony_ci    assert new BigInt(34930693049034092980065918370009389341341932481328231493102392100010239n).operatorRightShift(new BigInt(41)) == (15884640128676479880626138024130973163365493965706369405371n);
533af6ab5fSopenharmony_ci    assert new BigInt(34095405903900293499034024029409200000000000000000000094049304394284993939382949384984981018480144184891848991934893429489324901148449849382222222222222888384932890000103010381803018300103180381030084545225875678328499213403403984398439489384984287113383827387373382328328194394892948392222219791749717949183748237n).operatorRightShift(new BigInt(511)) == (5085903091997271218878067997324523590835536101241386224503069830700984460490307918626942225457432781938207872710051592009243523341752202627425621983245162030428n);
543af6ab5fSopenharmony_ci    assert new BigInt(-255).operatorRightShift(new BigInt(2)) == (-64n);
553af6ab5fSopenharmony_ci    assert new BigInt(-65535).operatorRightShift(new BigInt(12)) == (-16n);
563af6ab5fSopenharmony_ci    assert new BigInt(-4294967295).operatorRightShift(new BigInt(18)) == (-16384n);
573af6ab5fSopenharmony_ci    assert new BigInt(-18446744073709551615n).operatorRightShift(new BigInt(38)) == (-67108864n);
583af6ab5fSopenharmony_ci    assert new BigInt(-4095059032950818422890113130149234924134n).operatorRightShift(new BigInt(99)) == (-6460863952n);
593af6ab5fSopenharmony_ci    assert new BigInt(-3294302940940294094923040592059302590950294502940294029029409029429042942049028100104029439420990952n).operatorRightShift(new BigInt(100)) == (-2598746800062401791237527125433630339355687972972274247737341685088307n);
603af6ab5fSopenharmony_ci}
613af6ab5fSopenharmony_ci
623af6ab5fSopenharmony_cifunction main() : void {
633af6ab5fSopenharmony_ci    test_left_shift()
643af6ab5fSopenharmony_ci    test_right_shift()
653af6ab5fSopenharmony_ci}
663af6ab5fSopenharmony_ci
67