提交 6015131d 编写于 作者: H hu0475

完成commonlibrary子系统ArrayList,LightWeightSet,Set模块的跨平台测试套

Signed-off-by: Nhu0475 <huyanqiang5@huawei.com>
上级 9d32e4cb
......@@ -16,6 +16,11 @@ group("crossplatform") {
testonly = true
if (is_standard_system) {
deps = [
"commonlibraryArrayListetstest:ActsCrossPlatformArrayListTest",
"commonlibraryLightWeightMapetstest:ActsCrossplatformLightWeightMapTest",
"commonlibraryLightWeightSetetstest:ActsCrossPlatformLightWeightSetTest",
"commonlibraryLinkedListetstest:ActsCrossplatformLinkedListTest",
"commonlibraryListetstest:ActsCrossPlatformList2Test",
"commonlibraryTreeMapetstest:ActsCrossplatformTreeMapTest",
"commonlibraryWorkeretstest:ActsCrossplatformWorkerTest",
"commonlibrarybufferetstest:ActsCrossplatformBufferTest",
......@@ -24,15 +29,13 @@ group("crossplatform") {
"commonlibraryhashmapetstest:ActsCrossplatformHashMapTest",
"commonlibraryhashsetetstest:ActsCrossplatformHashSetTest",
"commonlibraryplainarrayetstest:ActsCrossplatformPlainArrayTest",
"commonlibraryprocessetstest:ActsCrossplatformProcessTest",
"commonlibraryqueueetstest:ActsCrossplatformCommonlibraryQueueTest",
"commonlibrarystacketstest:ActsCrossplatformCommonlibraryStackTest",
"commonlibrarytaskpooletstest:ActsCrossplatformCommonlibraryTaskpoolTest",
"commonlibrarytreesetetstest:ActsCrossplatformTreeSetTest",
"commonlibraryurietstest:ActsCrossplatformUriTest",
"commonlibraryurletstest:ActsCrossplatformUrlTest",
"commonlibraryutiletstest:ActsCrossplatformLightWeightMapTest",
"commonlibraryutiletstest:ActsCrossplatformLinkedListTest",
"commonlibraryutiletstest:ActsCrossplatformProcessTest",
"commonlibraryutiletstest:ActsCrossplatformUtilTest",
]
}
......
{
"app": {
"bundleName": "ohos.acts.commonlibrary.crossplatform.ArrayList.normal",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 10,
"targetAPIVersion": 10,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
}
# Copyright (C) 2023 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.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsCrossPlatformArrayListTest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
# hap_name: HAP的名字,可选,默认为目标名
hap_name = "ActsCrossPlatformArrayListTest"
subsystem_name = "commonlibrary"
part_name = "ets_utils"
}
ohos_app_scope("windowStage_app_profile") {
# app_profile: HAP的AppScope中的app.json,只在Stage模型下使用
app_profile = "AppScope/app.json"
# sources: 资源文件路径
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
# source_dir: js或ets代码路径,兼容FA模型的单ability配置到ability目录
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
# sources: 资源文件路径
sources = [ "src/main/resources" ]
# deps: 当前目标的依赖
deps = [ ":windowStage_app_profile" ]
# hap_profile: HAP的config.json,Stage模型对应module.json
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "60000",
"shell-timeout": "60000",
"bundle-name": "ohos.acts.commonlibrary.crossplatform.ArrayList.normal",
"module-name": "entry_test"
},
"kits": [
{
"test-file-name": [
"ActsDemoStageTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
/**
* Copyright (c) 2023 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.
*/
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import hilog from '@ohos.hilog';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import window from '@ohos.window';
export default class TestAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? '');
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
windowStage.loadContent('TestAbility/pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
}
onForeground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
}
onBackground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
}
}
\ No newline at end of file
/**
* Copyright (c) 2023 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.
*/
import hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
aboutToAppear() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear');
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ No newline at end of file
/*
* Copyright (C) 2023 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.
*/
import ArrayList from "@ohos.util.ArrayList";
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
export default function ArraylistTest() {
describe("ArraylistTest", function () {
/**
* @tc.number: TEST_CONSTRUCTOR_001
* @tc.name : testConstructor001
* @tc.desc : Create an ArrayList instance. For example: let arrayList = new ArrayList().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testConstructor001", 0, function () {
try {
let arrayList = new ArrayList();
expect(arrayList != undefined).assertEqual(true);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The ArrayList's constructor cannot be directly invoked");
}
});
/**
* @tc.number: TEST_LENGTH_001
* @tc.name : testLength001
* @tc.desc : Get the number of elements contained in the ArrayList instance. For example: arrayList.length.
* @tc.size : MediumTest
* @tc.type : Field
* @tc.level : Level 0
* */
it("testLength001", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
arrayList.insert(8, 2);
let res = arrayList.length;
expect(res).assertEqual(5);
});
/**
* @tc.number: TEST_ADD_001
* @tc.name : testAdd001
* @tc.desc : Add a string type element to the end of the ArrayList instance. For example: arrayList.add("四").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd001", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
let res = arrayList.has("四");
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_002
* @tc.name : testAdd002
* @tc.desc : Add a number type element to the end of the ArrayList instance. For example: arrayList.add(8).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd002", 0, function () {
let arrayList = new ArrayList();
arrayList.add(8);
let res = arrayList.has(8);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_003
* @tc.name : testAdd003
* @tc.desc : Add a object type element to the end of the ArrayList instance.
* For example: let a = {name: "lala", age: "13岁"}; arrayList.add(a).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd003", 0, function () {
let arrayList = new ArrayList();
let a = {name: "lala", age: "13岁"};
arrayList.add(a);
let res = arrayList.has(a);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_004
* @tc.name : testAdd004
* @tc.desc : Add a array type element to the end of the ArrayList instance.
* For example: let a = [1, 2, 3, 4]; arrayList.add(a).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd004", 0, function () {
let arrayList = new ArrayList();
let a = [1, 2, 3, 4];
arrayList.add(a);
let res = arrayList.has(a);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_005
* @tc.name : testAdd005
* @tc.desc : Add a boolean type element to the end of the ArrayList instance.
* For example: let a = true; arrayList.add(a).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd005", 0, function () {
let arrayList = new ArrayList();
let a = true;
arrayList.add(a);
let res = arrayList.has(a);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_006
* @tc.name : testAdd006
* @tc.desc : Add a string element to the end of the ArrayList instance.
* For example: for (let i = 0; i < 100; i++) {arrayList.add(i);}.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd006", 0, function () {
let arrayList = new ArrayList();
for (let i = 0; i < 100; i++) {
arrayList.add(i);
}
let res = arrayList.getIndexOf(99);
let res1 = arrayList.length;
expect(res).assertEqual(99);
expect(res1).assertEqual(100);
});
/**
* @tc.number: TEST_ADD_007
* @tc.name : testAdd007
* @tc.desc : Add a symbol type element to the end of the ArrayList instance.
* For example: let a = "*";arrayList.add(a).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd007", 0, function () {
let arrayList = new ArrayList();
let a = "*";
arrayList.add(a);
let res = arrayList.has(a);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_008
* @tc.name : testAdd008
* @tc.desc : Add a decimal type to the end of the ArrayList instance. For example: let a = "3.14";arrayList.add(a).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd008", 0, function () {
let arrayList = new ArrayList();
let a = "3.14";
arrayList.add(a);
let res = arrayList.has(a);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_009
* @tc.name : testAdd009
* @tc.desc : Add a null character element to the end of the ArrayList instance.
* For example: let a = "";arrayList.add(a).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd009", 0, function () {
let arrayList = new ArrayList();
let a = "";
arrayList.add(a);
let res = arrayList.has(a);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_010
* @tc.name : testAdd010
* @tc.desc : Add a boolean type element to the end of the ArrayList instance.
* For example: arrayList.add.bind({})().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd010", 0, function () {
let arrayList = new ArrayList();
try {
arrayList.add.bind({}, "a")()
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The add method cannot be bound`);
}
});
/**
* @tc.number: TEST_INSERT_001
* @tc.name : testInsert001
* @tc.desc : Insert an element into the middle of the ArrayList instance. For example: arrayList.insert(8, 2).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testInsert001", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
arrayList.insert(8, 2);
let arr = [];
arrayList.forEach((item, index) => {
arr.push(item);
});
let a = ["四", "三", 8, 1, "a"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_INSERT_002
* @tc.name : testInsert002
* @tc.desc : Inserting an element with an index less than 0 will throw an exception.
* For example: arrayList.insert(8, -1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testInsert002", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
try {
let res = arrayList.insert(8, -1);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "index" is out of range. It must be >= 0 && <= 4. Received value is: -1`);
}
});
/**
* @tc.number: TEST_INSERT_003
* @tc.name : testInsert003
* @tc.desc : Inserting an element with an index greater than or equal to the length of
* the ArrayList instance will throw an exception. For example: arrayList.insert(8, 10).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testInsert003", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
try {
let res = arrayList.insert(8, 10);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "index" is out of range. It must be >= 0 && <= 4. Received value is: 10`);
}
});
/**
* @tc.number: TEST_INSERT_004
* @tc.name : testInsert004
* @tc.desc : Inserting an element with an index greater than or equal to the length of
* the ArrayList instance will throw an exception. For example: arrayList.insert(8, 11).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testInsert004", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
try {
let res = arrayList.insert(8, 11);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "index" is out of range. It must be >= 0 && <= 4. Received value is: 11`);
}
});
/**
* @tc.number: TEST_HAS_001
* @tc.name : testHas001
* @tc.desc : Check whether the ArrayList contains a specified element. For example: arrayList.has(8).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testHas001", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
arrayList.insert(8, 2);
let res = arrayList.has(8);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_HAS_002
* @tc.name : testHas002
* @tc.desc : Check whether the ArrayList contains a specified element.
* For example: arrayList.has.bind({})().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testHas002', 0, function () {
let arrayList = new ArrayList();
try {
arrayList.has.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The has method cannot be bound`);
}
});
/**
* @tc.number: TEST_HAS_003
* @tc.name : testHas003
* @tc.desc : Check whether the ArrayList contains a specified element. For example: arrayList.has("二").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testHas003", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
arrayList.insert(8, 2);
let res = arrayList.has("二");
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_GET_INDEX_OF_001
* @tc.name : testGetIndexOf001
* @tc.desc : In the ArrayList instance, find the index of a specified element from front to back,
* and return the index found for the first time. If not found, return -1. For example: arrayList.getIndexOf(1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetIndexOf001", 0, function () {
let arrayList = new ArrayList();
arrayList.add(1);
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
arrayList.insert(1, 2);
let res1 = arrayList.getIndexOf(1);
expect(res1).assertEqual(0);
});
/**
* @tc.number: TEST_GET_INDEX_OF_002
* @tc.name : testGetIndexOf002
* @tc.desc : In the ArrayList instance, find the index of a specified element from front to back,
* and return the index found for the first time. If not found, return -1. For example: arrayList.getIndexOf("A").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetIndexOf002", 0, function () {
let arrayList = new ArrayList();
arrayList.add(1);
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
arrayList.insert(1, 2);
let res = arrayList.getIndexOf("A");
expect(res).assertEqual(-1);
});
/**
* @tc.number: TEST_REMOVE_BY_INDEX_001
* @tc.name : testRemoveByIndex001
* @tc.desc : In the ArrayList instance, delete the element based on its index.
* For example: arrayList.removeByIndex(2).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemoveByIndex001", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
arrayList.removeByIndex(2);
let arr = [];
arrayList.forEach((item, index) => {
arr.push(item);
});
let a = ["四", "三", "a"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_REMOVE_BY_INDEX_002
* @tc.name : testRemoveByIndex002
* @tc.desc : In the ArrayList instance, delete the element based on its index index.
* For example: arrayList.removeByIndex(5).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemoveByIndex002", 0, function () {
let arrayList = new ArrayList();
arrayList.add("a");
arrayList.add("b");
arrayList.add("c");
arrayList.add("a");
arrayList.add("b");
try {
let res = arrayList.removeByIndex(5);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "index" is out of range. It must be >= 0 && <= 4. Received value is: 5`);
}
});
/**
* @tc.number: TEST_REMOVE_BY_INDEX_003
* @tc.name : testRemoveByIndex003
* @tc.desc : In the ArrayList instance, delete the element based on its index.
* For example: arrayList.removeByIndex.bind({})().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testRemoveByIndex003', 0, function () {
let arrayList = new ArrayList();
try {
arrayList.removeByIndex.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The removeByIndex method cannot be bound`);
}
});
/**
* @tc.number: TEST_REMOVE_001
* @tc.name : testRemove001
* @tc.desc : Delete the specified element . For example: arrayList.remove("三").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemove001", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
arrayList.remove("三");
let res = arrayList.has("三");
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_REMOVE_002
* @tc.name : testRemove002
* @tc.desc : Delete the specified element.For example: arrayList.remove("A").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemove002", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
let res = arrayList.remove("A");
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_REMOVE_003
* @tc.name : testRemove003
* @tc.desc : Delete the specified element.
* For example: arrayList.forEach((item, index) => {if (item == 1) {arrayList.remove(item);}}).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemove003", 0, function () {
let arrayList = new ArrayList();
arrayList.add(0);
arrayList.add(1);
arrayList.add(2);
arrayList.add(1);
arrayList.add(3);
arrayList.add(1);
arrayList.forEach((item, index) => {
if (item == 1) {
arrayList.remove(item);
}
});
let arr = [];
arrayList.forEach((item, index) => {
arr.push(item);
});
let a = [0, 2, 3];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_REMOVE_004
* @tc.name : testRemove004
* @tc.desc : Delete the specified element . For example: arrayList.remove.bind({})().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testRemove004', 0, function () {
let arrayList = new ArrayList();
try {
arrayList.remove.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The remove method cannot be bound`);
}
});
/**
* @tc.number: TEST_GET_LAST_INDEX_OF_001
* @tc.name : testGetLastIndexOf001
* @tc.desc : In the ArrayList instance, find the index of a specified element from brack to front,
* and return the index found for the first time. If not found, return -1. For example: arrayList.add("四").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetLastIndexOf001", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
arrayList.add(1);
arrayList.add("b");
let res = arrayList.getLastIndexOf(1);
expect(res).assertEqual(4);
});
/**
* @tc.number: TEST_REMOVE_BY_RANGE_001
* @tc.name : testRemoveByRange001
* @tc.desc : Deletes elements from a specified range, including elements at the start position and
* elements at the end position. For example: arrayList.removeByRange(1, 3).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemoveByRange001", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
arrayList.add(1);
arrayList.add("b");
arrayList.add("c");
arrayList.add(1);
arrayList.removeByRange(1, 3);
let arr = [];
arrayList.forEach((item, index) => {
arr.push(item);
});
let a = ["四", "a", 1, "b", "c", 1];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_REMOVE_BY_RANGE_002
* @tc.name : testRemoveByRange002
* @tc.desc : Add a string element to the end of the ArrayList instance. For example: arrayList.add("四").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemoveByRange002", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
arrayList.add(1);
arrayList.add("b");
arrayList.add("c");
arrayList.add(1);
try {
let res = arrayList.removeByRange(3, 1);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "fromIndex" is out of range. It must be >= 0 && <= 0. Received value is: 3`);
}
});
/**
* @tc.number: TEST_REMOVE_BY_RANGE_003
* @tc.name : testRemoveByRange003
* @tc.desc : Deletes elements from a specified range, including elements at the start position and
* elements at the end position. For example: removeByRange(6, 8).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemoveByRange003", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
arrayList.add(1);
try {
let res = arrayList.removeByRange(6, 8);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "fromIndex" is out of range. It must be >= 0 && <= 4. Received value is: 6`);
}
});
/**
* @tc.number: TEST_REMOVE_BY_RANGE_004
* @tc.name : testRemoveByRange004
* @tc.desc : Deletes elements from a specified range, including elements at the start position and
* elements at the end position. For example: removeByRange(0, 7).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemoveByRange004", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
arrayList.add(1);
arrayList.add("b");
arrayList.add("c");
arrayList.add(1);
arrayList.removeByRange(0, 8);
let res = arrayList.length;
let res1 = arrayList.getLastIndexOf(1);
expect(res).assertEqual(0);
expect(res1).assertEqual(-1);
});
/**
* @tc.number: TEST_REMOVE_BY_RANGE_005
* @tc.name : testRemoveByRange005
* @tc.desc : Deletes elements from a specified range, including elements at the start position and
* elements at the end position. For example: removeByRange(0, 8).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemoveByRange005", 0, function () {
let arrayList = new ArrayList();
arrayList.add("四");
arrayList.add("三");
arrayList.add(1);
arrayList.add("a");
arrayList.add(1);
arrayList.add("b");
arrayList.add("c");
arrayList.add(1);
try {
arrayList.removeByRange(0, 9);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "toIndex" is out of range. It must be >= 0 && <= 8. Received value is: 9`);
}
});
/**
* @tc.number: TEST_REPLACE_ALL_ELEMENTS_001
* @tc.name : testReplaceAllElements001
* @tc.desc : Perform some operation on the elements in the ArrayList instance and return the ArrayList instance
* after the operation. For example: arrayList.replaceAllElements((item, index) => {return (item = 2 * item);}).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testReplaceAllElements001", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
arrayList.replaceAllElements((item:number, index:number) => {
return (item = 2 * item);
});
let arr = [];
arrayList.forEach((item, index) => {
arr.push(item);
});
let a = [8, 6, 2, 4, 28];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_FOR_EACH_001
* @tc.name : testForEach001
* @tc.desc : Traversing elements in an ArrayList instance.
* For example: arrayList.forEach((item, index) => {arr.push(item);}).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testForEach001", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
let arr = [];
arrayList.forEach((item, index) => {
arr.push(item);
});
let a = [4, 3, 1, 2, 14];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_FOR_EACH_002
* @tc.name : testForEach002
* @tc.desc : Traversing elements in an ArrayList instance.
* For example: arrayList.forEach.bind({}, "a")(() => {}).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testForEach002', 0, function () {
let arrayList = new ArrayList();
try {
arrayList.forEach.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The forEach method cannot be bound`);
}
});
/**
* @tc.number: TEST_SORT_001
* @tc.name : testSort001
* @tc.desc : Arrange the elements in the ArrayList instance in descending order.
* For example: arrayList.sort((a, b) => a - b).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSort001", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
arrayList.sort((a:any, b:any) => a - b);
let arr = [];
arrayList.forEach((item, index) => {
arr.push(item);
});
let a = [1, 2, 3, 4, 14];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_SORT_002
* @tc.name : testSort002
* @tc.desc : Arrange the elements in the ArrayList instance in descending order.
* For example: arrayList.sort((a, b) => a - b).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSort002", 0, function () {
let arrayList = new ArrayList();
arrayList.add("刘");
arrayList.add("张三");
arrayList.add(1);
arrayList.add(2);
arrayList.add("李四");
arrayList.sort((a:any, b:any) => a - b);
let arr = [];
arrayList.forEach((item, index) => {
arr.push(item);
});
let a = ["刘", "张三", 1, 2, "李四"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_SORT_003
* @tc.name : testSort003
* @tc.desc : Arrange the elements in the ArrayList instance in descending order.
* For example: arrayList.sort((a, b) => a - b).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSort003", 0, function () {
let arrayList = new ArrayList();
arrayList.add("c");
arrayList.add("a");
arrayList.add("b");
arrayList.add("e");
arrayList.add("d");
arrayList.sort((a:any, b:any) => a - b);
let arr = [];
arrayList.forEach((item, index) => {
arr.push(item);
});
let a = ["c", "a", "b", "e", "d"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_SUB_ARRAY_LIST_001
* @tc.name : testSubArrayList001
* @tc.desc : Intercepts an element within the specified range, including the element with the
* starting index but not the element with the ending index. For example: arrayList.subArrayList(2, 4).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSubArrayList001", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
let subArr = arrayList.subArrayList(2, 4);
let arr = [];
subArr.forEach((item, index) => {
arr.push(item);
});
let a = [1, 2];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_SUB_ARRAY_LIST_002
* @tc.name : testSubArrayList002
* @tc.desc : Intercepts an element within the specified range, including the element with the
* starting index but not the element with the ending index. For example: arrayList.subArrayList(4, 2).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSubArrayList002", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
try {
let subArr = arrayList.subArrayList(4, 2);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "fromIndex" is out of range. It must be >= 0 && <= 1. Received value is: 4`);
}
});
/**
* @tc.number: TEST_SUB_ARRAY_LIST_003
* @tc.name : testSubArrayList003
* @tc.desc : Intercepts an element within the specified range, including the element with the
* starting index but not the element with the ending index. For example: arrayList.subArrayList(0 ,6).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSubArrayList003", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
let subArr = arrayList.subArrayList(0, 5);
let arr = [];
arrayList.forEach((item, index) => {
arr.push(item);
});
let a = [4, 3, 1, 2, 14];
for (let i = 0; i < a.length; i++) {
expect(a[i]).assertEqual(arr[i]);
}
});
/**
* @tc.number: TEST_SUB_ARRAY_LIST_004
* @tc.name : testSubArrayList004
* @tc.desc : Intercepts an element within the specified range, including the element with the
* starting index but not the element with the ending index. For example: arrayList.subArrayList(6, 9).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSubArrayList004", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
try {
let subArr = arrayList.subArrayList(6, 9);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "fromIndex" is out of range. It must be >= 0 && <= 4. Received value is: 6`);
}
});
/**
* @tc.number: TEST_CLEAR_001
* @tc.name : testClear001
* @tc.desc : Clear all elements in the ArrayList instance. For example: arrayList.clear().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testClear001", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
arrayList.clear();
let res = arrayList.length;
expect(res).assertEqual(0);
});
/**
* @tc.number: TEST_CLEAR_002
* @tc.name : testClear002
* @tc.desc : Clear all elements in the ArrayList instance. For example: arrayList.clear.bind({}, "a")().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testClear002', 0, function () {
let arrayList = new ArrayList();
try {
arrayList.clear.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The clear method cannot be bound`);
}
});
/**
* @tc.number: TEST_CLONE_001
* @tc.name : testClone001
* @tc.desc : Clone an ArrayList instance. For example: arrayList.clone().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testClone001", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
let res = arrayList.clone();
let arr = [];
res.forEach((item, index) => {
arr.push(item);
});
let a = [4, 3, 1, 2, 14];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_GET_CAPACITY_001
* @tc.name : testGetCapacity001
* @tc.desc : Get the capacity of ArrayList instance. For example: arrayList.getCapacity().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetCapacity001", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
let res = arrayList.getCapacity();
expect(res).assertEqual(10);
});
/**
* @tc.number: TEST_GET_CAPACITY_002
* @tc.name : testGetCapacity002
* @tc.desc : Get the capacity of the ArrayList instance after capacity expansion.
* For example: arrayList.getCapacity().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetCapacity002", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
arrayList.add("a");
arrayList.add("b");
arrayList.add("c");
arrayList.add("d");
arrayList.add("v");
let a = [1, 2, 3, 4];
arrayList.add(a);
let res = arrayList.getCapacity();
expect(res).assertEqual(15);
});
/**
* @tc.number: TEST_CONVERT_TO_ARRAY_001
* @tc.name : testConvertToArray001
* @tc.desc : Convert an ArrayList instance to an array. For example: arrayList.convertToArray().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testConvertToArray001", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
let arr = arrayList.convertToArray();
let a = [4, 3, 1, 2, 14];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_IS_EMPTY_001
* @tc.name : testIsEmpty001
* @tc.desc : Determine whether the ArrayList instance is empty. For example: arrayList.isEmpty().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIsEmpty001", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
arrayList.clear();
let res = arrayList.isEmpty();
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_IS_EMPTY_002
* @tc.name : testIsEmpty002
* @tc.desc : Determine whether the ArrayList instance is empty. For example: arrayList.isEmpty().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIsEmpty002", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
let res = arrayList.isEmpty();
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_IS_EMPTY_003
* @tc.name : testIsEmpty003
* @tc.desc : Determine whether the ArrayList instance is empty. For example: arrayList.isEmpty.bind({}, "a")().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testIsEmpty003', 0, function () {
let arrayList = new ArrayList();
try {
arrayList.isEmpty.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The isEmpty method cannot be bound`);
}
});
/**
* @tc.number: TEST_INCREASE_CAPACITY_TO_001
* @tc.name : testIncreaseCapacityTo001
* @tc.desc : Expand the ArrayList instance capacity to the specified value.
* For example: arrayList.increaseCapacityTo(8).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIncreaseCapacityTo001", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
arrayList.increaseCapacityTo(8);
let res = arrayList.getCapacity();
expect(res).assertEqual(8);
});
/**
* @tc.number: TEST_INCREASE_CAPACITY_TO_002
* @tc.name : testIncreaseCapacityTo002
* @tc.desc : Expand the ArrayList instance capacity to the specified value.
* For example: arrayList.increaseCapacityTo(-1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIncreaseCapacityTo002", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
arrayList.increaseCapacityTo(-1);
let res = arrayList.getCapacity();
expect(res).assertEqual(10);
});
/**
* @tc.number: TEST_TRIM_TO_CURRENT_LENGTH_001
* @tc.name : testTrimToCurrentLength001
* @tc.desc : Limit the ArrayList instance capacity to the length of the ArrayList instance.
* For example: arrayList.trimToCurrentLength().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testTrimToCurrentLength001", 0, function () {
let arrayList = new ArrayList();
arrayList.add(4);
arrayList.add(3);
arrayList.add(1);
arrayList.add(2);
arrayList.add(14);
arrayList.trimToCurrentLength();
let res = arrayList.getCapacity();
expect(res).assertEqual(5);
});
/**
* @tc.number: TEST_ITERATOR_001
* @tc.name : testIterator001
* @tc.desc : Iterates over all elements in an ArrayList instance. For example: arrayList[Symbol.iterator]().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIterator001", 0, function () {
let arrayList = new ArrayList();
arrayList.add("刘");
arrayList.add("张三");
arrayList.add(1);
arrayList.add(2);
arrayList.add("李四");
let arr = [];
let itr = arrayList[Symbol.iterator]();
let tmp = undefined;
do {
tmp = itr.next().value;
arr.push(tmp);
} while (tmp != undefined);
let a = ["刘", "张三", 1, 2, "李四"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
})
}
\ No newline at end of file
/**
* Copyright (c) 2023 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.
*/
import ArraylistTest from './ArrayList.test'
export default function testsuite() {
ArraylistTest()
}
\ No newline at end of file
{
"module": {
"name": "entry_test",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/TestAbility/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"exported": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.commonlibrary.crossplatform.LightWeightSet.normal",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 10,
"targetAPIVersion": 10,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
}
# Copyright (C) 2023 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.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsCrossPlatformLightWeightSetTest") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
# hap_name: HAP的名字,可选,默认为目标名
hap_name = "ActsCrossPlatformLightWeightSetTest"
subsystem_name = "commonlibrary"
part_name = "ets_utils"
}
ohos_app_scope("windowStage_app_profile") {
# app_profile: HAP的AppScope中的app.json,只在Stage模型下使用
app_profile = "AppScope/app.json"
# sources: 资源文件路径
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
# source_dir: js或ets代码路径,兼容FA模型的单ability配置到ability目录
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
# sources: 资源文件路径
sources = [ "src/main/resources" ]
# deps: 当前目标的依赖
deps = [ ":windowStage_app_profile" ]
# hap_profile: HAP的config.json,Stage模型对应module.json
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
// 指定设备执行的驱动
"driver": {
"type": "OHJSUnitTest",
//test-timeout: 测试hap 整体执行用例的执行时长
"test-timeout": "60000",
//shell-timeout: aa test 拉起命令执行时长
"shell-timeout": "60000",
//bundle-name: 与HAP的app.json bundleName 保持一致
"bundle-name": "ohos.acts.commonlibrary.crossplatform.LightWeightSet.normal",
//module-name: 与HAP的module.json "module"字段的 name 保持一致
"module-name": "entry_test"
//testcase-timeout: 测试hap 单条用例的执行时长
//"testcase-timeout": 5000
},
// kit的作用主要是为了支撑测试执行活动,在测试前执行预制操作(Setup),在测试后执行清理操作(Teardown)
"kits": [
{
"test-file-name": [
"ActsDemoStageTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
/**
* Copyright (c) 2023 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.
*/
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import hilog from '@ohos.hilog';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import window from '@ohos.window';
export default class TestAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? '');
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
windowStage.loadContent('TestAbility/pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
}
onForeground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
}
onBackground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
}
}
\ No newline at end of file
/**
* Copyright (c) 2023 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.
*/
import hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
aboutToAppear() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear');
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ No newline at end of file
/*
* Copyright (C) 2023 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.
*/
import LightWeightSet from "@ohos.util.LightWeightSet";
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
export default function LightWeightSetTest() {
describe("LightWeightSetTest", function () {
/**
* @tc.number: TEST_CONSTRUCTOR_001
* @tc.name : testConstructor001
* @tc.desc : Create an LightWeightSet instance. For example: let lightWeightSet = new LightWeightSet().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testConstructor001", 0, function () {
try {
let lightWeightSet = new LightWeightSet();
expect(lightWeightSet != undefined).assertEqual(true);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The LightWeightSet's constructor cannot be directly invoked");
}
});
/**
* @tc.number: TEST_LENGTH_001
* @tc.name : testLength001
* @tc.desc : Get the number of element in the LightWeightSet instance. For example: lightWeightSet.length.
* @tc.size : MediumTest
* @tc.type : Field
* @tc.level : Level 1
*/
it("testLength001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let res = lightWeightSet.length;
expect(res).assertEqual(5);
});
/**
* @tc.number: TEST_ADD_001
* @tc.name : testAdd001
* @tc.desc : Add element to LightWeightSet instance. For example: lightWeightSet.add(1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
let res = lightWeightSet.has(1);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_002
* @tc.name : testAdd002
* @tc.desc : Add element to LightWeightSet instance. For example: lightWeightSet.add("a").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd002", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add("a");
let res = lightWeightSet.has("a");
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_003
* @tc.name : testAdd003
* @tc.desc : Add element to LightWeightSet instance.
* For example: let a = [1, 2, 3, 4]; lightWeightSet.add(a).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd003", 0, function () {
let lightWeightSet = new LightWeightSet();
let a = [1, 2, 3, 4];
lightWeightSet.add(a);
let res = lightWeightSet.has(a);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_004
* @tc.name : testAdd004
* @tc.desc : Add element to LightWeightSet instance.
* For example: let a = {name: "lili", age: "13"}; lightWeightSet.add(a).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd004", 0, function () {
let lightWeightSet = new LightWeightSet();
let c = {name: "lili", age: "13"};
lightWeightSet.add(c);
let res = lightWeightSet.has(c);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_005
* @tc.name : testAdd005
* @tc.desc : Add element to LightWeightSet instance. For example: let c = false; lightWeightSet.add(c).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd005", 0, function () {
let lightWeightSet = new LightWeightSet();
let c = false;
lightWeightSet.add(c);
let res = lightWeightSet.has(c);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_006
* @tc.name : testAdd006
* @tc.desc : Add element to LightWeightSet instance. For example: lightWeightSet.add(null).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd006", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(null);
let res = lightWeightSet.has(null);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_007
* @tc.name : testAdd007
* @tc.desc : Add element to LightWeightSet instance. For example: lightWeightSet.add(1.23).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd007", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1.23);
let res1 = lightWeightSet.has(1.23);
expect(res1).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_008
* @tc.name : testAdd008
* @tc.desc : Add element to LightWeightSet instance.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd008", 0, function () {
let lightWeightSet = new LightWeightSet();
for (let i = 0; i < 10000; i++) {
lightWeightSet.add(i);
}
let res = lightWeightSet.getValueAt(9999);
let res1 = lightWeightSet.length;
expect(res).assertEqual(9999);
expect(res1).assertEqual(10000);
});
/**
* @tc.number: TEST_ADD_009
* @tc.name : testAdd009
* @tc.desc : Add element to LightWeightSet instance. For example: lightWeightSet.add("").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd009", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add("");
let res = lightWeightSet.has("");
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_010
* @tc.name : testAdd010
* @tc.desc : Add element to LightWeightSet instance. For example: lightWeightSet.add("$").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd010", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add("$");
let res = lightWeightSet.has("$");
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_ADD_ALL_001
* @tc.name : testAddAll001
* @tc.desc : Copy all element from one LightWeightSet to another.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAddAll001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let lightWeightSet1 = new LightWeightSet();
lightWeightSet1.add(6);
lightWeightSet1.add(7);
let res1 = lightWeightSet.addAll(lightWeightSet1);
for (let item of lightWeightSet) {
console.log("lightWeightSet-----" + item);
}
for (let item of lightWeightSet1) {
console.log("lightWeightSet1-----" + item);
}
for (let i = 1; i < 8; i++) {
expect(lightWeightSet.has(i)).assertEqual(true);
}
expect(res1).assertEqual(true);
});
/**
* @tc.number: TEST_HAS_ALL_001
* @tc.name : testHasAll001
* @tc.desc : Judge whether a lightWeightSet contains all elements in another lightWeightSet.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testHasAll001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add("a");
lightWeightSet.add("b");
lightWeightSet.add("c");
lightWeightSet.add("d");
lightWeightSet.add("e");
let lightWeightSet1 = new LightWeightSet();
lightWeightSet1.add("a");
lightWeightSet1.add("d");
let res = lightWeightSet.hasAll(lightWeightSet1);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_HAS_ALL_002
* @tc.name : testHasAll002
* @tc.desc : Judge whether a lightWeightSet contains all elements in another lightWeightSet.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testHasAll002", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add("a");
lightWeightSet.add("b");
lightWeightSet.add("c");
lightWeightSet.add("e");
let lightWeightSet1 = new LightWeightSet();
lightWeightSet1.add("a");
lightWeightSet1.add("d");
let res = lightWeightSet.hasAll(lightWeightSet1);
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_HAS_ALL_003
* @tc.name : testHasAll003
* @tc.desc : Judge whether a lightWeightSet contains all elements in another lightWeightSet.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testHasAll003", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let lightWeightSet1 = new LightWeightSet();
lightWeightSet1.add("a1");
lightWeightSet1.add("d1");
let res = lightWeightSet.hasAll(lightWeightSet1);
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_HAS_ALL_004
* @tc.name : testHasAll004
* @tc.desc : Judge whether a lightWeightSet contains all elements in another lightWeightSet.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testHasAll004", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let lightWeightSet1 = new LightWeightSet();
lightWeightSet1.add(1);
lightWeightSet1.add("d");
let res = lightWeightSet.hasAll(lightWeightSet1);
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_HAS_001
* @tc.name : testHas001
* @tc.desc : Judge whether a lightWeightSet contains all elements in another lightWeightSet.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testHas001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add("a");
lightWeightSet.add("b");
lightWeightSet.add("c");
lightWeightSet.add("d");
lightWeightSet.add("e");
let res = lightWeightSet.has("a");
expect(res).assertEqual(true);
let res1 = lightWeightSet.has(1);
expect(res1).assertEqual(false);
});
/**
* @tc.number: TEST_EQUAL_001
* @tc.name : testEqual001
* @tc.desc : Compare lightWeightMap and specified object for equality. For example: lightWeightSet.equal(obj).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testEqual001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
let obj = [1,2,3];
let res = lightWeightSet.equal(obj);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_EQUAL_002
* @tc.name : testEqual002
* @tc.desc : Compare lightWeightMap and specified object for equality. For example: lightWeightSet.equal(obj).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testEqual002", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
let obj = [1,2];
let res = lightWeightSet.equal(obj);
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_INCREASE_CAPACITY_TO_001
* @tc.name : testIncreaseCapacityTo001
* @tc.desc : Expand the LightWeightSet capacity to the specified value.
* For example: lightWeightSet.increaseCapacityTo(3).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIncreaseCapacityTo001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
try {
lightWeightSet.increaseCapacityTo(3);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "minimumCapacity" is out of range. It must be > 8. Received value is: 3`);
}
});
/**
* @tc.number: TEST_INCREASE_CAPACITY_TO_002
* @tc.name : testIncreaseCapacityTo002
* @tc.desc : Expand the LightWeightSet capacity to the specified value.
* For example: lightWeightSet.increaseCapacityTo(20).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIncreaseCapacityTo002", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let res = lightWeightSet.increaseCapacityTo(20);
expect(res).assertEqual(undefined);
});
/**
* @tc.number: TEST_GET_INDEX_OF_001
* @tc.name : testGetIndexOf001
* @tc.desc : Get the index according to the specified element. For example: lightWeightSet.getIndexOf(2).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetIndexOf001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let res = lightWeightSet.getIndexOf(2);
expect(res).assertEqual(1);
});
/**
* @tc.number: TEST_REMOVE_001
* @tc.name : testRemove001
* @tc.desc : Delete elements according to key. For example: lightWeightMap.remove(1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemove001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let res = lightWeightSet.remove(1);
expect(res).assertEqual(1);
let arr = [];
lightWeightSet.forEach((value, index) => {
arr.push(value);
});
let arr1 = [2, 3, 4, 5];
for (let i = 0; i < arr.length; i++) {
expect(arr1[i]).assertEqual(arr[i]);
}
});
/**
* @tc.number: TEST_REMOVE_002
* @tc.name : testRemove002
* @tc.desc : Delete elements according to key. For example: lightWeightMap.remove(3).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemove002", 0, function () {
let lightWeightSet = new LightWeightSet();
let res = lightWeightSet.remove(3);
expect(res).assertEqual(undefined);
});
/**
* @tc.number: TEST_REMOVE_003
* @tc.name : testRemove003
* @tc.desc : Delete elements according to key. For example: lightWeightMap.remove("A").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemove003", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let res = lightWeightSet.remove("A");
expect(res).assertEqual(undefined);
});
/**
* @tc.number: TEST_REMOVE_AT_001
* @tc.name : testRemoveAt001
* @tc.desc : Delete elements according to index. For example: lightWeightSet.removeAt(1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemoveAt001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let res = lightWeightSet.removeAt(1);
expect(res).assertEqual(true);
let arr = [];
lightWeightSet.forEach((value, index) => {
arr.push(value);
});
let arr1 = [1, 3, 4, 5];
for (let i = 0; i < arr.length; i++) {
expect(arr1[i]).assertEqual(arr[i]);
}
});
/**
* @tc.number: TEST_REMOVE_AT_002
* @tc.name : testRemoveAt002
* @tc.desc : Delete elements according to index. For example: lightWeightSet.removeAt(1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemoveAt002", 0, function () {
let lightWeightSet = new LightWeightSet();
let res = lightWeightSet.removeAt(1);
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_CLEAR_001
* @tc.name : testClear001
* @tc.desc : Clear all elements in LightWeightSet. For example: lightWeightSet.clear().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testClear001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
lightWeightSet.clear();
let res = lightWeightSet.length;
expect(res).assertEqual(0);
});
/**
* @tc.number: TEST_CLEAR_002
* @tc.name : testClear002
* @tc.desc : Clear all elements in LightWeightSet. For example: lightWeightSet.clear().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testClear002", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let res = lightWeightSet.length;
lightWeightSet.clear();
let res1 = lightWeightSet.length;
expect(res).assertEqual(5);
expect(res1).assertEqual(0);
});
/**
* @tc.number: TEST_FOR_EACH_001
* @tc.name : testForEach001
* @tc.desc : Traverse all elements in the LightWeightSet instance.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testForEach001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let arr = [];
lightWeightSet.forEach((value, index) => {
arr.push(value);
});
let arr1 = [1, 2, 3, 4, 5];
for (let i = 0; i < arr1.length; i++) {
expect(arr[i]).assertEqual(arr1[i]);
}
});
/**
* @tc.number: TEST_ITERATOR_001
* @tc.name : testIterator001
* @tc.desc : Iterate over all elements in the LightWeightSet.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIterator001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let arr = [];
let res = lightWeightSet[Symbol.iterator]();
let temp = undefined;
do {
temp = res.next().value;
arr.push(temp);
} while (temp != undefined);
let arr1 = [1, 2, 3, 4, 5];
for (let i = 0; i < arr1.length; i++) {
expect(arr[i]).assertEqual(arr1[i]);
}
});
/**
* @tc.number: TEST_TO_STRING_001
* @tc.name : testToString001
* @tc.desc : Use "," to splice the elements in the LightWeightSet instance into a string.
* For example: lightWeightSet.toString().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testToString001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
let res = lightWeightSet.toString();
expect(res).assertEqual("1,2,3");
});
/**
* @tc.number: TEST_TO_ARRAY_001
* @tc.name : testToArray001
* @tc.desc : Convert an lightWeightSet instance to an array. For example: lightWeightSet.toArray().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testToArray001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let res = lightWeightSet.toArray();
let arr1 = [1, 2, 3, 4, 5];
for (let i = 0; i < arr1.length; i++) {
expect(res[i]).assertEqual(arr1[i]);
}
});
/**
* @tc.number: TEST_GET_VALUE_AT_001
* @tc.name : testGetValueAt001
* @tc.desc : Get the element according to the corresponding index. For example: lightWeightSet.getValueAt(1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetValueAt001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let res = lightWeightSet.getValueAt(1);
expect(res).assertEqual(2);
});
/**
* @tc.number: TEST_VALUES_001
* @tc.name : testValues001
* @tc.desc : Get a collection of all the values in the LightWeightSet. For example: lightWeightSet.values().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testValues001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let res = lightWeightSet.values();
expect(res.next().value).assertEqual(1);
expect(res.next().value).assertEqual(2);
expect(res.next().value).assertEqual(3);
expect(res.next().value).assertEqual(4);
expect(res.next().value).assertEqual(5);
});
/**
* @tc.number: TEST_ENTRIES_001
* @tc.name : testEntries001
* @tc.desc : Get all key value pairs collection in lightWeightSet.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testEntries001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let res = lightWeightSet.entries();
expect(JSON.stringify(res.next().value)).assertEqual("[1,1]");
expect(JSON.stringify(res.next().value)).assertEqual("[2,2]");
expect(JSON.stringify(res.next().value)).assertEqual("[3,3]");
expect(JSON.stringify(res.next().value)).assertEqual("[4,4]");
expect(JSON.stringify(res.next().value)).assertEqual("[5,5]");
});
/**
* @tc.number: TEST_IS_EMPTY_001
* @tc.name : testIsEmpty001
* @tc.desc : Determine whether the lightWeightSet instance is empty. For example: lightWeightSet.isEmpty().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIsEmpty001", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
let res = lightWeightSet.isEmpty();
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_IS_EMPTY_002
* @tc.name : testIsEmpty002
* @tc.desc : Determine whether the lightWeightSet instance is empty. For example: lightWeightSet.isEmpty().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIsEmpty002", 0, function () {
let lightWeightSet = new LightWeightSet();
lightWeightSet.add(1);
lightWeightSet.add(2);
lightWeightSet.add(3);
lightWeightSet.add(4);
lightWeightSet.add(5);
lightWeightSet.clear();
let res = lightWeightSet.isEmpty();
expect(res).assertEqual(true);
});
})
}
\ No newline at end of file
/**
* Copyright (c) 2023 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.
*/
import LightWeightSetTest from './LightWeightSet.test'
export default function testsuite() {
LightWeightSetTest()
}
\ No newline at end of file
{
"module": {
"name": "entry_test",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/TestAbility/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"exported": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.commonlibrary.crossplatform.List2.normal",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 10,
"targetAPIVersion": 10,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
}
# Copyright (C) 2023 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.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsCrossPlatformList2Test") {
hap_profile = "src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
# hap_name: HAP的名字,可选,默认为目标名
hap_name = "ActsCrossPlatformList2Test"
subsystem_name = "commonlibrary"
part_name = "ets_utils"
}
ohos_app_scope("windowStage_app_profile") {
# app_profile: HAP的AppScope中的app.json,只在Stage模型下使用
app_profile = "AppScope/app.json"
# sources: 资源文件路径
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
# source_dir: js或ets代码路径,兼容FA模型的单ability配置到ability目录
source_dir = "src/main/ets"
}
ohos_resources("windowStage_resources") {
# sources: 资源文件路径
sources = [ "src/main/resources" ]
# deps: 当前目标的依赖
deps = [ ":windowStage_app_profile" ]
# hap_profile: HAP的config.json,Stage模型对应module.json
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
// 指定设备执行的驱动
"driver": {
"type": "OHJSUnitTest",
//test-timeout: 测试hap 整体执行用例的执行时长
"test-timeout": "60000",
//shell-timeout: aa test 拉起命令执行时长
"shell-timeout": "60000",
//bundle-name: 与HAP的app.json bundleName 保持一致
"bundle-name": "ohos.acts.commonlibrary.crossplatform.List2.normal",
//module-name: 与HAP的module.json "module"字段的 name 保持一致
"module-name": "entry_test"
//testcase-timeout: 测试hap 单条用例的执行时长
//"testcase-timeout": 5000
},
// kit的作用主要是为了支撑测试执行活动,在测试前执行预制操作(Setup),在测试后执行清理操作(Teardown)
"kits": [
{
"test-file-name": [
"ActsDemoStageTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
/**
* Copyright (c) 2023 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.
*/
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import hilog from '@ohos.hilog';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import window from '@ohos.window';
export default class TestAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? '');
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
windowStage.loadContent('TestAbility/pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
}
onForeground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
}
onBackground() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
}
}
\ No newline at end of file
/**
* Copyright (c) 2023 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.
*/
import hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
aboutToAppear() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear');
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ No newline at end of file
/**
* Copyright (c) 2023 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.
*/
import ListTest from './List2.test'
export default function testsuite() {
ListTest()
}
\ No newline at end of file
/*
* Copyright (C) 2023 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.
*/
import List from "@ohos.util.List";
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
export default function ListTest() {
describe("ListTest", function () {
/**
* @tc.number: TEST_CONSTRUCTOR_001
* @tc.name : testConstructor001
* @tc.desc : Create an List instance. For example: let list = new List().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testConstructor001", 0, function () {
try {
let list = new List();
expect(list != undefined).assertEqual(true);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The List's constructor cannot be directly invoked");
}
});
/**
* @tc.number: TEST_LENGTH_001
* @tc.name : testLength001
* @tc.desc : Get the number of elements contained in the List instance. For example: list.length.
* @tc.size : MediumTest
* @tc.type : Field
* @tc.level : Level 1
*/
it("testLength001", 0, function () {
let list = new List();
list.add(4);
list.add(3);
list.add(1);
list.add(2);
list.add(14);
let res = list.length;
expect(res).assertEqual(5);
});
/**
* @tc.number: TEST_ADD_001
* @tc.name : testAdd001
* @tc.desc : Add a element to the end of the List instance. For example: list.add(8).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd001", 0, function () {
let list = new List();
list.add(8);
let res = list.get(0);
expect(res).assertEqual(8);
});
/**
* @tc.number: TEST_ADD_002
* @tc.name : testAdd002
* @tc.desc : Add a element to the end of the List instance.
* For example: let a = [1, 2, 3, 4]; list.add(a).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd002", 0, function () {
let list = new List();
let a = [1, 2, 3, 4];
list.add(a);
let res = list.get(0);
expect(res).assertEqual(a);
});
/**
* @tc.number: TEST_ADD_003
* @tc.name : testAdd003
* @tc.desc : Add a element to the end of the List instance.
* For example: let a = {name: "lala", age: "13"}; list.add(a).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd003", 0, function () {
let list = new List();
let a = {name: "lala", age: "13"};
list.add(a);
let res = list.get(0);
expect(res).assertEqual(a);
});
/**
* @tc.number: TEST_ADD_004
* @tc.name : testAdd004
* @tc.desc : Add a element to the end of the List instance. For example: list.add("*").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd004", 0, function () {
let list = new List();
list.add(".");
list.add("*");
list.add("|");
let res = list.get(0);
expect(res).assertEqual(".");
});
/**
* @tc.number: TEST_ADD_005
* @tc.name : testAdd005
* @tc.desc : Add a element to the end of the List instance. For example: list.add("*").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd005", 0, function () {
let list = new List();
list.add(".");
list.add("*");
list.add("|");
let arr = [];
list.forEach((item, index) => {
arr.push(item);
});
let a = [".", "*", "|"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_ADD_006
* @tc.name : testAdd006
* @tc.desc : Add a element to the end of the List instance. For example: list.add(" ").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd006", 0, function () {
let list = new List();
list.add(" ");
let res = list.get(0);
expect(res).assertEqual(" ");
});
/**
* @tc.number: TEST_ADD_007
* @tc.name : testAdd007
* @tc.desc : Add a element to the end of the List instance. For example: list.add("a").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd007", 0, function () {
let list = new List();
list.add("a");
list.add("a");
let res = list.get(0);
let res1 = list.get(1);
expect(res).assertEqual("a");
expect(res1).assertEqual("a");
});
/**
* @tc.number: TEST_ADD_008
* @tc.name : testAdd008
* @tc.desc : Add a element to the end of the List instance. For example: for (let i = 0; i < 100; i++) {list.add(i);}.
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd008", 0, function () {
let list = new List();
for (let i = 0; i < 100; i++) {
list.add(i);
}
let res = list.get(99);
let res1 = list.length;
expect(res).assertEqual(99);
expect(res1).assertEqual(100);
});
/**
* @tc.number: TEST_ADD_009
* @tc.name : testAdd009
* @tc.desc : Add a element to the end of the List instance. For example: list.add(null).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd009", 0, function () {
let list = new List();
list.add(null);
let res = list.get(0);
expect(res).assertEqual(null);
});
/**
* @tc.number: TEST_ADD_010
* @tc.name : testAdd010
* @tc.desc : Add a element to the end of the List instance. For example: list.add(0.1111).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd010", 0, function () {
let list = new List();
list.add(0.1111);
let res = list.get(0);
expect(res).assertEqual(0.1111);
});
/**
* @tc.number: TEST_ADD_011
* @tc.name : testAdd011
* @tc.desc : Add a element to the end of the List instance. For example: list.add(-1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd011", 0, function () {
let list = new List();
list.add(-1);
let res = list.get(0);
expect(res).assertEqual(-1);
});
/**
* @tc.number: TEST_ADD_012
* @tc.name : testAdd012
* @tc.desc : Add a element to the end of the List instance. For example: const obj = {}; list.add(obj).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testAdd012", 0, function () {
let list = new List();
const obj = {};
list.add(obj);
let res = list.get(0);
expect(res).assertEqual(obj);
});
/**
* @tc.number: TEST_ADD_013
* @tc.name : testAdd013
* @tc.desc : Add a element to the end of the List instance. For example: list.add.bind({}, "a")().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testAdd013', 0, function () {
let list = new List();
try {
list.add.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The add method cannot be bound`);
}
});
/**
* @tc.number: TEST_INSERT_001
* @tc.name : testInsert001
* @tc.desc : Insert an element into the middle of the List instance. For example: list.insert("d", 3).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testInsert001", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list.insert("d", 3);
let arr = [];
list.forEach((item, index) => {
arr.push(item);
});
let a = ["a", "b", "c", "d", "a", "b"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_INSERT_002
* @tc.name : testInsert002
* @tc.desc : Insert an element into the middle of the List instance. For example: list.insert("d", 8).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testInsert002", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
try {
let res = list.insert("d", 8);
expect(true).assertEqual(false);
} catch(err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "index" is out of range. It must be >= 0 && <= 5. Received value is: 8`);
}
});
/**
* @tc.number: TEST_GET_001
* @tc.name : testGet001
* @tc.desc : Gets the element corresponding to the specified index. For example: list.get(0).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGet001", 0, function () {
let list = new List();
list.add("四");
let res = list.get(0);
expect(res).assertEqual("四");
});
/**
* @tc.number: TEST_GET_002
* @tc.name : testGet002
* @tc.desc : Gets the element corresponding to the specified index. For example: list.get(2).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGet002", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list.add("b");
let res = list.get(2);
expect(res).assertEqual("c");
});
/**
* @tc.number: TEST_GET_003
* @tc.name : testGet003
* @tc.desc : Gets the element corresponding to the specified index. For example: list.get(6).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGet003", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list.add("b");
let res = list.get(6);
expect(res).assertEqual(undefined);
});
/**
* @tc.number: TEST_GET_004
* @tc.name : testGet004
* @tc.desc : Gets the element corresponding to the specified index. For example: list.get(1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGet004", 0, function () {
let list = new List();
let res = list.get(1);
expect(res).assertEqual(undefined);
});
/**
* @tc.number: TEST_GET_005
* @tc.name : testGet005
* @tc.desc : Gets the element corresponding to the specified index. For example: list.get.bind({}, 1)().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGet005", 0, function () {
let list = new List();
try {
list.get.bind({}, 1)();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The get method cannot be bound`);
}
});
/**
* @tc.number: TEST_HAS_001
* @tc.name : testHas001
* @tc.desc : Check whether the List contains a specified element. For example: list.has("a").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testHas001", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
let res = list.has("a");
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_HAS_002
* @tc.name : testHas002
* @tc.desc : Check whether the List contains a specified element. For example: list.has("d").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testHas002", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
let res = list.has("d");
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_HAS_003
* @tc.name : testHas003
* @tc.desc : Check whether the List contains a specified element. For example: list.has(1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testHas003", 0, function () {
let list = new List();
let res = list.has(1);
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_GET_INDEX_OF_001
* @tc.name : testGetIndexOf001
* @tc.desc : In the List instance, find the index of a specified element from front to back,
* and return the index found for the first time. If not found, return -1. For example: list.getIndexOf("b").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetIndexOf001", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list.add("b");
let res = list.getIndexOf("b");
expect(res).assertEqual(1);
});
/**
* @tc.number: TEST_GET_INDEX_OF_002
* @tc.name : testGetIndexOf002
* @tc.desc : In the List instance, find the index of a specified element from front to back,
* and return the index found for the first time. If not found, return -1. For example: list.getIndexOf("b").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetIndexOf002", 0, function () {
let list = new List();
let res = list.getIndexOf(1);
expect(res).assertEqual(-1);
});
/**
* @tc.number: TEST_REMOVE_BY_INDEX_001
* @tc.name : testRemoveByIndex001
* @tc.desc : In the List instance, delete the element based on its index. For example: list.removeByIndex(2).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemoveByIndex001", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list.removeByIndex(2);
let arr = [];
list.forEach((item, index) => {
arr.push(item);
});
let a = ["a", "b", "a", "b"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_REMOVE_BY_INDEX_002
* @tc.name : testRemoveByIndex002
* @tc.desc : In the List instance, delete the element based on its index. For example: list.removeByIndex(5).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemoveByIndex002", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
try {
let res = list.removeByIndex(5);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "index" is out of range. It must be >= 0 && <= 4. Received value is: 5`);
}
});
/**
* @tc.number: TEST_REMOVE_BY_INDEX_003
* @tc.name : testRemoveByIndex003
* @tc.desc : In the List instance, delete the element based on its index. For example: list.removeByIndex(1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemoveByIndex003", 0, function () {
let list = new List();
try {
let res = list.removeByIndex(1);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "index" is out of range. It must be >= 0 && <= 0. Received value is: 1`);
}
});
/**
* @tc.number: TEST_REMOVE_001
* @tc.name : testRemove001
* @tc.desc : Delete the specified element. For example: list.remove("a").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testRemove001", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.remove("a");
let arr = [];
list.forEach((item, index) => {
arr.push(item);
});
let a = ["b", "c", "a", "b"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_GET_LAST_INDEX_OF_001
* @tc.name : testGetLastIndexOf001
* @tc.desc : In the List instance, find the index of a specified element from brack to front,
* and return the index found for the first time. If not found, return -1. For example: list.getLastIndexOf("a").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetLastIndexOf001", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list.add("b");
let res = list.getLastIndexOf("a");
expect(res).assertEqual(3);
});
/**
* @tc.number: TEST_GET_LAST_INDEX_OF_002
* @tc.name : testGetLastIndexOf002
* @tc.desc : In the List instance, find the index of a specified element from brack to front,
* and return the index found for the first time. If not found, return -1. For example: list.getLastIndexOf("F").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetLastIndexOf002", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list.add("b");
let res = list.getLastIndexOf("F");
expect(res).assertEqual(-1);
});
/**
* @tc.number: TEST_GET_FIRST_001
* @tc.name : testGetFirst001
* @tc.desc : Get the header element of the List instance. For example: list.getFirst().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetFirst001", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.getFirst();
expect(res).assertEqual("a");
});
/**
* @tc.number: TEST_GET_FIRST_001
* @tc.name : testGetFirst001
* @tc.desc : Get the header element of the List instance. For example: list.getFirst().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetFirst002", 0, function () {
let list = new List();
let res = list.getFirst();
expect(res).assertEqual(undefined);
});
/**
* @tc.number: TEST_GET_LAST_001
* @tc.name : testGetLast001
* @tc.desc : Get the end element of the List instance. For example: list.getLast().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetLast001", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.getLast();
expect(res).assertEqual("b");
});
/**
* @tc.number: TEST_GET_LAST_001
* @tc.name : testGetLast001
* @tc.desc : Get the end element of the List instance. For example: list.getLast().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetLast002", 0, function () {
let list = new List();
let res = list.getLast();
expect(res).assertEqual(undefined);
});
/**
* @tc.number: TEST_SET_001
* @tc.name : testSet001
* @tc.desc : Modify the element corresponding to the specified index. For example: list.set(2, "d").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSet001", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.set(2, "d");
let res1 = list.get(2);
expect(res1).assertEqual("d");
});
/**
* @tc.number: TEST_SET_002
* @tc.name : testSet002
* @tc.desc : Modify the element corresponding to the specified index. For example: list.set(6, "d").
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSet002", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
try {
list.set(6, "d");
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "index" is out of range. It must be >= 0 && <= 2. Received value is: 6`);
}
});
/**
* @tc.number: TEST_EQUAL_001
* @tc.name : testEqual001
* @tc.desc : Judge whether two List instances are equal. For example: let res = list.equal(list1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testEqual001", 0, function () {
let list = new List();
let list1 = new List();
list.add("a");
list.add("b");
list.add("c");
list1.add("a");
list1.add("b");
list1.add("d");
let res = list.equal(list1);
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_EQUAL_002
* @tc.name : testEqual002
* @tc.desc : Judge whether two List instances are equal. For example: let res = list.equal(list1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testEqual002", 0, function () {
let list = new List();
let list1 = new List();
list.add("a");
list.add("b");
list.add("c");
list1.add("a");
list1.add("b");
list1.add("c");
let res = list.equal(list1);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_EQUAL_003
* @tc.name : testEqual003
* @tc.desc : Judge whether two List instances are equal. For example: let res = list.equal(list1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testEqual003", 0, function () {
let list = new List();
let list1 = new List();
list.add("a");
list.add("b");
list.add("c");
list1.add("a");
list1.add("b");
let res = list.equal(list1);
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_EQUAL_004
* @tc.name : testEqual004
* @tc.desc : Judge whether two List instances are equal. For example: let res = list.equal(list1).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testEqual004", 0, function () {
let list = new List();
let list1 = new List();
let res = list.equal(list1);
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_FOR_EACH_001
* @tc.name : testForEach001
* @tc.desc : Traversing elements in an List instance. For example: list.forEach((item, index) => {arr.push(item);}).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testForEach001", 0, function () {
let list = new List();
let c = [1, 2, 3, 4];
list.add(8);
list.add("一");
list.add("二");
list.add(5);
list.add(c);
list.add(6);
list.add("三");
list.add("四");
let arr = [];
list.forEach((item, index) => {
arr.push(item);
});
let a = [8, "一", "二", 5, c, 6, "三", "四"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_FOR_EACH_002
* @tc.name : testForEach002
* @tc.desc : Traversing elements in an List instance. For example: list.forEach((item, index) => {num++;}).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testForEach002", 0, function () {
let list = new List();
let num = 0;
list.forEach((item, index) => {
num++;
});
expect(num).assertEqual(0);
});
/**
* @tc.number: TEST_FOR_EACH_003
* @tc.name : testForEach003
* @tc.desc : Traversing elements in an List instance. For example: list.forEach.bind({}, "a")().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it('testForEach003', 0, function () {
let list = new List();
try {
list.forEach.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The forEach method cannot be bound`);
}
});
/**
* @tc.number: TEST_SORT_001
* @tc.name : testSort001
* @tc.desc : Arrange the elements in the List instance in descending order. For example: list.sort((a, b) => a - b).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSort001", 0, function () {
let list = new List();
list.add(4);
list.add(3);
list.add(1);
list.add(2);
list.add(14);
list.sort((a:any, b:any) => a - b);
let arr = [];
list.forEach((item, index) => {
arr.push(item);
});
let a = [1, 2, 3, 4, 14];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_SORT_002
* @tc.name : testSort002
* @tc.desc : Arrange the elements in the List instance in descending order. For example: list.sort((a, b) => a - b).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSort002", 0, function () {
let list = new List();
list.add(";");
list.add("一");
list.add("a");
list.add("1");
list.add("2");
list.add("14");
list.sort((a:any, b:any) => a - b);
let arr = [];
list.forEach((item, index) => {
arr.push(item);
});
let a = [";", "一", "a", "1", "2", "14"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_SORT_003
* @tc.name : testSort003
* @tc.desc : Arrange the elements in the List instance in descending order. For example: list.sort((a, b) => a - b).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testSort003", 0, function () {
let list = new List();
list.sort((a:any, b:any) => a - b);
let res1 = list.length;
expect(res1).assertEqual(0);
});
/**
* @tc.number: TEST_CLEAR_001
* @tc.name : testClear001
* @tc.desc : Clear all elements in the List instance. For example: list.clear().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testClear001", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.clear();
let res = list.length;
expect(res).assertEqual(0);
});
/**
* @tc.number: TEST_CLEAR_002
* @tc.name : testClear002
* @tc.desc : Clear all elements in the List instance. For example: list.clear().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testClear002", 0, function () {
let list = new List();
list.clear();
let res1 = list.length;
expect(res1).assertEqual(0);
});
/**
* @tc.number: TEST_GET_SUBLIST_001
* @tc.name : testGetSubList001
* @tc.desc : Intercepts an element within the specified range, including the element with the
* starting index but not the element with the ending index. For example: list.getSubList(2, 4).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetSubList001", 0, function () {
let list = new List();
list.add(4);
list.add(3);
list.add(1);
list.add(2);
list.add(14);
let res = list.getSubList(2, 4);
let arr = [];
res.forEach((item, index) => {
arr.push(item);
});
let a = [1, 2];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_GET_SUBLIST_002
* @tc.name : testGetSubList002
* @tc.desc : Intercepts an element within the specified range, including the element with the
* starting index but not the element with the ending index. For example: list.getSubList(2, 8).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetSubList002", 0, function () {
let list = new List();
list.add("4");
list.add("3");
list.add("1");
list.add("2");
list.add("14");
try {
list.getSubList(2, 8);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "toIndex" is out of range. It must be >= 0 && <= 5. Received value is: 8`);
}
});
/**
* @tc.number: TEST_GET_SUBLIST_003
* @tc.name : testGetSubList003
* @tc.desc : Intercepts an element within the specified range, including the element with the
* starting index but not the element with the ending index. For example: list.getSubList(6, 8).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetSubList003", 0, function () {
let list = new List();
list.add("4");
list.add("3");
list.add("1");
list.add("2");
list.add("14");
try {
list.getSubList(6, 8);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "fromIndex" is out of range. It must be >= 0 && <= 4. Received value is: 6`);
}
});
/**
* @tc.number: TEST_GET_SUBLIST_004
* @tc.name : testGetSubList004
* @tc.desc : Intercepts an element within the specified range, including the element with the
* starting index but not the element with the ending index. For example: list.getSubList(6, 2).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testGetSubList004", 0, function () {
let list = new List();
list.add("4");
list.add("3");
list.add("1");
list.add("2");
list.add("14");
try {
list.getSubList(6, 2);
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual(`The value of "fromIndex" is out of range. It must be >= 0 && <= 1. Received value is: 6`);
}
});
/**
* @tc.number: TEST_REPLACE_ALL_ELEMENTS_001
* @tc.name : testReplaceAllElements001
* @tc.desc : Perform some operation on the elements in the List instance and return the List instance
* after the operation. For example: list.replaceAllElements((item, index) => {return (item = 2 * item);}).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testReplaceAllElements001", 0, function () {
let list = new List();
list.add(1);
list.add(2);
list.add(4);
list.add(5);
list.replaceAllElements((item:number, index) => {
return (item = 2 * item);
});
let arr = [];
list.forEach((item, index) => {
arr.push(item);
});
let a = [2, 4, 8, 10];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_REPLACE_ALL_ELEMENTS_002
* @tc.name : testReplaceAllElements002
* @tc.desc : Perform some operation on the elements in the List instance and return the List instance
* after the operation. For example: list.replaceAllElements((item, index) => {num++;}).
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testReplaceAllElements002", 0, function () {
let list = new List();
let num = 0;
list.replaceAllElements((item, index) => {
num++;
});
expect(num).assertEqual(0);
});
/**
* @tc.number: TEST_CONVERT_TO_ARRAY_001
* @tc.name : testConvertToArray001
* @tc.desc : Convert an List instance to an array. For example: list.convertToArray().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testConvertToArray001", 0, function () {
let list = new List();
list.add(4);
list.add(3);
list.add(1);
list.add(2);
list.add(14);
let res = list.convertToArray();
let a = [4, 3, 1, 2, 14];
for (let i = 0; i < a.length; i++) {
expect(res[i]).assertEqual(a[i]);
}
});
/**
* @tc.number: TEST_CONVERT_TO_ARRAY_002
* @tc.name : testConvertToArray002
* @tc.desc : Convert an List instance to an array. For example: list.convertToArray().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testConvertToArray002", 0, function () {
let list = new List();
const res = list.convertToArray();
expect(res.length).assertEqual(0);
});
/**
* @tc.number: TEST_IS_EMPTY_001
* @tc.name : testIsEmpty001
* @tc.desc : Determine whether the List instance is empty. For example: list.isEmpty().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIsEmpty001", 0, function () {
let list = new List();
list.add(8);
list.add("一");
list.add("二");
list.add(5);
let c = [1, 2, 3, 4];
list.add(c);
list.add(6);
list.add("三");
list.add("四");
let res = list.isEmpty();
expect(res).assertEqual(false);
});
/**
* @tc.number: TEST_IS_EMPTY_002
* @tc.name : testIsEmpty002
* @tc.desc : Determine whether the List instance is empty. For example: list.isEmpty().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIsEmpty002", 0, function () {
let list = new List();
let res = list.isEmpty();
expect(res).assertEqual(true);
});
/**
* @tc.number: TEST_IS_EMPTY_003
* @tc.name : testIsEmpty003
* @tc.desc : Determine whether the List instance is empty. For example: list.isEmpty.bind({}, "a")().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIsEmpty003", 0, function () {
let list = new List();
try {
list.isEmpty.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The isEmpty method cannot be bound`);
}
});
/**
* @tc.number: TEST_ITERATOR_001
* @tc.name : testIterator001
* @tc.desc : Iterates over all elements in an List instance. For example: List[Symbol.iterator]().
* @tc.size : MediumTest
* @tc.type : Method
* @tc.level : Level 2
*/
it("testIterator001", 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list.removeByIndex(2);
let arr = [];
let itr = list[Symbol.iterator]();
let tmp = undefined;
do {
tmp = itr.next().value;
arr.push(tmp);
} while (tmp != undefined);
let a = ["a", "b", "a", "b"];
for (let i = 0; i < a.length; i++) {
expect(arr[i]).assertEqual(a[i]);
}
});
})
}
\ No newline at end of file
{
"module": {
"name": "entry_test",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/TestAbility/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"exported": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册