diff --git a/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/ArrayList.test.js b/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/ArrayList.test.js index e993f04cc7d0c8f5c4cf5a983db1fc86fa258470..714a48b74dcc0e04c92585729c7152b68db62a00 100644 --- a/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/ArrayList.test.js +++ b/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/ArrayList.test.js @@ -20,22 +20,21 @@ describe("ArraylistTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Create an ArrayList instance. For example: let arrayList = new ArrayList(). - * @tc.author: wangyong */ it("testConstructor001", 0, function () { try { let arrayList = new ArrayList(); expect(arrayList != undefined).assertEqual(true); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("Cannot create new arrayList"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200012); + expect(err.message).assertEqual("The ArrayList's constructor cannot be directly invoked"); } }); /** * @tc.name: testAdd002 * @tc.desc: Add a string type element to the end of the ArrayList instance. For example: arrayList.add("四"). - * @tc.author: wangyong */ it("testAdd002", 0, function () { let arrayList = new ArrayList(); @@ -47,7 +46,6 @@ describe("ArraylistTest", function () { /** * @tc.name: testAdd003 * @tc.desc: Add a number type element to the end of the ArrayList instance. For example: arrayList.add(8). - * @tc.author: wangyong */ it("testAdd003", 0, function () { let arrayList = new ArrayList(); @@ -60,7 +58,6 @@ describe("ArraylistTest", function () { * @tc.name: testAdd004 * @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.author: wangyong */ it("testAdd004 ", 0, function () { let arrayList = new ArrayList(); @@ -74,7 +71,6 @@ describe("ArraylistTest", function () { * @tc.name: testAdd005 * @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.author: wangyong */ it("testAdd005 ", 0, function () { let arrayList = new ArrayList(); @@ -88,7 +84,6 @@ describe("ArraylistTest", function () { * @tc.name: testAdd006 * @tc.desc: Add a boolean type element to the end of the ArrayList instance. * For example: let a = true; arrayList.add(a). - * @tc.author: wangyong */ it("testAdd006 ", 0, function () { let arrayList = new ArrayList(); @@ -101,7 +96,6 @@ describe("ArraylistTest", function () { /** * @tc.name: testInsert007 * @tc.desc: Insert an element into the middle of the ArrayList instance. For example: arrayList.insert(8, 2). - * @tc.author: wangyong */ it("testInsert007", 0, function () { let arrayList = new ArrayList(); @@ -123,7 +117,6 @@ describe("ArraylistTest", function () { /** * @tc.name: testLength008 * @tc.desc: Get the number of elements contained in the ArrayList instance. For example: arrayList.length. - * @tc.author: wangyong */ it("testLength008", 0, function () { let arrayList = new ArrayList(); @@ -139,7 +132,6 @@ describe("ArraylistTest", function () { /** * @tc.name: testHas009 * @tc.desc: Check whether the ArrayList contains a specified element. For example: arrayList.has(8). - * @tc.author: wangyong */ it("testHas009", 0, function () { let arrayList = new ArrayList(); @@ -156,7 +148,6 @@ describe("ArraylistTest", function () { * @tc.name: testGetIndexOf010 * @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.author: wangyong */ it("testGetIndexOf010", 0, function () { let arrayList = new ArrayList(); @@ -173,7 +164,6 @@ describe("ArraylistTest", function () { * @tc.name: testRemoveByIndex011 * @tc.desc: In the ArrayList instance, delete the element based on its index. * For example: arrayList.removeByIndex(2). - * @tc.author: wangyong */ it("testRemoveByIndex011", 0, function () { let arrayList = new ArrayList(); @@ -195,7 +185,6 @@ describe("ArraylistTest", function () { /** * @tc.name: testRemove012 * @tc.desc: Delete the specified element . For example: arrayList.remove("三"). - * @tc.author: wangyong */ it("testRemove012", 0, function () { let arrayList = new ArrayList(); @@ -212,7 +201,6 @@ describe("ArraylistTest", function () { * @tc.name: testGetLastIndexOf013 * @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.author: wangyong */ it("testGetLastIndexOf013", 0, function () { let arrayList = new ArrayList(); @@ -230,7 +218,6 @@ describe("ArraylistTest", function () { * @tc.name: testRemoveByRange014 * @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.author: wangyong */ it("testRemoveByRange014", 0, function () { let arrayList = new ArrayList(); @@ -257,7 +244,6 @@ describe("ArraylistTest", function () { * @tc.name: testReplaceAllElements015 * @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.author: wangyong */ it("testReplaceAllElements015", 0, function () { let arrayList = new ArrayList(); @@ -283,7 +269,6 @@ describe("ArraylistTest", function () { * @tc.name: testForEach016 * @tc.desc: Traversing elements in an ArrayList instance. * For example: arrayList.forEach((item, index) => {arr.push(item);}). - * @tc.author: wangyong */ it("testForEach016", 0, function () { let arrayList = new ArrayList(); @@ -306,7 +291,6 @@ describe("ArraylistTest", function () { * @tc.name: testSubArrayList017 * @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.author: wangyong */ it("testSubArrayList017", 0, function () { let arrayList = new ArrayList(); @@ -329,7 +313,6 @@ describe("ArraylistTest", function () { /** * @tc.name: testClear018 * @tc.desc: Clear all elements in the ArrayList instance. For example: arrayList.clear(). - * @tc.author: wangyong */ it("testClear018", 0, function () { let arrayList = new ArrayList(); @@ -346,7 +329,6 @@ describe("ArraylistTest", function () { /** * @tc.name: testConvertToArray19 * @tc.desc: Convert an ArrayList instance to an array. For example: arrayList.convertToArray(). - * @tc.author: wangyong */ it("testConvertToArray19", 0, function () { let arrayList = new ArrayList(); @@ -365,7 +347,6 @@ describe("ArraylistTest", function () { /** * @tc.name: testClone020 * @tc.desc: Clone an ArrayList instance. For example: arrayList.clone(). - * @tc.author: wangyong */ it("testClone020", 0, function () { let arrayList = new ArrayList(); @@ -388,7 +369,6 @@ describe("ArraylistTest", function () { /** * @tc.name: testGetCapacity021 * @tc.desc: Get the capacity of ArrayList instance. For example: arrayList.getCapacity(). - * @tc.author: wangyong */ it("testGetCapacity021", 0, function () { let arrayList = new ArrayList(); @@ -405,7 +385,6 @@ describe("ArraylistTest", function () { * @tc.name: testGetCapacity022 * @tc.desc: Get the capacity of the ArrayList instance after capacity expansion. * For example: arrayList.getCapacity(). - * @tc.author: wangyong */ it("testGetCapacity022", 0, function () { let arrayList = new ArrayList(); @@ -429,7 +408,6 @@ describe("ArraylistTest", function () { * @tc.name: testIncreaseCapacityTo023 * @tc.desc: Expand the ArrayList instance capacity to the specified value. * For example: arrayList.increaseCapacityTo(8). - * @tc.author: wangyong */ it("testIncreaseCapacityTo023", 0, function () { let arrayList = new ArrayList(); @@ -447,7 +425,6 @@ describe("ArraylistTest", function () { * @tc.name: testTrimToCurrentLength024 * @tc.desc: Limit the ArrayList instance capacity to the length of the ArrayList instance. * For example: arrayList.trimToCurrentLength(). - * @tc.author: wangyong */ it("testTrimToCurrentLength024", 0, function () { let arrayList = new ArrayList(); @@ -465,7 +442,6 @@ describe("ArraylistTest", function () { * @tc.name: testIterator025 * @tc.desc: Iterates over all elements in an ArrayList instance. * For example: for (let item of arrayList) {arr.push(item);}. - * @tc.author: wangyong */ it("testIterator025", 0, function () { let arrayList = new ArrayList(); @@ -492,7 +468,6 @@ describe("ArraylistTest", function () { * @tc.name: testSort026 * @tc.desc: Arrange the elements in the ArrayList instance in descending order. * For example: arrayList.sort((a, b) => a - b). - * @tc.author: wangyong */ it("testSort026", 0, function () { let arrayList = new ArrayList(); @@ -516,7 +491,6 @@ describe("ArraylistTest", function () { * @tc.name: testInsert0027 * @tc.desc: Inserting an element with an index less than 0 will throw an exception. * For example: arrayList.insert(8, -1). - * @tc.author: wangyong */ it("testInsert0027", 0, function () { let arrayList = new ArrayList(); @@ -526,13 +500,11 @@ describe("ArraylistTest", function () { arrayList.add("a"); try { let res = arrayList.insert(8, -1); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - if (err.message != "the index is out-of-bounds") { - expect(err.message).assertEqual("ArrayList: set out-of-bounds"); - } else { - expect(err.message).assertEqual("the index is out-of-bounds"); - } + 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`); } }); @@ -540,7 +512,6 @@ describe("ArraylistTest", function () { * @tc.name: testInsert028 * @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.author: wangyong */ it("testInsert028", 0, function () { let arrayList = new ArrayList(); @@ -550,13 +521,11 @@ describe("ArraylistTest", function () { arrayList.add("a"); try { let res = arrayList.insert(8, 10); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - if (err.message != "the index is out-of-bounds") { - expect(err.message).assertEqual("ArrayList: set out-of-bounds"); - } else { - expect(err.message).assertEqual("the index is out-of-bounds"); - } + 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`); } }); @@ -564,7 +533,6 @@ describe("ArraylistTest", function () { * @tc.name: testInsert029 * @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.author: wangyong */ it("testInsert029", 0, function () { let arrayList = new ArrayList(); @@ -574,20 +542,17 @@ describe("ArraylistTest", function () { arrayList.add("a"); try { let res = arrayList.insert(8, 11); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - if (err.message != "the index is out-of-bounds") { - expect(err.message).assertEqual("ArrayList: set out-of-bounds"); - } else { - expect(err.message).assertEqual("the index is out-of-bounds"); - } + 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.name: testIsEmpty030 * @tc.desc: Determine whether the ArrayList instance is empty. For example: arrayList.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty030", 0, function () { let arrayList = new ArrayList(); @@ -604,7 +569,6 @@ describe("ArraylistTest", function () { /** * @tc.name: testIsEmpty031 * @tc.desc: Determine whether the ArrayList instance is empty. For example: arrayList.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty031", 0, function () { let arrayList = new ArrayList(); @@ -620,7 +584,6 @@ describe("ArraylistTest", function () { /** * @tc.name: testHas032 * @tc.desc: Check whether the ArrayList contains a specified element. For example: arrayList.has("二"). - * @tc.author: wangyong */ it("testHas032", 0, function () { let arrayList = new ArrayList(); @@ -637,7 +600,6 @@ describe("ArraylistTest", function () { * @tc.name: testGetIndexOf033 * @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.author: wangyong */ it("testGetIndexOf033", 0, function () { let arrayList = new ArrayList(); @@ -653,7 +615,6 @@ describe("ArraylistTest", function () { /** * @tc.name: testRemove034 * @tc.desc: Delete the specified element.For example: arrayList.remove("A"). - * @tc.author: wangyong */ it("testRemove034", 0, function () { let arrayList = new ArrayList(); @@ -669,7 +630,6 @@ describe("ArraylistTest", function () { * @tc.name: testRemove035 * @tc.desc: Delete the specified element. * For example: arrayList.forEach((item, index) => {if (item == 1) {arrayList.remove(item);}}). - * @tc.author: wangyong */ it("testRemove035", 0, function () { let arrayList = new ArrayList(); @@ -698,7 +658,6 @@ describe("ArraylistTest", function () { * @tc.name: testRemoveByIndex036 * @tc.desc: In the ArrayList instance, delete the element based on its index index. * For example: arrayList.removeByIndex(5). - * @tc.author: wangyong */ it("testRemoveByIndex036", 0, function () { let arrayList = new ArrayList(); @@ -709,20 +668,17 @@ describe("ArraylistTest", function () { arrayList.add("b"); try { let res = arrayList.removeByIndex(5); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - if (err.message != "the index is out-of-bounds") { - expect(err.message).assertEqual("removeByIndex is out-of-bounds"); - } else { - expect(err.message).assertEqual("the index is out-of-bounds"); - } + 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.name: testRemoveByRange037 * @tc.desc: Add a string element to the end of the ArrayList instance. For example: arrayList.add("四"). - * @tc.author: wangyong */ it("testRemoveByRange037", 0, function () { let arrayList = new ArrayList(); @@ -736,13 +692,11 @@ describe("ArraylistTest", function () { arrayList.add(1); try { let res = arrayList.removeByRange(3, 1); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - if (err.message != "the fromIndex cannot be less than or equal to toIndex") { - expect(err.message).assertEqual("fromIndex cannot be less than or equal to toIndex"); - } else { - expect(err.message).assertEqual("the fromIndex cannot be less than or equal to toIndex"); - } + 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`); } }); @@ -750,7 +704,6 @@ describe("ArraylistTest", function () { * @tc.name: testRemoveByRange038 * @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.author: wangyong */ it("testRemoveByRange038", 0, function () { let arrayList = new ArrayList(); @@ -761,21 +714,18 @@ describe("ArraylistTest", function () { arrayList.add(1); try { let res = arrayList.removeByRange(6, 8); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - if (err.message != "the fromIndex or the toIndex is out-of-bounds") { - expect(err.message).assertEqual("ArrayList: set out-of-bounds"); - } else { - expect(err.message).assertEqual("the fromIndex or the toIndex is out-of-bounds"); - } + 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.name: testRemoveByRange039 * @tc.desc: Deletes elements from a specified range, including elements at the start position and - * elements at the end position. For example: removeByRange(0, 9). - * @tc.author: wangyong + * elements at the end position. For example: removeByRange(0, 7). */ it("testRemoveByRange039", 0, function () { let arrayList = new ArrayList(); @@ -787,7 +737,7 @@ describe("ArraylistTest", function () { arrayList.add("b"); arrayList.add("c"); arrayList.add(1); - arrayList.removeByRange(0, 9); + arrayList.removeByRange(0, 8); let res = arrayList.length; let res1 = arrayList.getLastIndexOf(1); expect(res).assertEqual(0); @@ -798,7 +748,6 @@ describe("ArraylistTest", function () { * @tc.name: testSubArrayList040 * @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.author: wangyong */ it("testSubArrayList040", 0, function () { let arrayList = new ArrayList(); @@ -809,13 +758,11 @@ describe("ArraylistTest", function () { arrayList.add(14); try { let subArr = arrayList.subArrayList(4, 2); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - if (err.message != "the fromIndex cannot be less than or equal to toIndex") { - expect(err.message).assertEqual("fromIndex cannot be less than or equal to toIndex"); - } else { - expect(err.message).assertEqual("the fromIndex cannot be less than or equal to toIndex"); - } + 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`); } }); @@ -823,7 +770,6 @@ describe("ArraylistTest", function () { * @tc.name: testSubArrayList041 * @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.author: wangyong */ it("testSubArrayList041", 0, function () { let arrayList = new ArrayList(); @@ -832,7 +778,7 @@ describe("ArraylistTest", function () { arrayList.add(1); arrayList.add(2); arrayList.add(14); - let subArr = arrayList.subArrayList(0, 6); + let subArr = arrayList.subArrayList(0, 5); let arr = []; arrayList.forEach((item, index) => { arr.push(item); @@ -847,7 +793,6 @@ describe("ArraylistTest", function () { * @tc.name: testSubArrayList042 * @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.author: wangyong */ it("testSubArrayList042", 0, function () { let arrayList = new ArrayList(); @@ -858,13 +803,11 @@ describe("ArraylistTest", function () { arrayList.add(14); try { let subArr = arrayList.subArrayList(6, 9); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - if (err.message != "the fromIndex or the toIndex is out-of-bounds") { - expect(err.message).assertEqual("fromIndex or toIndex is out-of-bounds"); - } else { - expect(err.message).assertEqual("the fromIndex or the toIndex is out-of-bounds"); - } + 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`); } }); @@ -872,7 +815,6 @@ describe("ArraylistTest", function () { * @tc.name: testIncreaseCapacityTo043 * @tc.desc: Expand the ArrayList instance capacity to the specified value. * For example: arrayList.increaseCapacityTo(-1). - * @tc.author: wangyong */ it("testIncreaseCapacityTo043", 0, function () { let arrayList = new ArrayList(); @@ -890,7 +832,6 @@ describe("ArraylistTest", function () { * @tc.name: testIncreaseCapacityTo044 * @tc.desc: Expand the ArrayList instance capacity to the specified value. * For example: arrayList.increaseCapacityTo(). - * @tc.author: wangyong */ it("testIncreaseCapacityTo044", 0, function () { let arrayList = new ArrayList(); @@ -901,13 +842,11 @@ describe("ArraylistTest", function () { arrayList.add(14); try { let res = arrayList.increaseCapacityTo(); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("TypeError"); - if (err.message != "index is not integer") { - expect(err.message).assertEqual("newCapacity is not Integer"); - } else { - expect(err.message).assertEqual("index is not integer"); - } + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "newCapacity" must be number. Received value is: undefined`); } }); @@ -915,7 +854,6 @@ describe("ArraylistTest", function () { * @tc.name: testAdd045 * @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.author: wangyong */ it("testAdd045", 0, function () { let arrayList = new ArrayList(); @@ -932,7 +870,6 @@ describe("ArraylistTest", function () { * @tc.name: testAdd046 * @tc.desc: Add a symbol type element to the end of the ArrayList instance. * For example: let a = "*";arrayList.add(a). - * @tc.author: wangyong */ it("testAdd046", 0, function () { let arrayList = new ArrayList(); @@ -945,7 +882,6 @@ describe("ArraylistTest", function () { /** * @tc.name: testAdd047 * @tc.desc: Add a decimal type to the end of the ArrayList instance. For example: let a = "3.14";arrayList.add(a). - * @tc.author: wangyong */ it("testAdd047", 0, function () { let arrayList = new ArrayList(); @@ -959,7 +895,6 @@ describe("ArraylistTest", function () { * @tc.name: testAdd048 * @tc.desc: Add a null character element to the end of the ArrayList instance. * For example: let a = "";arrayList.add(a). - * @tc.author: wangyong */ it("testAdd048", 0, function () { let arrayList = new ArrayList(); @@ -973,7 +908,6 @@ describe("ArraylistTest", function () { * @tc.name: testSort049 * @tc.desc: Arrange the elements in the ArrayList instance in descending order. * For example: arrayList.sort((a, b) => a - b). - * @tc.author: wangyong */ it("testSort049", 0, function () { let arrayList = new ArrayList(); @@ -997,7 +931,6 @@ describe("ArraylistTest", function () { * @tc.name: testSort050 * @tc.desc: Arrange the elements in the ArrayList instance in descending order. * For example: arrayList.sort((a, b) => a - b). - * @tc.author: wangyong */ it("testSort050", 0, function () { let arrayList = new ArrayList(); @@ -1020,7 +953,6 @@ describe("ArraylistTest", function () { /** * @tc.name: testIterator051 * @tc.desc: Iterates over all elements in an ArrayList instance. For example: arrayList[Symbol.iterator](). - * @tc.author: wangyong */ it("testIterator051", 0, function () { let arrayList = new ArrayList(); @@ -1046,7 +978,6 @@ describe("ArraylistTest", function () { * @tc.name: testRemoveByRange052 * @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.author: wangyong */ it("testRemoveByRange052", 0, function () { let arrayList = new ArrayList(); @@ -1058,9 +989,131 @@ describe("ArraylistTest", function () { arrayList.add("b"); arrayList.add("c"); arrayList.add(1); - arrayList.removeByRange(0, 9); - let res = arrayList.length; - expect(res).assertEqual(0); + 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.name: testAdd053 + * @tc.desc: Add a boolean type element to the end of the ArrayList instance. + * For example: arrayList.add.bind({})(). + */ + it("testAdd053 ", 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.name: testInsert054 + * @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("a", -2). + */ + it("testInsert054", 0, function () { + let arrayList = new ArrayList(); + arrayList.add(1); + try { + let res = arrayList.insert("a", "b"); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: b`); + } + }); + + /** + * @tc.name: testRemoveByIndex055 + * @tc.desc: In the ArrayList instance, delete the element based on its index index. + * For example: arrayList.removeByIndex(-1). + */ + it("testRemoveByIndex055", 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("a"); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); + } + }); + + /** + * @tc.name: testRemoveByRange056 + * @tc.desc: Deletes elements from a specified range, including elements at the start position and + * elements at the end position. For example: arrayList.removeByRange(-3, 9). + */ + it("testRemoveByRange056", 0, function () { + let arrayList = new ArrayList(); + arrayList.add(1); + arrayList.add("a"); + try { + arrayList.removeByRange("a", 9); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "fromIndex" must be number. Received value is: a`); + } + }); + + /** + * @tc.name: testReplaceAllElements057 + * @tc.desc: Perform some operation on the elements in the ArrayList instance and return the ArrayList instance + * after the operation. For example: arrayList.replaceAllElements(123). + */ + it("testReplaceAllElements057", 0, function () { + let arrayList = new ArrayList(); + arrayList.add(4); + arrayList.add(3); + try { + arrayList.replaceAllElements(123); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "callbackfn" must be callable. Received value is: 123`); + } + }); + + /** + * @tc.name: testSubArrayList058 + * @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("a", 2). + */ + it("testSubArrayList058", 0, function () { + let arrayList = new ArrayList(); + arrayList.add(4); + arrayList.add(3); + arrayList.add(1); + arrayList.add(2); + arrayList.add(14); + try { + arrayList.subArrayList("a", 2); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "fromIndex" must be number. Received value is: a`); + } }); }); } diff --git a/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Deque.test.js b/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Deque.test.js index 7ff18587049b664af208078e95c6ad60a257ddc3..3c6af53fe53519cf4005679a1c1304a8630e47f7 100644 --- a/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Deque.test.js +++ b/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Deque.test.js @@ -20,21 +20,20 @@ describe("DequeTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Create an Deque instance. For example: let deque = new Deque(). - * @tc.author: wangyong */ it("testConstructor001", 0, function () { try { let deque = new Deque(); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("Cannot create new deque"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200012); + expect(err.message).assertEqual("The Deque's constructor cannot be directly invoked"); } }); /** * @tc.name: testInsertFront002 * @tc.desc: Add element to deque instance header. For example: deque.insertFront("一"). - * @tc.author: wangyong */ it("testInsertFront002", 0, function () { let deque = new Deque(); @@ -46,7 +45,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertFront003 * @tc.desc: Add element to deque instance header. For example: deque.insertFront(8). - * @tc.author: wangyong */ it("testInsertFront003", 0, function () { let deque = new Deque(); @@ -59,7 +57,6 @@ describe("DequeTest", function () { * @tc.name: testInsertFront004 * @tc.desc: Add element to deque instance header. * For example: let a = {name: "lala", age: "15"}; deque.insertFront(a). - * @tc.author: wangyong */ it("testInsertFront004", 0, function () { let deque = new Deque(); @@ -72,7 +69,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertFront005 * @tc.desc: Add element to deque instance header. For example: let a = [1, 2, 3, 4]; deque.insertFront(a). - * @tc.author: wangyong */ it("testInsertFront005", 0, function () { let deque = new Deque(); @@ -85,7 +81,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertEnd006 * @tc.desc: Add element to deque instance end. For example: deque.insertEnd(8). - * @tc.author: wangyong */ it("testInsertEnd006", 0, function () { let deque = new Deque(); @@ -97,7 +92,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertEnd007 * @tc.desc: Add element to deque instance end. For example: let a = ["a", "b", "c"];deque.insertEnd(a). - * @tc.author: wangyong */ it("testInsertEnd007", 0, function () { let deque = new Deque(); @@ -110,7 +104,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertEnd008 * @tc.desc: Add element to deque instance end. For example: let a = {class: "6班", say: "we"};deque.insertEnd(a). - * @tc.author: wangyong */ it("testInsertEnd008", 0, function () { let deque = new Deque(); @@ -123,7 +116,6 @@ describe("DequeTest", function () { /** * @tc.name: testGetFirst009 * @tc.desc: Get the header element of the deque instance. For example: deque.getFirst(). - * @tc.author: wangyong */ it("testGetFirst009", 0, function () { let deque = new Deque(); @@ -136,7 +128,6 @@ describe("DequeTest", function () { /** * @tc.name: testGetLast010 * @tc.desc: Get the end element of the deque instance. For example: deque.getLast(). - * @tc.author: wangyong */ it("testGetLast010", 0, function () { let deque = new Deque(); @@ -149,7 +140,6 @@ describe("DequeTest", function () { /** * @tc.name: testHas011 * @tc.desc: Determine whether the deque instance contains the specified element. For example: deque.has(6). - * @tc.author: wangyong */ it("testHas011", 0, function () { let deque = new Deque(); @@ -161,7 +151,6 @@ describe("DequeTest", function () { /** * @tc.name: testHas012 * @tc.desc: Determine whether the deque instance contains the specified element. For example: deque.has(6). - * @tc.author: wangyong */ it("testHas012", 0, function () { let deque = new Deque(); @@ -173,7 +162,6 @@ describe("DequeTest", function () { /** * @tc.name: testPopFirst013 * @tc.desc: Delete the header element of a deque instance. For example: deque.popFirst(). - * @tc.author: wangyong */ it("testPopFirst013", 0, function () { let deque = new Deque(); @@ -186,7 +174,6 @@ describe("DequeTest", function () { /** * @tc.name: testPopLast014 * @tc.desc: Delete the end element of a deque instance. For example: deque.popLast(). - * @tc.author: wangyong */ it("testPopLast014", 0, function () { let deque = new Deque(); @@ -200,7 +187,6 @@ describe("DequeTest", function () { /** * @tc.name: testForEach015 * @tc.desc: Traversing elements in deque instances. For example: deque.forEach((item, index) => {arr.push(item);}). - * @tc.author: wangyong */ it("testForEach015", 0, function () { let deque = new Deque(); @@ -228,7 +214,6 @@ describe("DequeTest", function () { /** * @tc.name: testIterator016 * @tc.desc: Iterate over all elements in the deque instance. For example: for (let item of deque) { arr.push(item);}. - * @tc.author: wangyong */ it("testIterator016", 0, function () { let deque = new Deque(); @@ -252,7 +237,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertFront017 * @tc.desc: Add element to deque instance header. For example: deque.insertFront("$"). - * @tc.author: wangyong */ it("testInsertFront017", 0, function () { let deque = new Deque(); @@ -264,7 +248,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertFront018 * @tc.desc: Add element to deque instance header. For example: deque.insertFront(" "). - * @tc.author: wangyong */ it("testInsertFront018", 0, function () { let deque = new Deque(); @@ -276,7 +259,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertFront019 * @tc.desc: Add element to deque instance header. For example: deque.insertFront(null). - * @tc.author: wangyong */ it("testInsertFront019", 0, function () { let deque = new Deque(); @@ -288,7 +270,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertFront020 * @tc.desc: Add element to deque instance header. For example: deque.insertFront(undefined). - * @tc.author: wangyong */ it("testInsertFront020", 0, function () { let deque = new Deque(); @@ -300,7 +281,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertFront021 * @tc.desc: Add element to deque instance header. For example: for (let i = 0; i < 100; i++) {deque.insertFront(i)}. - * @tc.author: wangyong */ it("testInsertFront021", 0, function () { let deque = new Deque(); @@ -316,7 +296,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertEnd022 * @tc.desc: Add element to deque instance end. For example: deque.insertEnd("$"). - * @tc.author: wangyong */ it("testInsertEnd022", 0, function () { let deque = new Deque(); @@ -328,7 +307,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertEnd023 * @tc.desc: Add element to deque instance end. For example: deque.insertEnd(" "). - * @tc.author: wangyong */ it("testInsertEnd023", 0, function () { let deque = new Deque(); @@ -340,7 +318,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertEnd024 * @tc.desc: Add element to deque instance end. For example: deque.insertEnd(null). - * @tc.author: wangyong */ it("testInsertEnd024", 0, function () { let deque = new Deque(); @@ -352,7 +329,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertEnd025 * @tc.desc: Add element to deque instance end. For example: deque.insertEnd(undefined). - * @tc.author: wangyong */ it("testInsertEnd025", 0, function () { let deque = new Deque(); @@ -364,7 +340,6 @@ describe("DequeTest", function () { /** * @tc.name: testInsertFront026 * @tc.desc: Add element to deque instance end. For example: for (let i = 0; i < 100; i++) {deque.insertEnd(i);}. - * @tc.author: wangyong */ it("testInsertFront026", 0, function () { let deque = new Deque(); @@ -380,7 +355,6 @@ describe("DequeTest", function () { /** * @tc.name: testHas027 * @tc.desc: Determine whether the deque instance contains the specified element. For example: deque.has(6). - * @tc.author: wangyong */ it("testHas027", 0, function () { let deque = new Deque(); @@ -391,7 +365,6 @@ describe("DequeTest", function () { /** * @tc.name: testPopFirst028 * @tc.desc: Delete the header element of a deque instance. For example: deque.popFirst(). - * @tc.author: wangyong */ it("testPopFirst028", 0, function () { let deque = new Deque(); @@ -402,7 +375,6 @@ describe("DequeTest", function () { /** * @tc.name: testGetFirst029 * @tc.desc: Get the header element of the deque instance. For example: deque.getFirst(). - * @tc.author: wangyong */ it("testGetFirst029", 0, function () { let deque = new Deque(); @@ -413,7 +385,6 @@ describe("DequeTest", function () { /** * @tc.name: testPopLast030 * @tc.desc: Delete the end element of a deque instance. For example: deque.popLast(). - * @tc.author: wangyong */ it("testPopLast030", 0, function () { let deque = new Deque(); @@ -424,7 +395,6 @@ describe("DequeTest", function () { /** * @tc.name: testGetLast031 * @tc.desc: Get the end element of the deque instance. For example: deque.getLast(). - * @tc.author: wangyong */ it("testGetLast031", 0, function () { let deque = new Deque(); @@ -435,7 +405,6 @@ describe("DequeTest", function () { /** * @tc.name: testForEach032 * @tc.desc: Traversing elements in deque instances. For example: deque.forEach((item, index) => {arr.push(item);}). - * @tc.author: wangyong */ it("testForEach032", 0, function () { let deque = new Deque(); @@ -464,7 +433,6 @@ describe("DequeTest", function () { /** * @tc.name: testIterator033 * @tc.desc: Iterate over all elements in the deque instance. For example: for (let item of deque) { arr.push(item);}. - * @tc.author: wangyong */ it("testIterator033", 0, function () { let deque = new Deque(); @@ -492,7 +460,6 @@ describe("DequeTest", function () { /** * @tc.name: testIterator034 * @tc.desc: Iterate over all elements in the deque instance. For example: deque[Symbol.iterator](). - * @tc.author: wangyong */ it("testIterator034", 0, function () { let deque = new Deque(); @@ -522,7 +489,6 @@ describe("DequeTest", function () { /** * @tc.name: testLength035 * @tc.desc: Get the number of elements in the deque instance. For example: deque.length. - * @tc.author: wangyong */ it("testLength035", 0, function () { let deque = new Deque(); @@ -540,5 +506,37 @@ describe("DequeTest", function () { let size = deque.length; expect(size).assertEqual(7); }); + + /** + * @tc.name: testInsertFront036 + * @tc.desc: Add element to deque instance header.For example: let a = [1, 2, 3, 4]; deque.insertFront.bind({}, "a")(). + */ + it("testInsertFront036 ", 0, function () { + let deque = new Deque(); + try { + deque.insertFront.bind({}, "a")(); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200011); + expect(err.message).assertEqual(`The insertFront method cannot be bound`); + } + }); + + /** + * @tc.name: testForEach037 + * @tc.desc: Traversing elements in deque instances. For example: deque.forEach(123). + */ + it("testForEach037", 0, function () { + let deque = new Deque(); + try { + deque.forEach(123); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "callbackfn" must be callable. Received value is: 123`); + } + }); }); } diff --git a/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/LinkedList.test.js b/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/LinkedList.test.js index ae6be868ff1b944b66808f83cedd1fc0b2a92256..c4d1360ea50f9ee9059b006ee014a0f45b834b8c 100644 --- a/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/LinkedList.test.js +++ b/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/LinkedList.test.js @@ -20,21 +20,20 @@ describe("LinkedListTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Create an LinkedList instance. For example: let linkedList = new LinkedList(). - * @tc.author: wangyong */ it("testConstructor001", 0, function () { try { let linkedList = new LinkedList(); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("Cannot create new linkedList"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200012); + expect(err.message).assertEqual("The LinkedList's constructor cannot be directly invoked"); } }); /** * @tc.name: testAdd002 * @tc.desc: Add a element to the end of the LinkedList instance. For example: linkedList.add("四"). - * @tc.author: wangyong */ it("testAdd002", 0, function () { let linkedList = new LinkedList(); @@ -46,7 +45,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testAdd003 * @tc.desc: Add a element to the end of the LinkedList instance. For example: linkedList.add(8). - * @tc.author: wangyong */ it("testAdd003", 0, function () { let linkedList = new LinkedList(); @@ -59,7 +57,6 @@ describe("LinkedListTest", function () { * @tc.name: testAdd004 * @tc.desc: Add a element to the end of the LinkedList instance. * For example: let a = [1, 2, 3, 4];linkedList.add(a). - * @tc.author: wangyong */ it("testAdd004", 0, function () { let linkedList = new LinkedList(); @@ -73,7 +70,6 @@ describe("LinkedListTest", function () { * @tc.name: testAdd005 * @tc.desc: Add a element to the end of the LinkedList instance. * For example: let a = {name: "lala", age: "13"};linkedList.add(a). - * @tc.author: wangyong */ it("testAdd005", 0, function () { let linkedList = new LinkedList(); @@ -86,7 +82,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testAdd006 * @tc.desc: Add a element to the end of the LinkedList instance. For example: let a = ".";linkedList.add(a). - * @tc.author: wangyong */ it("testAdd006", 0, function () { let linkedList = new LinkedList(); @@ -99,7 +94,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testAdd007 * @tc.desc: Add a element to the end of the LinkedList instance. For example: let a = "*";linkedList.add(a). - * @tc.author: wangyong */ it("testAdd007", 0, function () { let linkedList = new LinkedList(); @@ -112,7 +106,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testAdd008 * @tc.desc: Add a element to the end of the LinkedList instance. For example: let a = "/";linkedList.add(a). - * @tc.author: wangyong */ it("testAdd008", 0, function () { let linkedList = new LinkedList(); @@ -125,7 +118,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testAdd009 * @tc.desc: Add a element to the end of the LinkedList instance. For example: let a = "";linkedList.add(a). - * @tc.author: wangyong */ it("testAdd009", 0, function () { let linkedList = new LinkedList(); @@ -138,7 +130,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testAdd010 * @tc.desc: Add a element to the end of the LinkedList instance. For example: let a = "a";linkedList.add(a). - * @tc.author: wangyong */ it("testAdd010", 0, function () { let linkedList = new LinkedList(); @@ -154,7 +145,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testHas011 * @tc.desc: Check whether the LinkedList contains a specified element. For example: linkedList.has("a"). - * @tc.author: wangyong */ it("testHas011", 0, function () { let linkedList = new LinkedList(); @@ -170,7 +160,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testClone012 * @tc.desc: Clone an LinkedList instance. For example: linkedList.clone(). - * @tc.author: wangyong */ it("testClone012", 0, function () { let linkedList = new LinkedList(); @@ -194,7 +183,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testAddFirst013 * @tc.desc: Add element to LinkedList instance header. For example: linkedList.addFirst("e"). - * @tc.author: wangyong */ it("testAddFirst013", 0, function () { let linkedList = new LinkedList(); @@ -209,7 +197,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testRemoveFirst014 * @tc.desc: Delete the header element of a LinkedList instance. For example: linkedList.removeFirst(). - * @tc.author: wangyong */ it("testRemoveFirst014", 0, function () { let linkedList = new LinkedList(); @@ -233,7 +220,6 @@ describe("LinkedListTest", function () { * @tc.desc: In the LinkedList 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: linkedList.getLastIndexOf("a"). - * @tc.author: wangyong */ it("testGetLastIndexOf015", 0, function () { let linkedList = new LinkedList(); @@ -252,7 +238,6 @@ describe("LinkedListTest", function () { * @tc.desc: In the LinkedList 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: linkedList.getLastIndexOf("f"). - * @tc.author: wangyong */ it("testGetLastIndexOf016", 0, function () { let linkedList = new LinkedList(); @@ -271,7 +256,6 @@ describe("LinkedListTest", function () { * @tc.desc: In the LinkedList 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: linkedList.getIndexOf("b"). - * @tc.author: wangyong */ it("testGetIndexOf017", 0, function () { let linkedList = new LinkedList(); @@ -290,7 +274,6 @@ describe("LinkedListTest", function () { * @tc.desc: In the LinkedList 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: linkedList.getIndexOf("f"). - * @tc.author: wangyong */ it("testGetIndexOf018", 0, function () { let linkedList = new LinkedList(); @@ -308,7 +291,6 @@ describe("LinkedListTest", function () { * @tc.name: testRemoveByIndex019 * @tc.desc: In the linkedList instance, delete the element based on its index. * For example: linkedList.removeByIndex(2). - * @tc.author: wangyong */ it("testRemoveByIndex019", 0, function () { let linkedList = new LinkedList(); @@ -332,7 +314,6 @@ describe("LinkedListTest", function () { * @tc.name: testRemoveByIndex020 * @tc.desc: In the linkedList instance, delete the element based on its subscript index. * For example: linkedList.removeByIndex(10). - * @tc.author: wangyong */ it("testRemoveByIndex020", 0, function () { let linkedList = new LinkedList(); @@ -343,16 +324,17 @@ describe("LinkedListTest", function () { linkedList.add("b"); try { let res = linkedList.removeByIndex(10); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - expect(err.message).assertEqual("the index is out-of-bounds"); + 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.name: testRemove021 * @tc.desc: Delete the specified element. For example: linkedList.remove("a"). - * @tc.author: wangyong */ it("testRemove021", 0, function () { let linkedList = new LinkedList(); @@ -375,7 +357,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testRemove022 * @tc.desc: Delete the specified element. For example: linkedList.remove("d"). - * @tc.author: wangyong */ it("testRemove022", 0, function () { let linkedList = new LinkedList(); @@ -391,7 +372,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testRemove023 * @tc.desc: Delete the specified element. For example: linkedList.remove("d"). - * @tc.author: wangyong */ it("testRemove023", 0, function () { let linkedList = new LinkedList(); @@ -402,7 +382,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testRemoveFirstFound024 * @tc.desc: Delete the specified element found for the first time. For example: linkedList.removeFirstFound("b"). - * @tc.author: wangyong */ it("testRemoveFirstFound024", 0, function () { let linkedList = new LinkedList(); @@ -425,7 +404,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testRemoveLastFound025 * @tc.desc: Delete the specified element found for the last time. For example: linkedList.removeLastFound("b"). - * @tc.author: wangyong */ it("testRemoveLastFound025", 0, function () { let linkedList = new LinkedList(); @@ -448,7 +426,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testGetFirst026 * @tc.desc: Get the header element of the linkedList instance. For example: linkedList.getFirst(). - * @tc.author: wangyong */ it("testGetFirst026", 0, function () { let linkedList = new LinkedList(); @@ -464,7 +441,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testGetLast027 * @tc.desc: Get the end element of the linkedList instance. For example: linkedList.getLast(). - * @tc.author: wangyong */ it("testGetLast027", 0, function () { let linkedList = new LinkedList(); @@ -480,7 +456,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testInsert028 * @tc.desc: Insert an element into the middle of the LinkedList instance. For example: linkedList.insert(3, "d"). - * @tc.author: wangyong */ it("testInsert028", 0, function () { let linkedList = new LinkedList(); @@ -503,7 +478,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testInsert029 * @tc.desc: Insert an element into the middle of the LinkedList instance. For example: linkedList.insert(0, "d"). - * @tc.author: wangyong */ it("testInsert029", 0, function () { let linkedList = new LinkedList(); @@ -526,7 +500,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testInsert030 * @tc.desc: Insert an element into the middle of the LinkedList instance. For example: linkedList.insert(5, "d"). - * @tc.author: wangyong */ it("testInsert030", 0, function () { let linkedList = new LinkedList(); @@ -549,7 +522,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testInsert031 * @tc.desc: Insert an element into the middle of the LinkedList instance. For example: linkedList.insert(9, "d"). - * @tc.author: wangyong */ it("testInsert031", 0, function () { let linkedList = new LinkedList(); @@ -560,16 +532,17 @@ describe("LinkedListTest", function () { linkedList.add("b"); try { let res = linkedList.insert(8, "d"); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - expect(err.message).assertEqual("the index is out-of-bounds"); + 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.name: testSet032 * @tc.desc: Modify the element corresponding to the specified index. For example: linkedList.set(2, "d"). - * @tc.author: wangyong */ it("testSet032", 0, function () { let linkedList = new LinkedList(); @@ -585,7 +558,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testConvertToArray033 * @tc.desc: Convert an LinkedList instance to an array. For example: linkedList.convertToArray(). - * @tc.author: wangyong */ it("testConvertToArray033", 0, function () { let linkedList = new LinkedList(); @@ -604,7 +576,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testLength034 * @tc.desc: Get the number of elements in the LinkedList instance. For example: linkedList.length. - * @tc.author: wangyong */ it("testLength034", 0, function () { let linkedList = new LinkedList(); @@ -620,7 +591,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testClear035 * @tc.desc: Clear all elements in the linkedList instance. For example: linkedList.clear(). - * @tc.author: wangyong */ it("testClear035", 0, function () { let linkedList = new LinkedList(); @@ -638,7 +608,6 @@ describe("LinkedListTest", function () { * @tc.name: testIterator036 * @tc.desc: Iterates over all elements in an LinkedList instance. * For example: for (let item of linkedList) {arr.push(item);}. - * @tc.author: wangyong */ it("testIterator036", 0, function () { let linkedList = new LinkedList(); @@ -665,7 +634,6 @@ describe("LinkedListTest", function () { * @tc.name: testForEach037 * @tc.desc: Traversing elements in an LinkedList instance. * For example: linkedList.forEach((item, index) => {arr.push(item);}). - * @tc.author: wangyong */ it("testForEach037", 0, function () { let linkedList = new LinkedList(); @@ -691,7 +659,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testRemoveLast038 * @tc.desc: Delete the end element of a LinkedList instance. linkedList.removeLast(). - * @tc.author: wangyong */ it("testRemoveLast038", 0, function () { let linkedList = new LinkedList(); @@ -714,7 +681,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testGet039 * @tc.desc: Gets the element corresponding to the specified index. For example: linkedList.get(1). - * @tc.author: wangyong */ it("testGet039", 0, function () { let linkedList = new LinkedList(); @@ -730,7 +696,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testGet040 * @tc.desc: Gets the element corresponding to the specified index. For example: linkedList.get(10). - * @tc.author: wangyong */ it("testGet040", 0, function () { let linkedList = new LinkedList(); @@ -746,7 +711,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testListGet041 * @tc.desc: Gets the element corresponding to the specified index. For example: linkedList[1]. - * @tc.author: wangyong */ it("testListGet041", 0, function () { let linkedList = new LinkedList(); @@ -765,7 +729,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testListSet042 * @tc.desc: Modify the element corresponding to the specified index. For example: linkedList[1] = "f". - * @tc.author: wangyong */ it("testListSet042", 0, function () { let linkedList = new LinkedList(); @@ -786,7 +749,6 @@ describe("LinkedListTest", function () { * @tc.name: testAdd043 * @tc.desc: Add a element to the end of the LinkedList instance. * For example: for (let i = 0; i < 100; i++) {linkedList.add(i);}. - * @tc.author: wangyong */ it("testAdd043", 0, function () { let linkedList = new LinkedList(); @@ -801,22 +763,22 @@ describe("LinkedListTest", function () { * @tc.name: testRemoveByIndex044 * @tc.desc: In the linkedList instance, delete the element based on its subscript index. * For example: linkedList.removeByIndex(1). - * @tc.author: wangyong */ it("testRemoveByIndex044", 0, function () { let linkedList = new LinkedList(); try { let res = linkedList.removeByIndex(1); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - expect(err.message).assertEqual("the index is out-of-bounds"); + 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.name: testClone045 * @tc.desc: Clone an LinkedList instance. For example: linkedList.clone(). - * @tc.author: wangyong */ it("testClone045", 0, function () { let linkedList = new LinkedList(); @@ -834,7 +796,6 @@ describe("LinkedListTest", function () { * @tc.name: testGetIndexOf046 * @tc.desc: In the LinkedList 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: linkedList.getIndexOf(1). - * @tc.author: wangyong */ it("testGetIndexOf046", 0, function () { let linkedList = new LinkedList(); @@ -846,7 +807,6 @@ describe("LinkedListTest", function () { * @tc.name: testForEach047 * @tc.desc: Traversing elements in an LinkedList instance. * For example: linkedList.forEach((item, index) => { num++; }). - * @tc.author: wangyong */ it("testForEach047", 0, function () { let linkedList = new LinkedList(); @@ -860,7 +820,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testHas048 * @tc.desc: Check whether the LinkedList contains a specified element. For example: linkedList.has(1). - * @tc.author: wangyong */ it("testHas048", 0, function () { let linkedList = new LinkedList(); @@ -871,7 +830,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testGet050 * @tc.desc: Gets the element corresponding to the specified index. For example: linkedList.get(1). - * @tc.author: wangyong */ it("testGet050", 0, function () { let linkedList = new LinkedList(); @@ -882,7 +840,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testClear051 * @tc.desc: Clear all elements in the LinkedList instance. For example: linkedList.clear(). - * @tc.author: wangyong */ it("testClear051", 0, function () { let linkedList = new LinkedList(); @@ -894,7 +851,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testGetLast052 * @tc.desc: Get the end element of the linkedList instance. For example: linkedList.getLast(). - * @tc.author: wangyong */ it("testGetLast052", 0, function () { let linkedList = new LinkedList(); @@ -905,7 +861,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testGetFirst053 * @tc.desc: Get the header element of the linkedList instance. For example: linkedList.getFirst(). - * @tc.author: wangyong */ it("testGetFirst053", 0, function () { let linkedList = new LinkedList(); @@ -916,7 +871,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testAdd054 * @tc.desc: Add a element to the end of the LinkedList instance. For example: linkedList.add(null). - * @tc.author: wangyong */ it("testAdd054", 0, function () { let linkedList = new LinkedList(); @@ -928,7 +882,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testAdd055 * @tc.desc: Add a element to the end of the LinkedList instance. For example: linkedList.add(0.1). - * @tc.author: wangyong */ it("testAdd055", 0, function () { let linkedList = new LinkedList(); @@ -940,7 +893,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testAdd056 * @tc.desc: Add a element to the end of the LinkedList instance. For example: linkedList.add(-1). - * @tc.author: wangyong */ it("testAdd056", 0, function () { let linkedList = new LinkedList(); @@ -952,7 +904,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testAdd057 * @tc.desc: Add a element to the end of the LinkedList instance. For example: const obj = {}; linkedList.add(obj). - * @tc.author: wangyong */ it("testAdd057", 0, function () { let linkedList = new LinkedList(); @@ -965,7 +916,6 @@ describe("LinkedListTest", function () { /** * @tc.name: testIterator058 * @tc.desc: Iterates over all elements in an LinkedList instance. For example: linkedList[Symbol.iterator](). - * @tc.author: wangyong */ it("testIterator058", 0, function () { let linkedList = new LinkedList(); @@ -987,5 +937,161 @@ describe("LinkedListTest", function () { expect(arr[i]).assertEqual(a[i]); } }); + + /** + * @tc.name: testAdd057 + * @tc.desc: Add a element to the end of the LinkedList instance. For example: linkedList.add.bind({}, obj)(). + */ + it("testAdd059 ", 0, function () { + let linkedList = new LinkedList(); + try { + linkedList.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.name: testInsert058 + * @tc.desc: Insert an element into the middle of the LinkedList instance. For example: linkedList.insert("a", "d"). + */ + it("testInsert058", 0, function () { + let linkedList = new LinkedList(); + linkedList.add("a"); + linkedList.add("b"); + linkedList.add("c"); + try { + linkedList.insert("a", "d"); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); + } + }); + + /** + * @tc.name: testGet059 + * @tc.desc: Gets the element corresponding to the specified index. For example: linkedList.get("a"). + */ + it("testGet059", 0, function () { + let linkedList = new LinkedList(); + try { + linkedList.get("a"); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); + } + }); + + /** + * @tc.name: testRemoveFirst060 + * @tc.desc: Delete the header element of a LinkedList instance. For example: linkedList.removeFirst(). + */ + it("testRemoveFirst060", 0, function () { + let linkedList = new LinkedList(); + try { + linkedList.removeFirst(); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200010); + expect(err.message).assertEqual(`Container is empty`); + } + }); + + /** + * @tc.name: testRemoveLast061 + * @tc.desc: Delete the end element of a LinkedList instance. linkedList.removeLast(). + */ + it("testRemoveLast061", 0, function () { + let linkedList = new LinkedList(); + try { + linkedList.removeLast(); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200010); + expect(err.message).assertEqual(`Container is empty`); + } + }); + + /** + * @tc.name: testRemoveByIndex062 + * @tc.desc: In the linkedList instance, delete the element based on its subscript index. + * For example: linkedList.removeByIndex("a"). + */ + it("testRemoveByIndex062", 0, function () { + let linkedList = new LinkedList(); + linkedList.add("a"); + linkedList.add("b"); + linkedList.add("c"); + try { + linkedList.removeByIndex("a"); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); + } + }); + + /** + * @tc.name: testRemoveFirstFound063 + * @tc.desc: Delete the specified element found for the first time. For example: linkedList.removeFirstFound("b"). + */ + it("testRemoveFirstFound063", 0, function () { + let linkedList = new LinkedList(); + try { + linkedList.removeFirstFound("b"); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200010); + expect(err.message).assertEqual(`Container is empty`); + } + }); + + /** + * @tc.name: testSet064 + * @tc.desc: Modify the element corresponding to the specified index. For example: linkedList.set(6, "d"). + */ + it("testSet064", 0, function () { + let linkedList = new LinkedList(); + linkedList.add("a"); + linkedList.add("b"); + linkedList.add("c"); + linkedList.add("a"); + try { + linkedList.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 && <= 3. Received value is: 6`); + } + }); + + /** + * @tc.name: testSet065 + * @tc.desc: Modify the element corresponding to the specified index. For example: linkedList.set("a", "d"). + */ + it("testSet065", 0, function () { + let linkedList = new LinkedList(); + linkedList.add("a"); + try { + linkedList.set("a", "d"); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); + } + }); }); } diff --git a/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/List.test.js b/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/List.test.js index b0fc85c13475a0afbab496b08100c93bc08d11ce..1129c445c452412373b399ca545f7321ae8e480d 100644 --- a/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/List.test.js +++ b/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/List.test.js @@ -20,22 +20,21 @@ describe("ListTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Create an List instance. For example: let list = new List(). - * @tc.author: wangyong */ it("testConstructor001", 0, function () { try { let list = new List(); expect(list != undefined).assertEqual(true); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("cannot create new list"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200012); + expect(err.message).assertEqual("The List's constructor cannot be directly invoked"); } }); /** * @tc.name: testGet002 * @tc.desc: Gets the element corresponding to the specified index. For example: list.get(0). - * @tc.author: wangyong */ it("testGet002", 0, function () { let list = new List(); @@ -47,7 +46,6 @@ describe("ListTest", function () { /** * @tc.name: testAdd003 * @tc.desc: Add a element to the end of the List instance. For example: list.add(8). - * @tc.author: wangyong */ it("testAdd003", 0, function () { let list = new List(); @@ -60,7 +58,6 @@ describe("ListTest", function () { * @tc.name: testAdd004 * @tc.desc: Add a element to the end of the List instance. * For example: let a = [1, 2, 3, 4]; list.add(a). - * @tc.author: wangyong */ it("testAdd004", 0, function () { let list = new List(); @@ -74,7 +71,6 @@ describe("ListTest", function () { * @tc.name: testAdd005 * @tc.desc: Add a element to the end of the List instance. * For example: let a = {name: "lala", age: "13"}; list.add(a). - * @tc.author: wangyong */ it("testAdd005", 0, function () { let list = new List(); @@ -87,7 +83,6 @@ describe("ListTest", function () { /** * @tc.name: testHas006 * @tc.desc: Check whether the List contains a specified element. For example: list.has("a"). - * @tc.author: wangyong */ it("testHas006", 0, function () { let list = new List(); @@ -101,7 +96,6 @@ describe("ListTest", function () { /** * @tc.name: testHas007 * @tc.desc: Check whether the List contains a specified element. For example: list.has("d"). - * @tc.author: wangyong */ it("testHas007", 0, function () { let list = new List(); @@ -115,7 +109,6 @@ describe("ListTest", function () { /** * @tc.name: testEqual008 * @tc.desc: Judge whether two List instances are equal. For example: let res = list.equal(list1). - * @tc.author: wangyong */ it("testEqual008", 0, function () { let list = new List(); @@ -133,7 +126,6 @@ describe("ListTest", function () { /** * @tc.name: testEqual009 * @tc.desc: Judge whether two List instances are equal. For example: let res = list.equal(list1). - * @tc.author: wangyong */ it("testEqual009", 0, function () { let list = new List(); @@ -151,7 +143,6 @@ describe("ListTest", function () { /** * @tc.name: testEqual010 * @tc.desc: Judge whether two List instances are equal. For example: let res = list.equal(list1). - * @tc.author: wangyong */ it("testEqual010", 0, function () { let list = new List(); @@ -168,7 +159,6 @@ describe("ListTest", function () { /** * @tc.name: testGet011 * @tc.desc: Gets the element corresponding to the specified index. For example: list.get(2). - * @tc.author: wangyong */ it("testGet010", 0, function () { let list = new List(); @@ -186,7 +176,6 @@ describe("ListTest", function () { * @tc.name: testGetLastIndexOf012 * @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.author: wangyong */ it("testGetLastIndexOf012", 0, function () { let list = new List(); @@ -204,7 +193,6 @@ describe("ListTest", function () { * @tc.name: testGetIndexOf013 * @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.author: wangyong */ it("testGetIndexOf013", 0, function () { let list = new List(); @@ -221,7 +209,6 @@ describe("ListTest", function () { /** * @tc.name: testRemoveByIndex014 * @tc.desc: In the List instance, delete the element based on its index. For example: list.removeByIndex(2). - * @tc.author: wangyong */ it("testRemoveByIndex014", 0, function () { let list = new List(); @@ -244,7 +231,6 @@ describe("ListTest", function () { /** * @tc.name: testRemove015 * @tc.desc: Delete the specified element. For example: list.remove("a"). - * @tc.author: wangyong */ it("testRemove015", 0, function () { let list = new List(); @@ -268,7 +254,6 @@ describe("ListTest", function () { * @tc.name: testReplaceAllElements016 * @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.author: wangyong */ it("testReplaceAllElements016", 0, function () { let list = new List(); @@ -292,7 +277,6 @@ describe("ListTest", function () { /** * @tc.name: testGetFirst017 * @tc.desc: Get the header element of the List instance. For example: list.getFirst(). - * @tc.author: wangyong */ it("testGetFirst017", 0, function () { let list = new List(); @@ -308,7 +292,6 @@ describe("ListTest", function () { /** * @tc.name: testGetLast018 * @tc.desc: Get the end element of the List instance. For example: list.getLast(). - * @tc.author: wangyong */ it("testGetLast018", 0, function () { let list = new List(); @@ -324,7 +307,6 @@ describe("ListTest", function () { /** * @tc.name: testInsert019 * @tc.desc: Insert an element into the middle of the List instance. For example: list.insert("d", 3). - * @tc.author: wangyong */ it("testInsert019", 0, function () { let list = new List(); @@ -347,7 +329,6 @@ describe("ListTest", function () { /** * @tc.name: testSet020 * @tc.desc: Modify the element corresponding to the specified index. For example: list.set(2, "d"). - * @tc.author: wangyong */ it("testSet020", 0, function () { let list = new List(); @@ -363,7 +344,6 @@ describe("ListTest", function () { /** * @tc.name: testSort021 * @tc.desc: Arrange the elements in the List instance in descending order. For example: list.sort((a, b) => a - b). - * @tc.author: wangyong */ it("testSort021", 0, function () { let list = new List(); @@ -387,7 +367,6 @@ describe("ListTest", function () { * @tc.name: testGetSubList022 * @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.author: wangyong */ it("testGetSubList022", 0, function () { let list = new List(); @@ -410,7 +389,6 @@ describe("ListTest", function () { /** * @tc.name: testConvertToArray023 * @tc.desc: Convert an List instance to an array. For example: list.convertToArray(). - * @tc.author: wangyong */ it("testConvertToArray023", 0, function () { let list = new List(); @@ -430,7 +408,6 @@ describe("ListTest", function () { /** * @tc.name: testLength024 * @tc.desc: Get the number of elements contained in the List instance. For example: list.length. - * @tc.author: wangyong */ it("testLength024", 0, function () { let list = new List(); @@ -446,7 +423,6 @@ describe("ListTest", function () { /** * @tc.name: testIterator025 * @tc.desc: Iterates over all elements in an List instance. For example: for (let item of list) {arr.push(item);}. - * @tc.author: wangyong */ it("testIterator025", 0, function () { let list = new List(); @@ -472,7 +448,6 @@ describe("ListTest", function () { /** * @tc.name: testForEach026 * @tc.desc: Traversing elements in an List instance. For example: list.forEach((item, index) => {arr.push(item);}). - * @tc.author: wangyong */ it("testForEach026", 0, function () { let list = new List(); @@ -498,7 +473,6 @@ describe("ListTest", function () { /** * @tc.name: testIsEmpty027 * @tc.desc: Determine whether the List instance is empty. For example: list.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty027", 0, function () { let list = new List(); @@ -518,7 +492,6 @@ describe("ListTest", function () { /** * @tc.name: testClear028 * @tc.desc: Clear all elements in the List instance. For example: list.clear(). - * @tc.author: wangyong */ it("testClear028", 0, function () { let list = new List(); @@ -534,7 +507,6 @@ describe("ListTest", function () { /** * @tc.name: testGet029 * @tc.desc: Gets the element corresponding to the specified index. For example: list.get(6). - * @tc.author: wangyong */ it("testGet029", 0, function () { let list = new List(); @@ -552,7 +524,6 @@ describe("ListTest", function () { * @tc.name: testGetLastIndexOf030 * @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.author: wangyong */ it("testGetLastIndexOf030", 0, function () { let list = new List(); @@ -569,7 +540,6 @@ describe("ListTest", function () { /** * @tc.name: testRemoveByIndex031 * @tc.desc: In the List instance, delete the element based on its index. For example: list.removeByIndex(5). - * @tc.author: wangyong */ it("testRemoveByIndex031", 0, function () { let list = new List(); @@ -580,16 +550,17 @@ describe("ListTest", function () { list.add("b"); try { let res = list.removeByIndex(5); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - expect(err.message).assertEqual("the index is out-of-bounds"); + 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.name: testRemove032 * @tc.desc: Delete the specified element. For example: list.remove(). - * @tc.author: wangyong */ it("testRemove032", 0, function () { let list = new List(); @@ -601,7 +572,6 @@ describe("ListTest", function () { /** * @tc.name: testInsert033 * @tc.desc: Insert an element into the middle of the List instance. For example: list.insert("d", 8). - * @tc.author: wangyong */ it("testInsert033", 0, function () { let list = new List(); @@ -612,16 +582,17 @@ describe("ListTest", function () { list.add("b"); try { let res = list.insert("d", 8); + expect(true).assertEqual(false); } catch(err) { - expect(err.name).assertEqual("RangeError"); - expect(err.message).assertEqual("the index is out-of-bounds"); + 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.name: testSort034 * @tc.desc: Arrange the elements in the List instance in descending order. For example: list.sort((a, b) => a - b). - * @tc.author: wangyong */ it("testSort034", 0, function () { let list = new List(); @@ -646,7 +617,6 @@ describe("ListTest", function () { * @tc.name: testGetSubList035 * @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.author: wangyong */ it("testGetSubList035", 0, function () { let list = new List(); @@ -657,9 +627,11 @@ describe("ListTest", function () { list.add("14"); try { list.getSubList(2, 8); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - expect(err.message).assertEqual("the fromIndex or the toIndex is out-of-bounds"); + 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`); } }); @@ -667,7 +639,6 @@ describe("ListTest", function () { * @tc.name: testGetSubList036 * @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.author: wangyong */ it("testGetSubList036", 0, function () { let list = new List(); @@ -678,9 +649,11 @@ describe("ListTest", function () { list.add("14"); try { let res = list.getSubList(6, 8); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - expect(err.message).assertEqual("the fromIndex or the toIndex is out-of-bounds"); + 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`); } }); @@ -688,7 +661,6 @@ describe("ListTest", function () { * @tc.name: testGetSubList037 * @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.author: wangyong */ it("testGetSubList037", 0, function () { let list = new List(); @@ -699,16 +671,17 @@ describe("ListTest", function () { list.add("14"); try { let res = list.getSubList(6, 2); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - expect(err.message).assertEqual("the toIndex cannot be less than or equal to fromIndex"); + 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.name: testAdd038 * @tc.desc: Add a element to the end of the List instance. For example: list.add("*"). - * @tc.author: wangyong */ it("testAdd038", 0, function () { let list = new List(); @@ -722,7 +695,6 @@ describe("ListTest", function () { /** * @tc.name: testAdd039 * @tc.desc: Add a element to the end of the List instance. For example: list.add("*"). - * @tc.author: wangyong */ it("testAdd039", 0, function () { let list = new List(); @@ -742,7 +714,6 @@ describe("ListTest", function () { /** * @tc.name: testAdd040 * @tc.desc: Add a element to the end of the List instance. For example: list.add(" "). - * @tc.author: wangyong */ it("testAdd040", 0, function () { let list = new List(); @@ -754,7 +725,6 @@ describe("ListTest", function () { /** * @tc.name: testAdd041 * @tc.desc: Add a element to the end of the List instance. For example: list.add("a"). - * @tc.author: wangyong */ it("testAdd041", 0, function () { let list = new List(); @@ -769,7 +739,6 @@ describe("ListTest", function () { /** * @tc.name: testListGet042 * @tc.desc: Gets the element corresponding to the specified index. For example: list[0]. - * @tc.author: wangyong */ it("testListGet042", 0, function () { let list = new List(); @@ -782,7 +751,6 @@ describe("ListTest", function () { /** * @tc.name: testListSet043 * @tc.desc: Modify the element corresponding to the specified index. For example: list[1] = "c". - * @tc.author: wangyong */ it("testListSet043", 0, function () { let list = new List(); @@ -799,7 +767,6 @@ describe("ListTest", function () { /** * @tc.name: testAdd044 * @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.author: wangyong */ it("testAdd044", 0, function () { let list = new List(); @@ -815,7 +782,6 @@ describe("ListTest", function () { /** * @tc.name: testAdd045 * @tc.desc: Add a element to the end of the List instance. For example: list.add(null). - * @tc.author: wangyong */ it("testAdd045", 0, function () { let list = new List(); @@ -827,7 +793,6 @@ describe("ListTest", function () { /** * @tc.name: testAdd046 * @tc.desc: Add a element to the end of the List instance. For example: list.add(0.1111). - * @tc.author: wangyong */ it("testAdd046", 0, function () { let list = new List(); @@ -839,7 +804,6 @@ describe("ListTest", function () { /** * @tc.name: testAdd047 * @tc.desc: Add a element to the end of the List instance. For example: list.add(-1). - * @tc.author: wangyong */ it("testAdd047", 0, function () { let list = new List(); @@ -851,7 +815,6 @@ describe("ListTest", function () { /** * @tc.name: testAdd048 * @tc.desc: Add a element to the end of the List instance. For example: const obj = {}; list.add(obj). - * @tc.author: wangyong */ it("testAdd048", 0, function () { let list = new List(); @@ -864,7 +827,6 @@ describe("ListTest", function () { /** * @tc.name: testSort049 * @tc.desc: Arrange the elements in the List instance in descending order. For example: list.sort((a, b) => a - b). - * @tc.author: wangyong */ it("testSort049", 0, function () { let list = new List(); @@ -876,22 +838,22 @@ describe("ListTest", function () { /** * @tc.name: testRemoveByIndex050 * @tc.desc: In the List instance, delete the element based on its index. For example: list.removeByIndex(1). - * @tc.author: wangyong */ it("testRemoveByIndex050", 0, function () { let list = new List(); try { let res = list.removeByIndex(1); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - expect(err.message).assertEqual("the index is out-of-bounds"); + 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.name: testEqual051 * @tc.desc: Judge whether two List instances are equal. For example: let res = list.equal(list1). - * @tc.author: wangyong */ it("testEqual051", 0, function () { let list = new List(); @@ -904,7 +866,6 @@ describe("ListTest", function () { * @tc.name: testGetIndexOf052 * @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.author: wangyong */ it("testGetIndexOf052", 0, function () { let list = new List(); @@ -915,7 +876,6 @@ describe("ListTest", function () { /** * @tc.name: testForEach053 * @tc.desc: Traversing elements in an List instance. For example: list.forEach((item, index) => {num++;}). - * @tc.author: wangyong */ it("testForEach053", 0, function () { let list = new List(); @@ -929,7 +889,6 @@ describe("ListTest", function () { /** * @tc.name: testIsEmpty054 * @tc.desc: Determine whether the List instance is empty. For example: list.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty054", 0, function () { let list = new List(); @@ -940,7 +899,6 @@ describe("ListTest", function () { /** * @tc.name: testHas055 * @tc.desc: Check whether the List contains a specified element. For example: list.has(1). - * @tc.author: wangyong */ it("testHas055", 0, function () { let list = new List(); @@ -951,7 +909,6 @@ describe("ListTest", function () { /** * @tc.name: testGet056 * @tc.desc: Gets the element corresponding to the specified index. For example: list.get(1). - * @tc.author: wangyong */ it("testGet056", 0, function () { let list = new List(); @@ -962,7 +919,6 @@ describe("ListTest", function () { /** * @tc.name: testClear057 * @tc.desc: Clear all elements in the List instance. For example: list.clear(). - * @tc.author: wangyong */ it("testClear057", 0, function () { let list = new List(); @@ -974,7 +930,6 @@ describe("ListTest", function () { /** * @tc.name: testGetLast058 * @tc.desc: Get the end element of the List instance. For example: list.getLast(). - * @tc.author: wangyong */ it("testGetLast058", 0, function () { let list = new List(); @@ -986,7 +941,6 @@ describe("ListTest", function () { * @tc.name: testReplaceAllElements059" * @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.author: wangyong */ it("testReplaceAllElements059", 0, function () { let list = new List(); @@ -1000,7 +954,6 @@ describe("ListTest", function () { /** * @tc.name: testConvertToArray060 * @tc.desc: Convert an List instance to an array. For example: list.convertToArray(). - * @tc.author: wangyong */ it("testConvertToArray060", 0, function () { let list = new List(); @@ -1011,7 +964,6 @@ describe("ListTest", function () { /** * @tc.name: testConvertToArray061 * @tc.desc: Convert an List instance to an array. For example: list.convertToArray(). - * @tc.author: wangyong */ it("testConvertToArray061", 0, function () { let list = new List(); @@ -1022,7 +974,6 @@ describe("ListTest", function () { /** * @tc.name: testlterator062 * @tc.desc: Iterates over all elements in an List instance. For example: for (const iterator of list) { num++;}. - * @tc.author: wangyong */ it("testlterator062", 0, function () { let list = new List(); @@ -1039,7 +990,6 @@ describe("ListTest", function () { /** * @tc.name: testlterator063 * @tc.desc: Get the header element of the List instance. For example: list.getFirst(). - * @tc.author: wangyong */ it("testGetFirst063", 0, function () { let list = new List(); @@ -1050,7 +1000,6 @@ describe("ListTest", function () { /** * @tc.name: testIterator064 * @tc.desc: Iterates over all elements in an List instance. For example: List[Symbol.iterator](). - * @tc.author: wangyong */ it("testIterator064", 0, function () { let list = new List(); @@ -1072,5 +1021,129 @@ describe("ListTest", function () { expect(arr[i]).assertEqual(a[i]); } }); + + /** + * @tc.name: testGet065 + * @tc.desc: Gets the element corresponding to the specified index. For example: list.get.bind({}, 1)(). + */ + it("testGet065 ", 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.name: testInsert066 + * @tc.desc: Insert an element into the middle of the List instance. For example: list.insert("d", "a"). + */ + it("testInsert066", 0, function () { + let list = new List(); + list.add("a"); + list.add("b"); + list.add("c"); + try { + list.insert("d", "a"); + expect(true).assertEqual(false); + } catch(err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); + } + }); + + /** + * @tc.name: testRemoveByIndex067 + * @tc.desc: In the List instance, delete the element based on its index. For example: list.removeByIndex("a"). + */ + it("testRemoveByIndex067", 0, function () { + let list = new List(); + try { + let res = list.removeByIndex("a"); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); + } + }); + + /** + * @tc.name: testSet068 + * @tc.desc: Modify the element corresponding to the specified index. For example: list.set(6, "d"). + */ + it("testSet068", 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.name: testSet069 + * @tc.desc: Modify the element corresponding to the specified index. For example: list.set("a", "d"). + */ + it("testSet069", 0, function () { + let list = new List(); + list.add("a"); + list.add("b"); + list.add("c"); + try { + list.set("a", "d"); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); + } + }); + + /** + * @tc.name: testSort070 + * @tc.desc: Arrange the elements in the List instance in descending order. For example: list.sort(123). + */ + it("testSort070", 0, function () { + let list = new List(); + try { + list.sort(123); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "comparator" must be callable. Received value is: 123`); + } + }); + + /** + * @tc.name: testGetSubList071 + * @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). + */ + it("testGetSubList071", 0, function () { + let list = new List(); + list.add("4"); + list.add("3"); + try { + let res = list.getSubList("a", 2); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "fromIndex" must be number. Received value is: a`); + } + }); }); } diff --git a/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Queue.test.js b/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Queue.test.js index f78b4ffb1bc6ea4aca5b8cf1bb0149387e660f23..60a18a5193d90ed64f6f6f744189aa90459be205 100644 --- a/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Queue.test.js +++ b/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Queue.test.js @@ -20,21 +20,20 @@ describe("QueueTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Create an Queue instance. For example: let queue = new Queue(). - * @tc.author: wangyong */ it("testConstructor001", 0, function () { try { let queue = new Queue(); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("Cannot create new queue"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200012); + expect(err.message).assertEqual("The Queue's constructor cannot be directly invoked"); } }); /** * @tc.name: testAdd002 * @tc.desc: Add element to Queue instance end. For example: queue.add("四"). - * @tc.author: wangyong */ it("testAdd002", 0, function () { let queue = new Queue(); @@ -46,7 +45,6 @@ describe("QueueTest", function () { /** * @tc.name: testAdd003 * @tc.desc: Add element to Queue instance end. For example: queue.add(8). - * @tc.author: wangyong */ it("testAdd003", 0, function () { let queue = new Queue(); @@ -58,7 +56,6 @@ describe("QueueTest", function () { /** * @tc.name: testAdd004 * @tc.desc: Add element to Queue instance end. For example: queue.add(8). - * @tc.author: wangyong */ it("testAdd004", 0, function () { let queue = new Queue(); @@ -71,7 +68,6 @@ describe("QueueTest", function () { /** * @tc.name: testGetFirst005 * @tc.desc: Get the header element of the queue instance. For example: queue.getFirst(). - * @tc.author: wangyong */ it("testGetFirst005", 0, function () { let queue = new Queue(); @@ -84,7 +80,6 @@ describe("QueueTest", function () { /** * @tc.name: testPop006 * @tc.desc: Delete the header element of a queue instance. For example: queue.pop(). - * @tc.author: wangyong */ it("testPop006", 0, function () { let queue = new Queue(); @@ -99,7 +94,6 @@ describe("QueueTest", function () { /** * @tc.name: testForEach007 * @tc.desc: Traversing elements in queue instances. For example: queue.forEach((item, index) => {arr.push(item);}). - * @tc.author: wangyong */ it("testForEach007", 0, function () { let queue = new Queue(); @@ -127,7 +121,6 @@ describe("QueueTest", function () { /** * @tc.name: testIterator008 * @tc.desc: Iterate over all elements in the queue instance. For example: for (let item of queue) { arr.push(item);}. - * @tc.author: wangyong */ it("testIterator008", 0, function () { let queue = new Queue(); @@ -151,7 +144,6 @@ describe("QueueTest", function () { /** * @tc.name: testLength009 * @tc.desc: Get the number of elements in the queue instance. For example: queue.length. - * @tc.author: wangyong */ it("testLength009", 0, function () { let queue = new Queue(); @@ -171,7 +163,6 @@ describe("QueueTest", function () { /** * @tc.name: testAdd010 * @tc.desc: Add element to Queue instance end. For example: queue.add("$"). - * @tc.author: wangyong */ it("testAdd010", 0, function () { let queue = new Queue(); @@ -183,7 +174,6 @@ describe("QueueTest", function () { /** * @tc.name: testAdd011 * @tc.desc: Add element to Queue instance end. For example: queue.add(" "). - * @tc.author: wangyong */ it("testAdd011", 0, function () { let queue = new Queue(); @@ -195,7 +185,6 @@ describe("QueueTest", function () { /** * @tc.name: testAdd012 * @tc.desc: Add element to Queue instance end. For example: queue.add(null). - * @tc.author: wangyong */ it("testAdd012", 0, function () { let queue = new Queue(); @@ -207,7 +196,6 @@ describe("QueueTest", function () { /** * @tc.name: testAdd013 * @tc.desc: Add element to Queue instance end. For example: queue.add(undefined). - * @tc.author: wangyong */ it("testAdd013", 0, function () { let queue = new Queue(); @@ -219,7 +207,6 @@ describe("QueueTest", function () { /** * @tc.name: testAdd014 * @tc.desc: Add element to Queue instance end. For example: for (let i = 0; i < 100; i++) { queue.add(i);}. - * @tc.author: wangyong */ it("testAdd014", 0, function () { let queue = new Queue(); @@ -233,7 +220,6 @@ describe("QueueTest", function () { /** * @tc.name: testGetFirst015 * @tc.desc: Get the header element of the queue instance. For example: queue.getFirst(). - * @tc.author: wangyong */ it("testGetFirst015", 0, function () { let queue = new Queue(); @@ -244,7 +230,6 @@ describe("QueueTest", function () { /** * @tc.name: testPop016 * @tc.desc: Delete the header element of a queue instance. For example: queue.pop(). - * @tc.author: wangyong */ it("testPop016", 0, function () { let queue = new Queue(); @@ -255,7 +240,6 @@ describe("QueueTest", function () { /** * @tc.name: testForEach017 * @tc.desc: Traversing elements in queue instances. For example: queue.forEach((item, index) => {arr.push(item);}). - * @tc.author: wangyong */ it("testForEach017", 0, function () { let queue = new Queue(); @@ -269,7 +253,6 @@ describe("QueueTest", function () { /** * @tc.name: testIterator018 * @tc.desc: Iterate over all elements in the queue instance. For example: for (let item of queue) { arr.push(item);}. - * @tc.author: wangyong */ it("testIterator018", 0, function () { let queue = new Queue(); @@ -283,7 +266,6 @@ describe("QueueTest", function () { /** * @tc.name: testIterator019 * @tc.desc: Iterate over all elements in the queue instance. For example: queue[Symbol.iterator](). - * @tc.author: wangyong */ it("testIterator019", 0, function () { let queue = new Queue(); @@ -305,5 +287,21 @@ describe("QueueTest", function () { expect(arr[i]).assertEqual(a[i]); } }); + + /** + * @tc.name: testAdd020 + * @tc.desc: Add element to Queue instance end. For example: queue.add.bind({}, 10)(). + */ + it("testAdd020 ", 0, function () { + let queue = new Queue(); + try { + queue.add.bind({}, 10)(); + 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`); + } + }); }); } diff --git a/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Stack.test.js b/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Stack.test.js index 1f56958d5f633957df22d8d24dd7a536f113af66..9ca58c62a77974f07327c2a08a5d795afebfb1c8 100644 --- a/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Stack.test.js +++ b/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Stack.test.js @@ -20,22 +20,21 @@ describe("StackTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Create an Stack instance. For example: let stack = new Stack(). - * @tc.author: wangyong */ it("testConstructor001", 0, function () { try { let stack = new Stack(); expect(stack != undefined).assertEqual(true); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("Cannot create new stack"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200012); + expect(err.message).assertEqual("The Stack's constructor cannot be directly invoked"); } }); /** * @tc.name: testPush002 * @tc.desc: Insert element at top of stack.For example: stack.push("四"). - * @tc.author: wangyong */ it("testPush002", 0, function () { let stack = new Stack(); @@ -47,7 +46,6 @@ describe("StackTest", function () { /** * @tc.name: testPush003 * @tc.desc: Insert element at top of stack.For example: stack.push(8). - * @tc.author: wangyong */ it("testPush003", 0, function () { let stack = new Stack(); @@ -59,7 +57,6 @@ describe("StackTest", function () { /** * @tc.name: testPush004 * @tc.desc: Insert element at top of stack.For example: let a = {name: "lala", age: "13岁"}; stack.push(a). - * @tc.author: wangyong */ it("testPush004", 0, function () { let stack = new Stack(); @@ -72,7 +69,6 @@ describe("StackTest", function () { /** * @tc.name: testPush005 * @tc.desc: Insert element at top of stack.For example: let a = [1, 2, 3, 4]; stack.push(a). - * @tc.author: wangyong */ it("testPush005", 0, function () { let stack = new Stack(); @@ -85,7 +81,6 @@ describe("StackTest", function () { /** * @tc.name: testPeek006 * @tc.desc: Get stack top element. For example: stack.peek(). - * @tc.author: wangyong */ it("testPeek006", 0, function () { let stack = new Stack(); @@ -101,7 +96,6 @@ describe("StackTest", function () { /** * @tc.name: testLocate007 * @tc.desc: Get the index corresponding to the element in the stack. For example: stack.locate("A"). - * @tc.author: wangyong */ it("testLocate007", 0, function () { let stack = new Stack(); @@ -120,7 +114,6 @@ describe("StackTest", function () { /** * @tc.name: testPop008 * @tc.desc: Delete top of stack element. For example: stack.pop(). - * @tc.author: wangyong */ it("testPop008", 0, function () { let stack = new Stack(); @@ -135,7 +128,6 @@ describe("StackTest", function () { /** * @tc.name: testForEach009 * @tc.desc: Traversing elements in stack instances. For example: stack.forEach((item, index) => {arr.push(item);}). - * @tc.author: wangyong */ it("testForEach009", 0, function () { let stack = new Stack(); @@ -159,7 +151,6 @@ describe("StackTest", function () { /** * @tc.name: testIterator010 * @tc.desc: Iterate over all elements in the stack instance. For example: for (let item of stack) {arr.push(item);}. - * @tc.author: wangyong */ it("testIterator010", 0, function () { let stack = new Stack(); @@ -185,7 +176,6 @@ describe("StackTest", function () { /** * @tc.name: testLength011 * @tc.desc: Get the number of elements in the stack instance. For example: stack.length. - * @tc.author: wangyong */ it("testLength011", 0, function () { let stack = new Stack(); @@ -200,7 +190,6 @@ describe("StackTest", function () { /** * @tc.name: testLength012 * @tc.desc: Get the number of elements in the stack instance. For example: stack.length. - * @tc.author: wangyong */ it("testLength012", 0, function () { let stack = new Stack(); @@ -211,7 +200,6 @@ describe("StackTest", function () { /** * @tc.name: testIsEmpty013 * @tc.desc: Determine whether the Stack instance is empty. For example: stack.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty013", 0, function () { let stack = new Stack(); @@ -226,7 +214,6 @@ describe("StackTest", function () { /** * @tc.name: testIsEmpty014 * @tc.desc: Determine whether the Stack instance is empty. For example: stack.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty014", 0, function () { let stack = new Stack(); @@ -237,7 +224,6 @@ describe("StackTest", function () { /** * @tc.name: testPush015 * @tc.desc: Insert element at top of stack.For example: stack.push("你好世界"). - * @tc.author: wangyong */ it("testPush015", 0, function () { let stack = new Stack(); @@ -249,7 +235,6 @@ describe("StackTest", function () { /** * @tc.name: testPush016 * @tc.desc: Insert element at top of stack.For example: stack.push(1234). - * @tc.author: wangyong */ it("testPush016", 0, function () { let stack = new Stack(); @@ -261,7 +246,6 @@ describe("StackTest", function () { /** * @tc.name: testPush017 * @tc.desc: Insert element at top of stack.For example: stack.push(1.234). - * @tc.author: wangyong */ it("testPush017", 0, function () { let stack = new Stack(); @@ -273,7 +257,6 @@ describe("StackTest", function () { /** * @tc.name: testPush018 * @tc.desc: Insert element at top of stack.For example: stack.push(-1234). - * @tc.author: wangyong */ it("testPush018", 0, function () { let stack = new Stack(); @@ -285,7 +268,6 @@ describe("StackTest", function () { /** * @tc.name: testPush019 * @tc.desc: Insert element at top of stack.For example: stack.push(0). - * @tc.author: wangyong */ it("testPush019", 0, function () { let stack = new Stack(); @@ -297,7 +279,6 @@ describe("StackTest", function () { /** * @tc.name: testPush020 * @tc.desc: Insert element at top of stack.For example: stack.push("*"). - * @tc.author: wangyong */ it("testPush020", 0, function () { let stack = new Stack(); @@ -313,7 +294,6 @@ describe("StackTest", function () { /** * @tc.name: testPush021 * @tc.desc: Insert element at top of stack.For example: let arr = {}; stack.push(arr). - * @tc.author: wangyong */ it("testPush021", 0, function () { let stack = new Stack(); @@ -326,7 +306,6 @@ describe("StackTest", function () { /** * @tc.name: testPush022 * @tc.desc: Insert element at top of stack.For example: let arr = []; stack.push(arr). - * @tc.author: wangyong */ it("testPush022", 0, function () { let stack = new Stack(); @@ -339,7 +318,6 @@ describe("StackTest", function () { /** * @tc.name: testPush023 * @tc.desc: Insert element at top of stack.For example: stack.push("hello world"). - * @tc.author: wangyong */ it("testPush023", 0, function () { let stack = new Stack(); @@ -351,7 +329,6 @@ describe("StackTest", function () { /** * @tc.name: testPush024 * @tc.desc: Insert element at top of stack. - * @tc.author: wangyong */ it("testPush024", 0, function () { let stack = new Stack(); @@ -363,7 +340,6 @@ describe("StackTest", function () { /** * @tc.name: testPush025 * @tc.desc: Insert element at top of stack. For example: stack.push(""). - * @tc.author: wangyong */ it("testPush025", 0, function () { let stack = new Stack(); @@ -375,7 +351,6 @@ describe("StackTest", function () { /** * @tc.name: testPush026 * @tc.desc: Insert element at top of stack. For example: stack.push(true). - * @tc.author: wangyong */ it("testPush026", 0, function () { let stack = new Stack(); @@ -387,7 +362,6 @@ describe("StackTest", function () { /** * @tc.name: testPush027 * @tc.desc: Insert element at top of stack. For example: stack.push(false). - * @tc.author: wangyong */ it("testPush027", 0, function () { let stack = new Stack(); @@ -399,7 +373,6 @@ describe("StackTest", function () { /** * @tc.name: testPush028 * @tc.desc: Insert element at top of stack. For example: stack.push(null). - * @tc.author: wangyong */ it("testPush028", 0, function () { let stack = new Stack(); @@ -411,7 +384,6 @@ describe("StackTest", function () { /** * @tc.name: testPush029 * @tc.desc: Insert element at top of stack. For example: stack.push(undefined). - * @tc.author: wangyong */ it("testPush029", 0, function () { let stack = new Stack(); @@ -423,7 +395,6 @@ describe("StackTest", function () { /** * @tc.name: testPeek030 * @tc.desc: Get stack top element. For example: stack.peek(). - * @tc.author: wangyong */ it("testPeek030", 0, function () { let stack = new Stack(); @@ -434,7 +405,6 @@ describe("StackTest", function () { /** * @tc.name: testPop031 * @tc.desc: Delete top of stack element. For example: stack.pop(). - * @tc.author: wangyong */ it("testPop031", 0, function () { let stack = new Stack(); @@ -445,7 +415,6 @@ describe("StackTest", function () { /** * @tc.name: testForEach032 * @tc.desc: Traversing elements in stack instances. For example: stack.forEach((item, index) => {arr.push(item);}). - * @tc.author: wangyong */ it("testForEach032", 0, function () { let stack = new Stack(); @@ -459,7 +428,6 @@ describe("StackTest", function () { /** * @tc.name: testIterator033 * @tc.desc: Iterate over all elements in the stack instance. For example: for (let item of stack) {arr.push(item);}. - * @tc.author: wangyong */ it("testIterator033", 0, function () { let stack = new Stack(); @@ -473,7 +441,6 @@ describe("StackTest", function () { /** * @tc.name: testPush034 * @tc.desc: Insert element at top of stack. For example: for (let i = 0; i < 1000; i++) {stack.push(i);}. - * @tc.author: wangyong */ it("testPush034", 0, function () { let stack = new Stack(); @@ -489,7 +456,6 @@ describe("StackTest", function () { /** * @tc.name: testIterator035 * @tc.desc: Iterate over all elements in the stack instance. For example: stack[Symbol.iterator](). - * @tc.author: wangyong */ it("testIterator035", 0, function () { let stack = new Stack(); @@ -514,5 +480,21 @@ describe("StackTest", function () { expect(arr[i]).assertEqual(a[i]); } }); + + /** + * @tc.name: testPush036 + * @tc.desc: Insert element at top of stack. For example: stack.push.bind({}, 10)(). + */ + it("testPush036 ", 0, function () { + let stack = new Stack(); + try { + stack.push.bind({}, 10)(); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200011); + expect(err.message).assertEqual(`The push method cannot be bound`); + } + }); }); } diff --git a/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Vector.test.js b/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Vector.test.js index c77d21fca14086665695a0b8abf4f1eda986f5fb..9721003c940e1012c67460512778cbddacb27114 100644 --- a/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Vector.test.js +++ b/commonlibrary/ets_utils/containerLine_lib_standard/src/main/js/test/Vector.test.js @@ -20,7 +20,6 @@ describe("VectorTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Create an Vector instance. For example: let vector = new Vector(). - * @tc.author: wangyong */ it("testConstructor001", 0, function () { try { @@ -34,7 +33,6 @@ describe("VectorTest", function () { /** * @tc.name: testAdd002 * @tc.desc: Add a element to the end of the Vector instance. For example: vector.add("四"). - * @tc.author: wangyong */ it("testAdd002", 0, function () { let vector = new Vector(); @@ -46,7 +44,6 @@ describe("VectorTest", function () { /** * @tc.name: testAdd003 * @tc.desc: Add a element to the end of the Vector instance. For example: vector.add(4). - * @tc.author: wangyong */ it("testAdd003", 0, function () { let vector = new Vector(); @@ -59,7 +56,6 @@ describe("VectorTest", function () { * @tc.name: testAdd004 * @tc.desc: Add a element to the end of the Vector instance. * For example: let a = {name: "lala", age: "13岁"}; vector.add(a). - * @tc.author: wangyong */ it("testAdd004", 0, function () { let vector = new Vector(); @@ -72,7 +68,6 @@ describe("VectorTest", function () { /** * @tc.name: testAdd005 * @tc.desc: Add a element to the end of the Vector instance. For example: let a = [1, 2, 3, 4]; vector.add(a). - * @tc.author: wangyong */ it("testAdd005", 0, function () { let vector = new Vector(); @@ -85,7 +80,6 @@ describe("VectorTest", function () { /** * @tc.name: testInsert006 * @tc.desc: Insert an element into the middle of the Vector instance. For example: vector.insert(8, 2). - * @tc.author: wangyong */ it("testInsert006", 0, function () { let vector = new Vector(); @@ -101,7 +95,6 @@ describe("VectorTest", function () { /** * @tc.name: testInsert007 * @tc.desc: Insert an element into the middle of the Vector instance. For example: vector.insert(-1, 2). - * @tc.author: wangyong */ it("testInsert007", 0, function () { let vector = new Vector(); @@ -120,7 +113,6 @@ describe("VectorTest", function () { /** * @tc.name: testInsert008 * @tc.desc: Insert an element into the middle of the Vector instance. For example: vector.insert(capacity, 2). - * @tc.author: wangyong */ it("testInsert008", 0, function () { let vector = new Vector(); @@ -137,7 +129,6 @@ describe("VectorTest", function () { /** * @tc.name: testInsert009 * @tc.desc: Insert an element into the middle of the Vector instance. For example: vector.insert(2, capacity + 1). - * @tc.author: wangyong */ it("testInsert009", 0, function () { let vector = new Vector(); @@ -157,7 +148,6 @@ describe("VectorTest", function () { /** * @tc.name: testLength010 * @tc.desc: Get the number of elements contained in the Vector instance. For example: vector.length. - * @tc.author: wangyong */ it("testLength010", 0, function () { let vector = new Vector(); @@ -172,7 +162,6 @@ describe("VectorTest", function () { /** * @tc.name: testHas011 * @tc.desc: Check whether the Vector contains a specified element. For example: vector.has(8). - * @tc.author: wangyong */ it("testHas011", 0, function () { let vector = new Vector(); @@ -188,7 +177,6 @@ describe("VectorTest", function () { /** * @tc.name: testHas012 * @tc.desc: Check whether the Vector contains a specified element. For example: vector.has("二"). - * @tc.author: wangyong */ it("testHas012", 0, function () { let vector = new Vector(); @@ -204,7 +192,6 @@ describe("VectorTest", function () { /** * @tc.name: testGet013 * @tc.desc: Gets the element corresponding to the specified index. For example: vector.get(1). - * @tc.author: wangyong */ it("testGet013", 0, function () { let vector = new Vector(); @@ -220,7 +207,6 @@ describe("VectorTest", function () { /** * @tc.name: testGet014 * @tc.desc: Gets the element corresponding to the specified index. For example: vector.get(10). - * @tc.author: wangyong */ it("testGet014", 0, function () { let vector = new Vector(); @@ -241,7 +227,6 @@ describe("VectorTest", function () { * @tc.name: testGetIndexOf015 * @tc.desc: In the Vector 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: vector.getIndexOf(1). - * @tc.author: wangyong */ it("testGetIndexOf015", 0, function () { let vector = new Vector(); @@ -257,7 +242,6 @@ describe("VectorTest", function () { /** * @tc.name: testGetFirstElement016 * @tc.desc: Get the header element of the Vector instance. For example: vector.getFirstElement(). - * @tc.author: wangyong */ it("testGetFirstElement016", 0, function () { let vector = new Vector(); @@ -273,7 +257,6 @@ describe("VectorTest", function () { /** * @tc.name: testGetFirstElement017 * @tc.desc: Get the header element of the Vector instance. For example: vector.getFirstElement(). - * @tc.author: wangyong */ it("testGetFirstElement017", 0, function () { let vector = new Vector(); @@ -284,7 +267,6 @@ describe("VectorTest", function () { /** * @tc.name: testSet018 * @tc.desc: Modify the element corresponding to the specified index. For example: vector.set(1, "二"). - * @tc.author: wangyong */ it("testSet018", 0, function () { let vector = new Vector(); @@ -301,7 +283,6 @@ describe("VectorTest", function () { /** * @tc.name: testRemoveByIndex019 * @tc.desc: In the Vector instance, delete the element based on its index. For example: vector.removeByIndex(2). - * @tc.author: wangyong */ it("testRemoveByIndex019", 0, function () { let vector = new Vector(); @@ -317,7 +298,6 @@ describe("VectorTest", function () { /** * @tc.name: testRemove020 * @tc.desc: Delete the specified element. For example: vector.remove("三"). - * @tc.author: wangyong */ it("testRemove020", 0, function () { let vector = new Vector(); @@ -333,7 +313,6 @@ describe("VectorTest", function () { /** * @tc.name: testRemove021 * @tc.desc: Delete the specified element. For example: vector.remove(2). - * @tc.author: wangyong */ it("testRemove021", 0, function () { let vector = new Vector(); @@ -348,7 +327,6 @@ describe("VectorTest", function () { /** * @tc.name: testGetLastElement022 * @tc.desc: Get the end element of the Vector instance. For example: vector.getLastElement(). - * @tc.author: wangyong */ it("testGetLastElement022", 0, function () { let vector = new Vector(); @@ -364,7 +342,6 @@ describe("VectorTest", function () { /** * @tc.name: testGetLastElement023 * @tc.desc: Get the end element of the Vector instance. For example: vector.getLastElement(). - * @tc.author: wangyong */ it("testGetLastElement023", 0, function () { let vector = new Vector(); @@ -376,7 +353,6 @@ describe("VectorTest", function () { * @tc.name: testGetLastIndexOf024 * @tc.desc: In the Vector instance, find the index of a specified element from back to front, * and return the index found for the first time. If not found, return -1. For example: vector.getLastIndexOf(1). - * @tc.author: wangyong */ it("testGetLastIndexOf024", 0, function () { let vector = new Vector(); @@ -395,7 +371,6 @@ describe("VectorTest", function () { * In the vector instance, find the index of the specified element from back to front * from the specified index position, and return the index found for the first time If not found, * return -1.vector.getLastIndexFrom(1, 5). - * @tc.author: wangyong */ it("testGetLastIndexFrom025", 0, function () { let vector = new Vector(); @@ -416,7 +391,6 @@ describe("VectorTest", function () { * In the vector instance, find the index of the specified element from front to back * from the specified index position, and return the index found for the first time If not found, * return -1.vector.getLastIndexFrom(1, 5). - * @tc.author: wangyong */ it("testGetIndexFrom026", 0, function () { let vector = new Vector(); @@ -436,7 +410,6 @@ describe("VectorTest", function () { * @tc.name: testRemoveByRange027 * @tc.desc: Deletes elements from a specified range, including elements at the start position and * elements at the end position. For example: vector.removeByRange(1, 3). - * @tc.author: wangyong */ it("testRemoveByRange027", 0, function () { let vector = new Vector(); @@ -463,7 +436,6 @@ describe("VectorTest", function () { * @tc.name: testRemoveByRange028 * @tc.desc: Deletes elements from a specified range, including elements at the start position and * elements at the end position. For example: vector.removeByRange(3, 1). - * @tc.author: wangyong */ it("testRemoveByRange028", 0, function () { let vector = new Vector(); @@ -487,7 +459,6 @@ describe("VectorTest", function () { * @tc.name: testRemoveByRange029 * @tc.desc: Deletes elements from a specified range, including elements at the start position and * elements at the end position. For example: vector.removeByRange(length + 1, 7). - * @tc.author: wangyong */ it("testRemoveByRange029", 0, function () { let vector = new Vector(); @@ -507,7 +478,6 @@ describe("VectorTest", function () { * @tc.name: testRemoveByRange030 * @tc.desc: Deletes elements from a specified range, including elements at the start position and * elements at the end position. For example: vector.removeByRange(1, 7). - * @tc.author: wangyong */ it("testRemoveByRange030", 0, function () { let vector = new Vector(); @@ -527,7 +497,6 @@ describe("VectorTest", function () { * @tc.name: testRemoveByRange031 * @tc.desc: Deletes elements from a specified range, including elements at the start position and * elements at the end position. For example: vector.removeByRange(0, capacity). - * @tc.author: wangyong */ it("testRemoveByRange031", 0, function () { let vector = new Vector(); @@ -552,7 +521,6 @@ describe("VectorTest", function () { * @tc.name: testRemoveByRange032 * @tc.desc: Deletes elements from a specified range, including elements at the start position and * elements at the end position. For example: vector.removeByRange(-1, capacity). - * @tc.author: wangyong */ it("testRemoveByRange032", 0, function () { let vector = new Vector(); @@ -577,7 +545,6 @@ describe("VectorTest", function () { * @tc.name: testRemoveByRange033 * @tc.desc: Deletes elements from a specified range, including elements at the start position and * elements at the end position. For example: vector.removeByRange(0, capacity + 1). - * @tc.author: wangyong */ it("testRemoveByRange033", 0, function () { let vector = new Vector(); @@ -598,7 +565,6 @@ describe("VectorTest", function () { /** * @tc.name: testSetLength034 * @tc.desc: Get the number of elements contained in the Vector instance. For example: vector.length. - * @tc.author: wangyong */ it("testSetLength034", 0, function () { let vector = new Vector(); @@ -619,7 +585,6 @@ describe("VectorTest", function () { * @tc.name: testReplaceAllElements035 * @tc.desc: Perform some operation on the elements in the Vector instance and return the Vector instance * after the operation. For example: vector.replaceAllElements((item, index) => {return (item = 2 * item);}). - * @tc.author: wangyong */ it("testReplaceAllElements035", 0, function () { let vector = new Vector(); @@ -645,7 +610,6 @@ describe("VectorTest", function () { * @tc.name: testForEach036 * @tc.desc: Traversing elements in an Vector instance. * For example: vector.forEach((item, index) => {arr.push(item);}). - * @tc.author: wangyong */ it("testForEach036", 0, function () { let vector = new Vector(); @@ -668,7 +632,6 @@ describe("VectorTest", function () { * @tc.name: testForEach037 * @tc.desc: Traversing elements in an Vector instance. * For example: vector.forEach((item, index) => {arr.push(item);}). - * @tc.author: wangyong */ it("testForEach037", 0, function () { let vector = new Vector(); @@ -684,7 +647,6 @@ describe("VectorTest", function () { * @tc.name: testSubVector038 * @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: vector.subVector(2, 4). - * @tc.author: wangyong */ it("testSubVector038", 0, function () { let vector = new Vector(); @@ -708,7 +670,6 @@ describe("VectorTest", function () { * @tc.name: testSubVector039 * @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: vector.subVector(4, 2). - * @tc.author: wangyong */ it("testSubVector039", 0, function () { let vector = new Vector(); @@ -729,7 +690,6 @@ describe("VectorTest", function () { * @tc.name: testSubVector040 * @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: vector.subVector(length + 1, length + 3). - * @tc.author: wangyong */ it("testSubVector040", 0, function () { let vector = new Vector(); @@ -751,7 +711,6 @@ describe("VectorTest", function () { * @tc.name: testSubVector041 * @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: vector.vector.subVector(1, length + 1). - * @tc.author: wangyong */ it("testSubVector041", 0, function () { let vector = new Vector(); @@ -772,7 +731,6 @@ describe("VectorTest", function () { /** * @tc.name: testClear042 * @tc.desc: Clear all elements in the Vector instance. For example: vector.clear(). - * @tc.author: wangyong */ it("testClear042", 0, function () { let vector = new Vector(); @@ -789,7 +747,6 @@ describe("VectorTest", function () { /** * @tc.name: testConvertToArray043 * @tc.desc: Convert an Vector instance to an array. For example: vector.convertToArray(). - * @tc.author: wangyong */ it("testConvertToArray043", 0, function () { let vector = new Vector(); @@ -809,7 +766,6 @@ describe("VectorTest", function () { * @tc.name: testCopyToArray044 * @tc.desc: Appends the number of elements of corresponding length to a specified array. * For example: vector.copyToArray(arr1). - * @tc.author: wangyong */ it("testCopyToArray044", 0, function () { let vector = new Vector(); @@ -820,7 +776,7 @@ describe("VectorTest", function () { vector.add(14); let arr1 = ["a", "b", "c"]; vector.copyToArray(arr1); - let a = ["a", "b", "c", 4, 3, 1]; + let a = ["a", "b", "c", 4, 3, 1, 2, 14]; for (let i = 0; i < a.length; i++) { expect(arr1[i]).assertEqual(a[i]); } @@ -829,7 +785,6 @@ describe("VectorTest", function () { /** * @tc.name: testToString045 * @tc.desc: Use "," to splice the elements in the vector instance into a string. For example: vector.toString(). - * @tc.author: wangyong */ it("testToString045", 0, function () { let vector = new Vector(); @@ -845,7 +800,6 @@ describe("VectorTest", function () { /** * @tc.name: testClone046 * @tc.desc: Clone an ArrayList instance. For example: vector.clone(). - * @tc.author: wangyong */ it("testClone046", 0, function () { let vector = new Vector(); @@ -868,7 +822,6 @@ describe("VectorTest", function () { /** * @tc.name: testGetCapacity047 * @tc.desc: Get the capacity of Vector instance. For example: vector.getCapacity(). - * @tc.author: wangyong */ it("testGetCapacity047", 0, function () { let vector = new Vector(); @@ -884,7 +837,6 @@ describe("VectorTest", function () { /** * @tc.name: testGetCapacity048 * @tc.desc: Get the capacity of Vector instance. For example: vector.getCapacity(). - * @tc.author: wangyong */ it("testGetCapacity048", 0, function () { let vector = new Vector(); @@ -907,7 +859,6 @@ describe("VectorTest", function () { /** * @tc.name: testIncreaseCapacityTo049 * @tc.desc: Expand the Vector instance capacity to the specified value. For example: vector.increaseCapacityTo(30). - * @tc.author: wangyong */ it("testIncreaseCapacityTo049", 0, function () { let vector = new Vector(); @@ -925,7 +876,6 @@ describe("VectorTest", function () { * @tc.name: testTrimToCurrentLength050 * @tc.desc: Limit the Vector instance capacity to the length of the Vector instance. * For example: vector.trimToCurrentLength(). - * @tc.author: wangyong */ it("testTrimToCurrentLength050", 0, function () { let vector = new Vector(); @@ -942,7 +892,6 @@ describe("VectorTest", function () { /** * @tc.name: testSetLength051 * @tc.desc: Sets the length of the vector instance to the specified value. For example: vector.setLength(7). - * @tc.author: wangyong */ it("testSetLength051", 0, function () { let vector = new Vector(); @@ -960,7 +909,6 @@ describe("VectorTest", function () { * @tc.name: testIterator052 * @tc.desc: Iterate over all elements in the Vector instance. * For example: for (let item of vector) {arr.push(item);}. - * @tc.author: wangyong */ it("testIterator052", 0, function () { let vector = new Vector(); @@ -986,7 +934,6 @@ describe("VectorTest", function () { /** * @tc.name: testIteratorAndRemove053 * @tc.desc: Iterate over all elements in the Vector instance. - * @tc.author: wangyong */ it("testIteratorAndRemove053", 0, function () { let vector = new Vector(); @@ -1018,7 +965,6 @@ describe("VectorTest", function () { /** * @tc.name: testIteratorAndRemove054 * @tc.desc: Iterate over all elements in the Vector instance. - * @tc.author: wangyong */ it("testIteratorAndRemove054", 0, function () { let vector = new Vector(); @@ -1049,7 +995,6 @@ describe("VectorTest", function () { * @tc.name: testIterator055 * @tc.desc: Iterate over all elements in the Vector instance. * For example: for (let item of vector) {arr.push(item);}. - * @tc.author: wangyong */ it("testIterator055", 0, function () { let vector = new Vector(); @@ -1064,7 +1009,6 @@ describe("VectorTest", function () { * @tc.name: testSort056 * @tc.desc: Arrange the elements in the Vector instance in descending order. * For example: vector.sort((a, b) => a - b). - * @tc.author: wangyong */ it("testSort056", 0, function () { let vector = new Vector(); @@ -1087,7 +1031,6 @@ describe("VectorTest", function () { /** * @tc.name: testIsEmpty057 * @tc.desc: Determine whether the Vector instance is empty. For example: vector.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty057", 0, function () { let vector = new Vector(); @@ -1099,7 +1042,6 @@ describe("VectorTest", function () { /** * @tc.name: testisEmpty058 * @tc.desc: Determine whether the Vector instance is empty. For example: vector.isEmpty(). - * @tc.author: wangyong */ it("testisEmpty058", 0, function () { let vector = new Vector(); @@ -1111,7 +1053,6 @@ describe("VectorTest", function () { * @tc.name: testAdd060 * @tc.desc: Add a element to the end of the Vector instance. * For example: for (let i = 0; i < 100; i++) {let res3 = vector.add(i);}. - * @tc.author: wangyong */ it("testAdd060", 0, function () { let vector = new Vector(); @@ -1127,7 +1068,6 @@ describe("VectorTest", function () { /** * @tc.name: testAdd061 * @tc.desc: Add a element to the end of the Vector instance. For example: vector.add("%"). - * @tc.author: wangyong */ it("testAdd061", 0, function () { let vector = new Vector(); @@ -1139,7 +1079,6 @@ describe("VectorTest", function () { /** * @tc.name: testAdd062 * @tc.desc: Add a element to the end of the Vector instance. For example: vector.add(1.89). - * @tc.author: wangyong */ it("testAdd062", 0, function () { let vector = new Vector(); @@ -1151,7 +1090,6 @@ describe("VectorTest", function () { /** * @tc.name: testAdd063 * @tc.desc: Add a element to the end of the Vector instance. For example: vector.add(""). - * @tc.author: wangyong */ it("testAdd063", 0, function () { let vector = new Vector(); @@ -1163,7 +1101,6 @@ describe("VectorTest", function () { /** * @tc.name: testAdd064 * @tc.desc: Add a element to the end of the Vector instance. For example: vector.add(true). - * @tc.author: wangyong */ it("testAdd064", 0, function () { let vector = new Vector(); @@ -1176,7 +1113,6 @@ describe("VectorTest", function () { * @tc.name: testGetIndexOf065 * @tc.desc: In the Vector 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: vector.getIndexOf(23). - * @tc.author: wangyong */ it("testGetIndexOf065", 0, function () { let vector = new Vector(); @@ -1190,7 +1126,6 @@ describe("VectorTest", function () { /** * @tc.name: testSet066 * @tc.desc: Modify the element corresponding to the specified index. For example: vector.set(12, "二"). - * @tc.author: wangyong */ it("testSet066", 0, function () { let vector = new Vector(); @@ -1207,7 +1142,6 @@ describe("VectorTest", function () { /** * @tc.name: testRemoveByIndex067 * @tc.desc: In the Vector instance, delete the element based on its index. For example: vector.removeByIndex(12). - * @tc.author: wangyong */ it("testRemoveByIndex067", 0, function () { let vector = new Vector(); @@ -1225,7 +1159,6 @@ describe("VectorTest", function () { * @tc.name: testGetLastIndexOf068 * @tc.desc: In the Vector instance, find the index of a specified element from back to front, * and return the index found for the first time. If not found, return -1. For example: vector.getLastIndexOf("二"). - * @tc.author: wangyong */ it("testGetLastIndexOf068", 0, function () { let vector = new Vector(); @@ -1238,7 +1171,6 @@ describe("VectorTest", function () { /** * @tc.name: testIterator069 * @tc.desc: Iterate over all elements in the Vector instance. For example: Vector[Symbol.iterator](). - * @tc.author: wangyong */ it("testIterator069", 0, function () { let vector = new Vector(); diff --git a/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/HashMap.test.js b/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/HashMap.test.js index 56609fe0b57ffef694a69cbdcab8cfb7ac01f886..b55f17be7575f62e13298cd9c7da4da7121297b8 100644 --- a/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/HashMap.test.js +++ b/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/HashMap.test.js @@ -20,22 +20,21 @@ describe("HashMapTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Create an HashMap instance. For example: let hashMap = new HashMap(). - * @tc.author: wangyong */ it("testConstructor001", 0, function () { try { let hashMap = new HashMap(); expect(hashMap != undefined).assertEqual(true); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("Cannot create new HashMap"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200012); + expect(err.message).assertEqual("The HashMap's constructor cannot be directly invoked"); } }); /** * @tc.name: testSet002 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set(1, "A"). - * @tc.author: wangyong */ it("testSet002", 0, function () { let hashMap = new HashMap(); @@ -47,7 +46,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet003 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set(1, 2). - * @tc.author: wangyong */ it("testSet003", 0, function () { let hashMap = new HashMap(); @@ -59,7 +57,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet004 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: let c = [1, 2, 3]; hashMap.set(1, c). - * @tc.author: wangyong */ it("testSet004", 0, function () { let hashMap = new HashMap(); @@ -73,7 +70,6 @@ describe("HashMapTest", function () { * @tc.name: testSet005 * @tc.desc: Add a pair of key value pairs to the HashMap. * For example: let c = {name: "lili", age: "13"}; hashMap.set(1, c). - * @tc.author: wangyong */ it("testSet005", 0, function () { let hashMap = new HashMap(); @@ -86,7 +82,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet006 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set("a", "A"). - * @tc.author: wangyong */ it("testSet006", 0, function () { let hashMap = new HashMap(); @@ -98,7 +93,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet007 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set("", "A"). - * @tc.author: wangyong */ it("testSet007", 0, function () { let hashMap = new HashMap(); @@ -110,7 +104,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet008 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set("$", "A"). - * @tc.author: wangyong */ it("testSet008", 0, function () { let hashMap = new HashMap(); @@ -122,7 +115,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet009 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set(3.14, "A"). - * @tc.author: wangyong */ it("testSet009", 0, function () { let hashMap = new HashMap(); @@ -134,7 +126,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet010 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set(0.3, "A"). - * @tc.author: wangyong */ it("testSet010", 0, function () { let hashMap = new HashMap(); @@ -146,7 +137,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet011 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set(-1, "A"). - * @tc.author: wangyong */ it("testSet011", 0, function () { let hashMap = new HashMap(); @@ -158,7 +148,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet012 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: let a = {}; hashMap.set(a, "A"). - * @tc.author: wangyong */ it("testSet012", 0, function () { let hashMap = new HashMap(); @@ -171,7 +160,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet013 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set(1, null). - * @tc.author: wangyong */ it("testSet013", 0, function () { let hashMap = new HashMap(); @@ -183,7 +171,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet014 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set(1, "$"). - * @tc.author: wangyong */ it("testSet014", 0, function () { let hashMap = new HashMap(); @@ -195,7 +182,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet015 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set(1, "3.14"). - * @tc.author: wangyong */ it("testSet015", 0, function () { let hashMap = new HashMap(); @@ -207,7 +193,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet016 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set(1, -1). - * @tc.author: wangyong */ it("testSet016", 0, function () { let hashMap = new HashMap(); @@ -219,7 +204,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet017 * @tc.desc: Add a pair of key value pairs to the HashMap. For example: let a = {}; hashMap.set(1, a). - * @tc.author: wangyong */ it("testSet017", 0, function () { let hashMap = new HashMap(); @@ -233,7 +217,6 @@ describe("HashMapTest", function () { * @tc.name: testSet018 * @tc.desc: Add a pair of key value pairs to the HashMap. * For example: for (let i = 0; i < 100; i++) {hashMap.set(1, i);}. - * @tc.author: wangyong */ it("testSet018", 0, function () { let hashMap = new HashMap(); @@ -249,7 +232,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSet019 * @tc.desc: Add a pair of key value pairs to the HashMap. - * @tc.author: wangyong */ it("testSet019", 0, function () { let hashMap = new HashMap(); @@ -265,7 +247,6 @@ describe("HashMapTest", function () { /** * @tc.name: testLength020 * @tc.desc: Get the number of key value pairs in the HashMap instance. For example: hashMap.length. - * @tc.author: wangyong */ it("testLength020", 0, function () { let hashMap = new HashMap(); @@ -281,7 +262,6 @@ describe("HashMapTest", function () { /** * @tc.name: testHasKey021 * @tc.desc: Determine whether the HashMap contains the specified key. For example: hashMap.hasKey(3). - * @tc.author: wangyong */ it("testHasKey021", 0, function () { let hashMap = new HashMap(); @@ -299,7 +279,6 @@ describe("HashMapTest", function () { /** * @tc.name: testHasKey022 * @tc.desc: Determine whether the HashMap contains the specified key. For example: hashMap.hasKey(8). - * @tc.author: wangyong */ it("testHasKey022", 0, function () { let hashMap = new HashMap(); @@ -310,7 +289,6 @@ describe("HashMapTest", function () { /** * @tc.name: testHasValue023 * @tc.desc: Determine whether the HashMap contains the specified value. For example: hashMap.hasValue("C"). - * @tc.author: wangyong */ it("testHasValue023", 0, function () { let hashMap = new HashMap(); @@ -328,7 +306,6 @@ describe("HashMapTest", function () { /** * @tc.name: testHasValue024 * @tc.desc: Determine whether the HashMap contains the specified value. For example: hashMap.hasValue(8). - * @tc.author: wangyong */ it("testHasValue024", 0, function () { let hashMap = new HashMap(); @@ -339,7 +316,6 @@ describe("HashMapTest", function () { /** * @tc.name: testGet025 * @tc.desc: Get the corresponding value through the key. For example: hashMap.get(3). - * @tc.author: wangyong */ it("testGet025", 0, function () { let hashMap = new HashMap(); @@ -355,7 +331,6 @@ describe("HashMapTest", function () { /** * @tc.name: testGet026 * @tc.desc: Get the corresponding value through the key. For example: hashMap.get(3). - * @tc.author: wangyong */ it("testGet026", 0, function () { let hashMap = new HashMap(); @@ -366,7 +341,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSetAll027 * @tc.desc: Copy key value pairs from one HashMap to another. - * @tc.author: wangyong */ it("testSetAll027", 0, function () { let hashMap = new HashMap(); @@ -396,7 +370,6 @@ describe("HashMapTest", function () { /** * @tc.name: testSetAll028 * @tc.desc: Copy key value pairs from one HashMap to another. - * @tc.author: wangyong */ it("testSetAll028", 0, function () { let hashMap = new HashMap(); @@ -421,7 +394,6 @@ describe("HashMapTest", function () { /** * @tc.name: testRemove029 * @tc.desc: Delete key value pairs according to key. For example: hashMap.remove(3). - * @tc.author: wangyong */ it("testRemove029", 0, function () { let hashMap = new HashMap(); @@ -439,7 +411,6 @@ describe("HashMapTest", function () { /** * @tc.name: testRemove030 * @tc.desc: Delete key value pairs according to key. For example: hashMap.remove(3). - * @tc.author: wangyong */ it("testRemove030", 0, function () { let hashMap = new HashMap(); @@ -450,7 +421,6 @@ describe("HashMapTest", function () { /** * @tc.name: testClear031 * @tc.desc: Clear all key value pairs in HashMap. For example: hashMap.clear(). - * @tc.author: wangyong */ it("testClear031", 0, function () { let hashMap = new HashMap(); @@ -469,7 +439,6 @@ describe("HashMapTest", function () { /** * @tc.name: testClear032 * @tc.desc: Clear all key value pairs in HashMap. For example: hashMap.clear(). - * @tc.author: wangyong */ it("testClear032", 0, function () { let hashMap = new HashMap(); @@ -481,7 +450,6 @@ describe("HashMapTest", function () { /** * @tc.name: testKeys033 * @tc.desc: Get a collection of all the keys in the HashMap. For example: hashMap.keys(). - * @tc.author: wangyong */ it("testKeys033", 0, function () { let hashMap = new HashMap(); @@ -499,7 +467,6 @@ describe("HashMapTest", function () { /** * @tc.name: testValues034 * @tc.desc: Get a collection of all the values in the HashMap. For example: hashMap.values(). - * @tc.author: wangyong */ it("testValues034", 0, function () { let hashMap = new HashMap(); @@ -518,7 +485,6 @@ describe("HashMapTest", function () { /** * @tc.name: testReplace035 * @tc.desc: Modify the corresponding value according to the specified key. For example: hashMap.replace(2, "G"). - * @tc.author: wangyong */ it("testReplace035", 0, function () { let hashMap = new HashMap(); @@ -535,7 +501,6 @@ describe("HashMapTest", function () { /** * @tc.name: testReplace036 * @tc.desc: Modify the corresponding value according to the specified key. For example: hashMap.replace(2, "G"). - * @tc.author: wangyong */ it("testReplace036", 0, function () { let hashMap = new HashMap(); @@ -546,7 +511,6 @@ describe("HashMapTest", function () { /** * @tc.name: testForEach037 * @tc.desc: Traverse all key value pairs in the HashMap instance. - * @tc.author: wangyong */ it("testForEach037", 0, function () { let hashMap = new HashMap(); @@ -574,7 +538,6 @@ describe("HashMapTest", function () { /** * @tc.name: testForEach038 * @tc.desc: Traverse all key value pairs in the HashMap instance. - * @tc.author: wangyong */ it("testForEach038", 0, function () { let hashMap = new HashMap(); @@ -588,7 +551,6 @@ describe("HashMapTest", function () { /** * @tc.name: testIterator039 * @tc.desc: Iterate over all key value pairs in the HashMap. - * @tc.author: wangyong */ it("testIterator039", 0, function () { let hashMap = new HashMap(); @@ -613,7 +575,6 @@ describe("HashMapTest", function () { /** * @tc.name: testIterator040 * @tc.desc: Traverse all key value pairs in the HashMap instance. - * @tc.author: wangyong */ it("testIterator040", 0, function () { let hashMap = new HashMap(); @@ -627,7 +588,6 @@ describe("HashMapTest", function () { /** * @tc.name: testEntries041 * @tc.desc: Get all key value pairs collection in HashMap. - * @tc.author: wangyong */ it("testEntries041", 0, function () { let hashMap = new HashMap(); @@ -654,7 +614,6 @@ describe("HashMapTest", function () { /** * @tc.name: testEntries042 * @tc.desc: Get all key value pairs collection in HashMap. - * @tc.author: wangyong */ it("testEntries042", 0, function () { let hashMap = new HashMap(); @@ -665,7 +624,6 @@ describe("HashMapTest", function () { /** * @tc.name: testIsEmpty043 * @tc.desc: Determine whether the HashMap instance is empty. For example: hashMap.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty043", 0, function () { let hashMap = new HashMap(); @@ -683,7 +641,6 @@ describe("HashMapTest", function () { /** * @tc.name: testIsEmpty044 * @tc.desc: Determine whether the HashMap instance is empty. For example: hashMap.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty044", 0, function () { let hashMap = new HashMap(); @@ -702,7 +659,6 @@ describe("HashMapTest", function () { /** * @tc.name: testEntries045 * @tc.desc: Get all key value pairs collection in HashMap.For example: hashMap.entries(). - * @tc.author: wangyong */ it("testEntries045", 0, function () { let hashMap = new HashMap(); @@ -713,7 +669,6 @@ describe("HashMapTest", function () { /** * @tc.name: testIterator046 * @tc.desc: Iterate over all key value pairs in the HashMap. For example: hashMap[Symbol.iterator](). - * @tc.author: wangyong */ it("testIterator046", 0, function () { let hashMap = new HashMap(); @@ -735,5 +690,55 @@ describe("HashMapTest", function () { } expect(flag).assertEqual(true); }); + + /** + * @tc.name: testSet047 + * @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set.bind({}, 1, "A")(). + */ + it("testSet047", 0, function () { + let hashMap = new HashMap(); + try { + hashMap.set.bind({}, 1, "A")(); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200011); + expect(err.message).assertEqual(`The set method cannot be bound`); + } + }); + + /** + * @tc.name: testSetAll048 + * @tc.desc: Copy key value pairs from one HashMap to another. + */ + it("testSetAll048", 0, function () { + let hashMap = new HashMap(); + hashMap.set(1, "A"); + hashMap.set(2, "B"); + try { + hashMap.setAll([1, 2, 3]); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "map" must be HashMap. Received value is: 1,2,3`); + } + }); + + /** + * @tc.name: testSet049 + * @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set.bind({}, "a", "b")(). + */ + it("testSet049", 0, function () { + let hashMap = new HashMap(); + try { + hashMap.set.bind({}, "a", "b")(); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200011); + expect(err.message).assertEqual(`The set method cannot be bound`); + } + }); }); } diff --git a/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/HashSet.test.js b/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/HashSet.test.js index 4cb19e48f7a4a0d7032bb59bff3bcffd1a05575c..a85e60c47eff838646ce91a258b68d7fd7a96b69 100644 --- a/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/HashSet.test.js +++ b/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/HashSet.test.js @@ -20,21 +20,20 @@ describe("HashSetTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Create an HashSet instance. For example: let hashSet = new HashSet(). - * @tc.author: wangyong */ it("testConstructor001", 0, function () { try { let hashSet = new HashSet(); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("Cannot create new HashSet"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200012); + expect(err.message).assertEqual("The HashSet's constructor cannot be directly invoked"); } }); /** * @tc.name: testAdd001 * @tc.desc: Add element to HashSet instance. For example: hashSet.add(1). - * @tc.author: wangyong */ it("testAdd001", 0, function () { let hashSet = new HashSet(); @@ -46,7 +45,6 @@ describe("HashSetTest", function () { /** * @tc.name: testAdd002 * @tc.desc: Add element to HashSet instance. For example: hashSet.add("a"). - * @tc.author: wangyong */ it("testAdd002", 0, function () { let hashSet = new HashSet(); @@ -62,7 +60,6 @@ describe("HashSetTest", function () { /** * @tc.name: testAdd003 * @tc.desc: Add element to HashSet instance. For example: let c = [1, 2, 3]; hashSet.add(c). - * @tc.author: wangyong */ it("testAdd003", 0, function () { let hashSet = new HashSet(); @@ -75,7 +72,6 @@ describe("HashSetTest", function () { /** * @tc.name: testAdd004 * @tc.desc: Add element to HashSet instance. For example: let c = {name: "lili", age: "13"}; hashSet.add(c). - * @tc.author: wangyong */ it("testAdd004", 0, function () { let hashSet = new HashSet(); @@ -88,7 +84,6 @@ describe("HashSetTest", function () { /** * @tc.name: testLength005 * @tc.desc: Get the number of element in the HashSet instance. For example: hashSet.length. - * @tc.author: wangyong */ it("testLength005", 0, function () { let hashSet = new HashSet(); @@ -104,7 +99,6 @@ describe("HashSetTest", function () { /** * @tc.name: testHas006 * @tc.desc: Determine whether the HashSet instance contains the specified element. For example: hashSet.has(1). - * @tc.author: wangyong */ it("testHas006", 0, function () { let hashSet = new HashSet(); @@ -122,7 +116,6 @@ describe("HashSetTest", function () { /** * @tc.name: testIsEmpty007 * @tc.desc: Determine whether the HashSet instance is empty. For example: hashSet.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty007", 0, function () { let hashSet = new HashSet(); @@ -138,7 +131,6 @@ describe("HashSetTest", function () { /** * @tc.name: testRemove008 * @tc.desc: Delete the specified element. For example: hashSet.remove(1). - * @tc.author: wangyong */ it("testRemove008", 0, function () { let hashSet = new HashSet(); @@ -162,7 +154,6 @@ describe("HashSetTest", function () { /** * @tc.name: testClear009 * @tc.desc: Clear all elements of the HashSet instance. For example: hashSet.clear(). - * @tc.author: wangyong */ it("testClear009", 0, function () { let hashSet = new HashSet(); @@ -181,7 +172,6 @@ describe("HashSetTest", function () { /** * @tc.name: testValues010 * @tc.desc: Get a collection of all elements of a HashSet instance. For example: hashSet.values(). - * @tc.author: wangyong */ it("testValues010", 0, function () { let hashSet = new HashSet(); @@ -200,7 +190,6 @@ describe("HashSetTest", function () { /** * @tc.name: testForEach011 * @tc.desc: Traverse the collection of all elements of the HashSet instance. - * @tc.author: wangyong */ it("testForEach011", 0, function () { let hashSet = new HashSet(); @@ -223,7 +212,6 @@ describe("HashSetTest", function () { * @tc.name: testIterator012 * @tc.desc: Iterate over all elements of the HashSet instance. * For example: for (let item of hashSet) {arr.push(item);}. - * @tc.author: wangyong */ it("testIterator012", 0, function () { let hashSet = new HashSet(); @@ -246,7 +234,6 @@ describe("HashSetTest", function () { * @tc.name: testIterator013 * @tc.desc: Iterate over all elements of the HashSet instance. * For example: for (let item of hashSet) {arr.push(item);}. - * @tc.author: wangyong */ it("testIterator013", 0, function () { let hashSet = new HashSet(); @@ -268,7 +255,6 @@ describe("HashSetTest", function () { /** * @tc.name: testEntries014 * @tc.desc: Iterate over all elements of the HashSet instance. For example: hashSet.entries(). - * @tc.author: wangyong */ it("testEntries014", 0, function () { let hashSet = new HashSet(); @@ -287,7 +273,6 @@ describe("HashSetTest", function () { /** * @tc.name: testAdd015 * @tc.desc: Add element to HashSet instance. For example: hashSet.add(""). - * @tc.author: wangyong */ it("testAdd015", 0, function () { let hashSet = new HashSet(); @@ -299,7 +284,6 @@ describe("HashSetTest", function () { /** * @tc.name: testAdd016 * @tc.desc: Add element to HashSet instance. For example: hashSet.add("$"). - * @tc.author: wangyong */ it("testAdd016", 0, function () { let hashSet = new HashSet(); @@ -311,7 +295,6 @@ describe("HashSetTest", function () { /** * @tc.name: testAdd017 * @tc.desc: Add element to HashSet instance. For example: hashSet.add(1.34). - * @tc.author: wangyong */ it("testAdd017", 0, function () { let hashSet = new HashSet(); @@ -323,7 +306,6 @@ describe("HashSetTest", function () { /** * @tc.name: testAdd018 * @tc.desc: Add element to HashSet instance. For example: hashSet.add(-1). - * @tc.author: wangyong */ it("testAdd018", 0, function () { let hashSet = new HashSet(); @@ -335,7 +317,6 @@ describe("HashSetTest", function () { /** * @tc.name: testAdd019 * @tc.desc: Add element to HashSet instance. For example: let a = {}; hashSet.add(a). - * @tc.author: wangyong */ it("testAdd019", 0, function () { let hashSet = new HashSet(); @@ -348,7 +329,6 @@ describe("HashSetTest", function () { /** * @tc.name: testAdd020 * @tc.desc: Add element to HashSet instance. - * @tc.author: wangyong */ it("testAdd020", 0, function () { let hashSet = new HashSet(); @@ -364,7 +344,6 @@ describe("HashSetTest", function () { /** * @tc.name: testIterator021 * @tc.desc: Iterate over all elements of the HashSet instance. - * @tc.author: wangyong */ it("testIterator021", 0, function () { let hashSet = new HashSet(); @@ -378,7 +357,6 @@ describe("HashSetTest", function () { /** * @tc.name: testForEach022 * @tc.desc: Traverse the collection of all elements of the HashSet instance. - * @tc.author: wangyong */ it("testForEach022", 0, function () { let hashSet = new HashSet(); @@ -392,7 +370,6 @@ describe("HashSetTest", function () { /** * @tc.name: testIsEmpty023 * @tc.desc: Determine whether the HashSet instance is empty. For example: hashSet.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty023", 0, function () { let hashSet = new HashSet(); @@ -409,7 +386,6 @@ describe("HashSetTest", function () { /** * @tc.name:testHas024 * @tc.desc: Determine whether the HashSet instance contains the specified element. For example: hashSet.has(1). - * @tc.author: wangyong */ it("testHas024", 0, function () { let hashSet = new HashSet(); @@ -420,7 +396,6 @@ describe("HashSetTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Delete the specified element. For example: hashSet.remove(1). - * @tc.author: wangyong */ it("testRemove025", 0, function () { let hashSet = new HashSet(); @@ -431,7 +406,6 @@ describe("HashSetTest", function () { /** * @tc.name: testClear026 * @tc.desc: Clear all elements of the HashSet instance. For example: hashSet.clear(). - * @tc.author: wangyong */ it("testClear026", 0, function () { let hashSet = new HashSet(); @@ -442,7 +416,6 @@ describe("HashSetTest", function () { /** * @tc.name: testEntries027 * @tc.desc: Iterate over all elements of the HashSet instance. For example: hashSet.entries(). - * @tc.author: wangyong */ it("testEntries027", 0, function () { let hashSet = new HashSet(); @@ -453,7 +426,6 @@ describe("HashSetTest", function () { /** * @tc.name: testIterator028 * @tc.desc: Iterate over all elements of the HashSet instance. - * @tc.author: wangyong */ it("testIterator028", 0, function () { let hashSet = new HashSet(); @@ -474,7 +446,6 @@ describe("HashSetTest", function () { /** * @tc.name: testForEach029 * @tc.desc: Traverse the collection of all elements of the HashSet instance. - * @tc.author: wangyong */ it("testForEach029", 0, function () { let hashSet = new HashSet(); @@ -495,7 +466,6 @@ describe("HashSetTest", function () { /** * @tc.name: testAdd030 * @tc.desc: Add element to HashSet instance. For example: hashSet.add(1). - * @tc.author: wangyong */ it("testAdd030", 0, function () { let hashSet = new HashSet(); @@ -510,7 +480,6 @@ describe("HashSetTest", function () { /** * @tc.name: testIterator031 * @tc.desc: Iterate over all elements of the HashSet instance. For example: hashSet[Symbol.iterator](). - * @tc.author: wangyong */ it("testIterator031", 0, function () { let hashSet = new HashSet(); @@ -534,5 +503,42 @@ describe("HashSetTest", function () { expect(arr[i]).assertEqual(arr1[i]); } }); + + /** + * @tc.name: testHas032 + * @tc.desc: Determine whether the HashSet instance contains the specified element. For example: hashSet.has.bind({}, "a")(). + */ + it("testHas032", 0, function () { + let hashSet = new HashSet(); + hashSet.add(4); + hashSet.add(1); + hashSet.add(3); + hashSet.add(2); + hashSet.add(5); + try { + hashSet.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.name: testAdd033 + * @tc.desc: Add element to HashSet instance. For example: hashSet.add.bind({}, "a")(). + */ + it("testAdd033", 0, function () { + let hashSet = new HashSet(); + try { + hashSet.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`); + } + }); }); } diff --git a/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/LightWeightMap.test.js b/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/LightWeightMap.test.js index 00f1cd035cbc7085c32c17fa389de6a5a40bbe82..cc15e7503311b20013e94f03a00745885e507ab8 100644 --- a/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/LightWeightMap.test.js +++ b/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/LightWeightMap.test.js @@ -20,22 +20,21 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Create an LightWeightMap instance. For example: let lightWeightMap = new LightWeightMap(). - * @tc.author: wangyong */ it("testConstructor001", 0, function () { try { let lightWeightMap = new LightWeightMap(); expect(lightWeightMap != undefined).assertEqual(true); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("Cannot create new TreeMap"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200012); + expect(err.message).assertEqual("The LightWeightMap's constructor cannot be directly invoked"); } }); /** * @tc.name: testSet002 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. For example: lightWeightMap.set(1, "A"). - * @tc.author: wangyong */ it("testSet002", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -49,7 +48,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSet003 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. For example: lightWeightMap.set("a", "A"). - * @tc.author: wangyong */ it("testSet003", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -63,7 +61,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSet004 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. For example: lightWeightMap.set("a", "A"). - * @tc.author: wangyong */ it("testSet004", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -78,7 +75,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSet005 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. - * @tc.author: wangyong */ it("testSet005", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -93,7 +89,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testGet006 * @tc.desc: Get the corresponding value through the key. For example: lightWeightMap.get(4). - * @tc.author: wangyong */ it("testGet006", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -109,7 +104,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testLength007 * @tc.desc: Get the number of key value pairs in the lightWeightMap instance. For example: lightWeightMap.length. - * @tc.author: wangyong */ it("testLength007", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -125,7 +119,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testHasAll008 * @tc.desc: Judge whether a lightweightmap contains all key value pairs in another lightweightmap. - * @tc.author: wangyong */ it("testHasAll008", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -144,7 +137,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Determine whether the LightWeightMap contains the specified key. For example: lightWeightMap.hasKey("a"). - * @tc.author: wangyong */ it("testHasKey009", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -163,7 +155,6 @@ describe("LightWeightMapTest", function () { * @tc.name: testHasValue010 * @tc.desc: Determine whether the LightWeightMap contains the specified value. * For example: lightWeightMap.hasValue("A"). - * @tc.author: wangyong */ it("testHasValue010", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -182,7 +173,6 @@ describe("LightWeightMapTest", function () { * @tc.name: testIncreaseCapacityTo011 * @tc.desc: Expand the LightWeightMap instance capacity to the specified value. * For example: lightWeightMap.increaseCapacityTo(3). - * @tc.author: wangyong */ it("testIncreaseCapacityTo011", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -199,7 +189,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testEntries012 * @tc.desc: Get all key value pairs collection in lightWeightMap. - * @tc.author: wangyong */ it("testEntries012", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -220,7 +209,6 @@ describe("LightWeightMapTest", function () { * @tc.name: testGetIndexOfKey013 * @tc.desc: Find the index of the key value pair according to the corresponding key. * If no key is specified, return -1. - * @tc.author: wangyong */ it("testGetIndexOfKey013", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -237,7 +225,6 @@ describe("LightWeightMapTest", function () { * @tc.name: testGetIndexOfValue014 * @tc.desc: Find the index of the key value pair according to the corresponding value. * If no key is specified, return -1. - * @tc.author: wangyong */ it("testGetIndexOfValue014", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -254,7 +241,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testIsEmpty015 * @tc.desc: Determine whether the LightWeightMap instance is empty. For example: lightWeightMap.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty015", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -273,7 +259,6 @@ describe("LightWeightMapTest", function () { * @tc.name: testGetKeyAt016 * @tc.desc: Find the key of the key value pair according to the corresponding index. * For example: lightWeightMap.getKeyAt(1). - * @tc.author: wangyong */ it("testGetKeyAt016", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -289,7 +274,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testKeys017 * @tc.desc: Get a collection of all the keys in the LightWeightMap. For example: lightWeightMap.keys(). - * @tc.author: wangyong */ it("testKeys017", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -309,7 +293,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSetAll018 * @tc.desc: Copy key value pairs from one LightWeightMap to another. - * @tc.author: wangyong */ it("testSetAll018", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -330,7 +313,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testRemove019 * @tc.desc: Delete key value pairs according to key. For example: lightWeightMap.remove(3). - * @tc.author: wangyong */ it("testRemove019", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -348,7 +330,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testRemoveAt020 * @tc.desc: Delete key value pairs according to index. For example: lightWeightMap.removeAt(1). - * @tc.author: wangyong */ it("testRemoveAt020", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -370,7 +351,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testClear021 * @tc.desc: Clear all key value pairs in LightWeightMap. For example: lightWeightMap.clear(). - * @tc.author: wangyong */ it("testClear021", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -390,7 +370,6 @@ describe("LightWeightMapTest", function () { * @tc.name: testSetValueAt022 * @tc.desc: Modify the value of the key value pair according to the corresponding index. * For example: setValueAt(0, "a"). - * @tc.author: wangyong */ it("testSetValueAt022", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -407,7 +386,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testForEach023 * @tc.desc: Traverse all key value pairs in the LightWeightMap instance. - * @tc.author: wangyong */ it("testForEach023", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -430,7 +408,6 @@ describe("LightWeightMapTest", function () { * @tc.name: testToString024 * @tc.desc: Use "," to splice the elements in the LightWeightMap instance into a string. * For example: lightWeightMap.toString(). - * @tc.author: wangyong */ it("testToString024", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -444,7 +421,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testValues025 * @tc.desc: Get a collection of all the values in the LightWeightMap. For example: lightWeightMap.values(). - * @tc.author: wangyong */ it("testValues025", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -465,7 +441,6 @@ describe("LightWeightMapTest", function () { * @tc.name: testGetValueAt026 * @tc.desc: Get the value of the key value pair according to the corresponding index. * For example: lightWeightMap.getValueAt(1). - * @tc.author: wangyong */ it("testGetValueAt026", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -481,7 +456,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testIterator027 * @tc.desc: Iterate over all key value pairs in the LightWeightMap. - * @tc.author: wangyong */ it("testIterator027", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -506,7 +480,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSet028 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. For example: lightWeightMap.set(1, null). - * @tc.author: wangyong */ it("testSet028", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -520,7 +493,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSet029 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. For example: lightWeightMap.set(null, null). - * @tc.author: wangyong */ it("testSet029", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -534,7 +506,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSet030 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. For example: lightWeightMap.set(true, false). - * @tc.author: wangyong */ it("testSet030", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -548,7 +519,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSet031 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. For example: lightWeightMap.set(1.23, 321). - * @tc.author: wangyong */ it("testSet031", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -562,7 +532,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testHasAll032 * @tc.desc: Judge whether a lightweightmap contains all key value pairs in another lightweightmap. - * @tc.author: wangyong */ it("testHasAll032", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -581,7 +550,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testHasAll033 * @tc.desc: Judge whether a lightweightmap contains all key value pairs in another lightweightmap. - * @tc.author: wangyong */ it("testHasAll033", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -600,7 +568,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testRemove034 * @tc.desc: Delete key value pairs according to key. For example: lightWeightMap.remove(3). - * @tc.author: wangyong */ it("testRemove034", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -611,7 +578,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testRemoveAt035 * @tc.desc: Delete key value pairs according to index. For example: lightWeightMap.removeAt(1). - * @tc.author: wangyong */ it("testRemoveAt035", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -623,7 +589,6 @@ describe("LightWeightMapTest", function () { * @tc.name: testIncreaseCapacityTo036 * @tc.desc: Expand the LightWeightMap instance capacity to the specified value. * For example: lightWeightMap.increaseCapacityTo(10). - * @tc.author: wangyong */ it("testIncreaseCapacityTo036", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -640,7 +605,6 @@ describe("LightWeightMapTest", function () { * @tc.name: testIncreaseCapacityTo037 * @tc.desc: Expand the LightWeightMap instance capacity to the specified value. * For example: lightWeightMap.increaseCapacityTo("qwe"). - * @tc.author: wangyong */ it("testIncreaseCapacityTo037", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -651,32 +615,34 @@ describe("LightWeightMapTest", function () { lightWeightMap.set("e", "E"); try { lightWeightMap.increaseCapacityTo("qwe"); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("the size is not integer"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "minimumCapacity" must be number. Received value is: qwe`); } }); /** * @tc.name: testRemoveAt038 - * @tc.desc: Delete key value pairs according to index. For example: lightWeightMap.removeAt("123"). - * @tc.author: wangyong + * @tc.desc: Delete key value pairs according to index. For example: lightWeightMap.removeAt("a"). */ it("testRemoveAt038", 0, function () { let lightWeightMap = new LightWeightMap(); try { - let res = lightWeightMap.removeAt("123"); + let res = lightWeightMap.removeAt("a"); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("index is not integer"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); } }); /** * @tc.name: testGetValueAt039 * @tc.desc: Get the value of the key value pair according to the corresponding index. - * For example: lightWeightMap.getValueAt("123"). - * @tc.author: wangyong + * For example: lightWeightMap.getValueAt("a"). */ it("testGetValueAt039", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -686,18 +652,19 @@ describe("LightWeightMapTest", function () { lightWeightMap.set(4, "D"); lightWeightMap.set(5, "E"); try { - let res = lightWeightMap.getValueAt("123"); + let res = lightWeightMap.getValueAt("a"); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("the index is not integer"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); } }); /** * @tc.name: testGetKeyAt040 * @tc.desc: Find the key of the key value pair according to the corresponding index. - * For example: lightWeightMap.getKeyAt("123"). - * @tc.author: wangyong + * For example: lightWeightMap.getKeyAt("a"). */ it("testGetKeyAt040", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -707,17 +674,18 @@ describe("LightWeightMapTest", function () { lightWeightMap.set(4, "D"); lightWeightMap.set(5, "E"); try { - let res = lightWeightMap.getKeyAt("123"); + let res = lightWeightMap.getKeyAt("a"); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("the index is not integer"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); } }); /** * @tc.name: testConstructor001 * @tc.desc: Judge whether a lightweightmap contains all key value pairs in another lightweightmap. - * @tc.author: wangyong */ it("testHasAll041", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -729,7 +697,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSet042 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. - * @tc.author: wangyong */ it("testSet042", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -745,7 +712,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSet043 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. - * @tc.author: wangyong */ it("testSet043", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -761,7 +727,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSet044 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. - * @tc.author: wangyong */ it("testSet044", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -781,7 +746,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSet045 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. - * @tc.author: wangyong */ it("testSet045", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -810,7 +774,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSet046 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. - * @tc.author: wangyong */ it("testSet046", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -824,7 +787,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSet047 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. - * @tc.author: wangyong */ it("testSet047", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -839,7 +801,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testSet048 * @tc.desc: Add a pair of key value pairs to the LightWeightMap. - * @tc.author: wangyong */ it("testSet048", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -854,7 +815,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testGet049 * @tc.desc: Get the corresponding value through the key. For example: lightWeightMap.get(10). - * @tc.author: wangyong */ it("testGet049", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -870,7 +830,6 @@ describe("LightWeightMapTest", function () { /** * @tc.name: testHasAll050 * @tc.desc: Judge whether a lightweightmap contains all key value pairs in another lightweightmap. - * @tc.author: wangyong */ it("testHasAll050", 0, function () { let lightWeightMap = new LightWeightMap(); @@ -885,5 +844,121 @@ describe("LightWeightMapTest", function () { let res = lightWeightMap.hasAll(lightWeightMap1); expect(res).assertEqual(false); }); + + /** + * @tc.name: testHasAll051 + * @tc.desc: Judge whether a lightweightmap contains all key value pairs in another lightweightmap. + */ + it("testHasAll051", 0, function () { + let lightWeightMap = new LightWeightMap(); + try { + lightWeightMap.hasAll([1, 2, 3]); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "map" must be LightWeightMap. Received value is: 1,2,3`); + } + }); + + /** + * @tc.name: testGetKeyAt052 + * @tc.desc: Find the key of the key value pair according to the corresponding index. + * For example: lightWeightMap.getKeyAt(6). + */ + it("testGetKeyAt052", 0, function () { + let lightWeightMap = new LightWeightMap(); + lightWeightMap.set(1, "A"); + lightWeightMap.set(2, "B"); + lightWeightMap.set(3, "C"); + lightWeightMap.set(4, "D"); + lightWeightMap.set(5, "E"); + try { + let res = lightWeightMap.getKeyAt(6); + 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: 6`); + } + }); + + /** + * @tc.name: testSetAll053 + * @tc.desc: Copy key value pairs from one LightWeightMap to another. + */ + it("testSetAll053", 0, function () { + let lightWeightMap = new LightWeightMap(); + lightWeightMap.set(1, "A"); + lightWeightMap.set(2, "B"); + try { + lightWeightMap.setAll([1, 2, 3]); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "map" must be LightWeightMap. Received value is: 1,2,3`); + } + }); + + /** + * @tc.name: testSetValueAt054 + * @tc.desc: Modify the value of the key value pair according to the corresponding index. + * For example: lightWeightMap.setValueAt("a", "a"). + */ + it("testSetValueAt054", 0, function () { + let lightWeightMap = new LightWeightMap(); + lightWeightMap.set(1, "A"); + lightWeightMap.set(2, "B"); + try { + lightWeightMap.setValueAt("a", "a"); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); + } + }); + + /** + * @tc.name: testSetValueAt055 + * @tc.desc: Modify the value of the key value pair according to the corresponding index. + * For example: lightWeightMap.setValueAt(3, "a"). + */ + it("testSetValueAt055", 0, function () { + let lightWeightMap = new LightWeightMap(); + lightWeightMap.set(1, "A"); + lightWeightMap.set(2, "B"); + try { + lightWeightMap.setValueAt(3, "a"); + 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 && <= 1. Received value is: 3`); + } + }); + + /** + * @tc.name: testGetValueAt056 + * @tc.desc: Get the value of the key value pair according to the corresponding index. + * For example: lightWeightMap.getValueAt(6). + */ + it("testGetValueAt056", 0, function () { + let lightWeightMap = new LightWeightMap(); + lightWeightMap.set(1, "A"); + lightWeightMap.set(2, "B"); + lightWeightMap.set(3, "C"); + lightWeightMap.set(4, "D"); + lightWeightMap.set(5, "E"); + try { + lightWeightMap.getValueAt(6); + 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: 6`); + } + }); }); } diff --git a/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/LightWeightSet.test.js b/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/LightWeightSet.test.js index 7630ffa7cdf330a2961fc78df3071c17ba8ee421..50e5cd69189ac2031f7f61f25f64955b9ef22cdd 100644 --- a/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/LightWeightSet.test.js +++ b/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/LightWeightSet.test.js @@ -20,22 +20,21 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Create an LightWeightSet instance. For example: let lightWeightSet = new LightWeightSet(). - * @tc.author: wangyong */ it("testConstructor001", 0, function () { try { let lightWeightSet = new LightWeightSet(); expect(lightWeightSet != undefined).assertEqual(true); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("Cannot create new TreeMap"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200012); + expect(err.message).assertEqual("The LightWeightSet's constructor cannot be directly invoked"); } }); /** * @tc.name: testAdd002 * @tc.desc: Add element to LightWeightSet instance. For example: lightWeightSet.add(1). - * @tc.author: wangyong */ it("testAdd002", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -47,7 +46,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testAdd003 * @tc.desc: Add element to LightWeightSet instance. For example: lightWeightSet.add("a"). - * @tc.author: wangyong */ it("testAdd003", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -60,7 +58,6 @@ describe("LightWeightSetTest", function () { * @tc.name: testAdd004 * @tc.desc: Add element to LightWeightSet instance. * For example: let a = [1, 2, 3, 4]; lightWeightSet.add(a). - * @tc.author: wangyong */ it("testAdd004", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -74,7 +71,6 @@ describe("LightWeightSetTest", function () { * @tc.name: testAdd005 * @tc.desc: Add element to LightWeightSet instance. * For example: let a = {name: "lili", age: "13"}; lightWeightSet.add(a). - * @tc.author: wangyong */ it("testAdd005", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -87,7 +83,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testAdd006 * @tc.desc: Add element to LightWeightSet instance. For example: let c = false; lightWeightSet.add(c). - * @tc.author: wangyong */ it("testAdd006", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -100,7 +95,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testLength007 * @tc.desc: Get the number of element in the LightWeightSet instance. For example: lightWeightSet.length. - * @tc.author: wangyong */ it("testLength007", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -116,7 +110,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testAddAll008 * @tc.desc: Copy all element from one LightWeightSet to another. - * @tc.author: wangyong */ it("testAddAll008", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -144,7 +137,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testHasAll009 * @tc.desc: Judge whether a lightWeightSet contains all elements in another lightWeightSet. - * @tc.author: wangyong */ it("testHasAll009", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -163,7 +155,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testHasAll010 * @tc.desc: Judge whether a lightWeightSet contains all elements in another lightWeightSet. - * @tc.author: wangyong */ it("testHasAll010", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -181,7 +172,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testHas011 * @tc.desc: Judge whether a lightWeightSet contains all elements in another lightWeightSet. - * @tc.author: wangyong */ it("testHas011", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -199,7 +189,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testEntries012 * @tc.desc: Get all key value pairs collection in lightWeightSet. - * @tc.author: wangyong */ it("testEntries012", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -219,7 +208,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testGetIndexOf013 * @tc.desc: Get the index according to the specified element. For example: lightWeightSet.getIndexOf(2). - * @tc.author: wangyong */ it("testGetIndexOf013", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -235,7 +223,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testIsEmpty014 * @tc.desc: Determine whether the lightWeightSet instance is empty. For example: lightWeightSet.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty014", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -251,7 +238,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testRemove015 * @tc.desc: Delete elements according to key. For example: lightWeightMap.remove(1). - * @tc.author: wangyong */ it("testRemove015", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -275,7 +261,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testRemoveAt016 * @tc.desc: Delete elements according to index. For example: lightWeightSet.removeAt(1). - * @tc.author: wangyong */ it("testRemoveAt016", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -299,7 +284,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testClear017 * @tc.desc: Clear all elements in LightWeightSet. For example: lightWeightSet.clear(). - * @tc.author: wangyong */ it("testClear017", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -316,7 +300,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testForEach018 * @tc.desc: Traverse all elements in the LightWeightSet instance. - * @tc.author: wangyong */ it("testForEach018", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -339,7 +322,6 @@ describe("LightWeightSetTest", function () { * @tc.name: testToString019 * @tc.desc: Use "," to splice the elements in the LightWeightSet instance into a string. * For example: lightWeightSet.toString(). - * @tc.author: wangyong */ it("testToString019", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -353,7 +335,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testToArray020 * @tc.desc: Convert an lightWeightSet instance to an array. For example: lightWeightSet.toArray(). - * @tc.author: wangyong */ it("testToArray020", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -372,7 +353,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testGetValueAt021 * @tc.desc: Get the element according to the corresponding index. For example: lightWeightSet.getValueAt(1). - * @tc.author: wangyong */ it("testGetValueAt021", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -388,7 +368,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testIterator022 * @tc.desc: Iterate over all elements in the LightWeightSet. - * @tc.author: wangyong */ it("testIterator022", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -410,7 +389,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testValues023 * @tc.desc: Get a collection of all the values in the LightWeightSet. For example: lightWeightSet.values(). - * @tc.author: wangyong */ it("testValues023", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -430,7 +408,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testAdd024 * @tc.desc: Add element to LightWeightSet instance. For example: lightWeightSet.add(null). - * @tc.author: wangyong */ it("testAdd024", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -442,7 +419,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testAdd025 * @tc.desc: Add element to LightWeightSet instance. For example: lightWeightSet.add(1.23). - * @tc.author: wangyong */ it("testAdd025", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -454,7 +430,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testHasAll026 * @tc.desc: Judge whether a lightWeightSet contains all elements in another lightWeightSet. - * @tc.author: wangyong */ it("testHasAll026", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -473,7 +448,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testHasAll027 * @tc.desc: Judge whether a lightWeightSet contains all elements in another lightWeightSet. - * @tc.author: wangyong */ it("testHasAll027", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -492,7 +466,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testRemove028 * @tc.desc: Delete elements according to key. For example: lightWeightMap.remove(3). - * @tc.author: wangyong */ it("testRemove028", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -503,7 +476,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testRemoveAt029 * @tc.desc: Delete elements according to index. For example: lightWeightSet.removeAt(1). - * @tc.author: wangyong */ it("testRemoveAt029", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -515,7 +487,6 @@ describe("LightWeightSetTest", function () { * @tc.name: testIncreaseCapacityTo030 * @tc.desc: Expand the LightWeightSet capacity to the specified value. * For example: lightWeightSet.increaseCapacityTo(3). - * @tc.author: wangyong */ it("testIncreaseCapacityTo030", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -526,9 +497,11 @@ describe("LightWeightSetTest", function () { lightWeightSet.add(5); try { lightWeightSet.increaseCapacityTo(3); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("the index is not integer"); + 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`); } }); @@ -536,7 +509,6 @@ describe("LightWeightSetTest", function () { * @tc.name: testIncreaseCapacityTo031 * @tc.desc: Expand the LightWeightSet capacity to the specified value. * For example: lightWeightSet.increaseCapacityTo("qwe"). - * @tc.author: wangyong */ it("testIncreaseCapacityTo031", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -547,24 +519,27 @@ describe("LightWeightSetTest", function () { lightWeightSet.add(5); try { let res = lightWeightSet.increaseCapacityTo("qwe"); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("the index is not integer"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "minimumCapacity" must be number. Received value is: qwe`); } }); /** * @tc.name: testRemoveAt032 - * @tc.desc: Delete elements according to index. For example: lightWeightSet.removeAt("123"). - * @tc.author: wangyong + * @tc.desc: Delete elements according to index. For example: lightWeightSet.removeAt("a"). */ it("testRemoveAt032", 0, function () { let lightWeightSet = new LightWeightSet(); try { - let res = lightWeightSet.removeAt("123"); + let res = lightWeightSet.removeAt("a"); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("the index is not integer"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); } }); @@ -572,7 +547,6 @@ describe("LightWeightSetTest", function () { * @tc.name: testIncreaseCapacityTo033 * @tc.desc: Expand the LightWeightSet capacity to the specified value. * For example: lightWeightSet.increaseCapacityTo(20). - * @tc.author: wangyong */ it("testIncreaseCapacityTo033", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -587,8 +561,7 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testGetValueAt034 - * @tc.desc: Get the element according to the corresponding index. For example: lightWeightSet.getValueAt("123"). - * @tc.author: wangyong + * @tc.desc: Get the element according to the corresponding index. For example: lightWeightSet.getValueAt("a"). */ it("testGetValueAt034", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -598,17 +571,18 @@ describe("LightWeightSetTest", function () { lightWeightSet.add(4); lightWeightSet.add(5); try { - let res = lightWeightSet.getValueAt("123"); + let res = lightWeightSet.getValueAt("a"); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("the index is not integer"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); } }); /** * @tc.name: testIsEmpty035 * @tc.desc: Determine whether the lightWeightSet instance is empty. For example: lightWeightSet.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty035", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -625,7 +599,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testAdd036 * @tc.desc: Add element to LightWeightSet instance. - * @tc.author: wangyong */ it("testAdd036", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -641,7 +614,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testAdd037 * @tc.desc: Add element to LightWeightSet instance. For example: lightWeightSet.add(""). - * @tc.author: wangyong */ it("testAdd037", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -653,7 +625,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testAdd038 * @tc.desc: Add element to LightWeightSet instance. For example: lightWeightSet.add("$"). - * @tc.author: wangyong */ it("testAdd038", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -665,7 +636,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testClear039 * @tc.desc: Clear all elements in LightWeightSet. For example: lightWeightSet.clear(). - * @tc.author: wangyong */ it("testClear039", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -684,7 +654,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testRemove040 * @tc.desc: Delete elements according to key. For example: lightWeightMap.remove("A"). - * @tc.author: wangyong */ it("testRemove040", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -693,18 +662,13 @@ describe("LightWeightSetTest", function () { lightWeightSet.add(3); lightWeightSet.add(4); lightWeightSet.add(5); - try { - let res = lightWeightSet.remove("A"); - } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("the index is not integer"); - } + let res = lightWeightSet.remove("A"); + expect(res).assertEqual(undefined); }); /** * @tc.name: testIterator41 * @tc.desc: Iterate over all elements in the LightWeightSet. - * @tc.author: wangyong */ it("testIterator41", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -729,7 +693,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testEqual42 * @tc.desc: Compare lightweightmap and specified object for equality. For example: lightWeightSet.equal(obj). - * @tc.author: wangyong */ it("testEqual42", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -744,7 +707,6 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testEqual43 * @tc.desc: Compare lightweightmap and specified object for equality. For example: lightWeightSet.equal(obj). - * @tc.author: wangyong */ it("testEqual43", 0, function () { let lightWeightSet = new LightWeightSet(); @@ -755,5 +717,43 @@ describe("LightWeightSetTest", function () { let res = lightWeightSet.equal(obj); expect(res).assertEqual(false); }); + + /** + * @tc.name: testAddAll044 + * @tc.desc: Copy all element from one LightWeightSet to another. + */ + it("testAddAll044", 0, function () { + let lightWeightSet = new LightWeightSet(); + lightWeightSet.add(1); + lightWeightSet.add(2); + lightWeightSet.add(3); + try { + lightWeightSet.addAll([1, 2, 3]); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "set" must be LightWeightSet. Received value is: 1,2,3`); + } + }); + + /** + * @tc.name: testHasAll045 + * @tc.desc: Judge whether a lightWeightSet contains all elements in another lightWeightSet. + */ + it("testHasAll045", 0, function () { + let lightWeightSet = new LightWeightSet(); + lightWeightSet.add("a"); + lightWeightSet.add("b"); + lightWeightSet.add("c"); + try { + lightWeightSet.hasAll([1, 2, 3]); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "set" must be LightWeightSet. Received value is: 1,2,3`); + } + }); }); } diff --git a/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/PlainArray.test.js b/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/PlainArray.test.js index c4ff4af7bbd645d4edcc93d64d81e6d262170042..c57ace6880fe56e846aed3f9f884bcb05be01316 100644 --- a/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/PlainArray.test.js +++ b/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/PlainArray.test.js @@ -20,21 +20,20 @@ describe("PlainArrayTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Create an PlainArray instance. For example: let plainArray = new PlainArray(). - * @tc.author: wangyong */ it("testConstructor001", 0, function () { try { let plainArray = new PlainArray(); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("Cannot create new PlainArray"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200012); + expect(err.message).assertEqual("The PlainArray's constructor cannot be directly invoked"); } }); /** * @tc.name: testAdd002 * @tc.desc: Add a pair of key value pairs to the PlainArray. For example: plainArray.add(1, "A"). - * @tc.author: wangyong */ it("testAdd002", 0, function () { let plainArray = new PlainArray(); @@ -46,7 +45,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testAdd003 * @tc.desc: Add a pair of key value pairs to the PlainArray. - * @tc.author: wangyong */ it("testAdd003", 0, function () { let plainArray = new PlainArray(); @@ -59,7 +57,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testAdd004 * @tc.desc: Add a pair of key value pairs to the PlainArray. - * @tc.author: wangyong */ it("testAdd004", 0, function () { let plainArray = new PlainArray(); @@ -72,7 +69,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testAdd005 * @tc.desc: Add a pair of key value pairs to the PlainArray. - * @tc.author: wangyong */ it("testAdd005", 0, function () { let plainArray = new PlainArray(); @@ -85,7 +81,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testAdd006 * @tc.desc: Add a pair of key value pairs to the PlainArray. - * @tc.author: wangyong */ it("testAdd006", 0, function () { let plainArray = new PlainArray(); @@ -97,7 +92,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testGet007 * @tc.desc: Get the corresponding value through the key. For example: plainArray.get(4). - * @tc.author: wangyong */ it("testGet007", 0, function () { let plainArray = new PlainArray(); @@ -115,7 +109,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testLength008 * @tc.desc: Get the number of key value pairs in the PlainArray instance. For example: plainArray.length. - * @tc.author: wangyong */ it("testLength008", 0, function () { let plainArray = new PlainArray(); @@ -133,7 +126,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testClone009 * @tc.desc: Clone an PlainArray instance. For example: plainArray.clone(). - * @tc.author: wangyong */ it("testClone009", 0, function () { let plainArray = new PlainArray(); @@ -159,7 +151,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testClear010 * @tc.desc: Clear all key value pairs in PlainArray. For example: plainArray.clear(). - * @tc.author: wangyong */ it("testClear010", 0, function () { let plainArray = new PlainArray(); @@ -180,8 +171,7 @@ describe("PlainArrayTest", function () { /** * @tc.name: testHas011 - * @tc.desc: Check whether the PlainArray contains a specified element. For example: plainArray.has("a"). - * @tc.author: wangyong + * @tc.desc: Check whether the PlainArray contains a specified element. For example: plainArray.has(6). */ it("testHas011", 0, function () { let plainArray = new PlainArray(); @@ -190,7 +180,7 @@ describe("PlainArrayTest", function () { plainArray.add(3, "C"); plainArray.add(4, "D"); plainArray.add(5, "E"); - let res = plainArray.has("a"); + let res = plainArray.has(6); expect(res).assertEqual(false); let res1 = plainArray.has(1); expect(res1).assertEqual(true); @@ -200,7 +190,6 @@ describe("PlainArrayTest", function () { * @tc.name: testGetIndexOfKey012 * @tc.desc: Find the index of the key value pair according to the corresponding key. * If no key is specified, return -1. - * @tc.author: wangyong */ it("testGetIndexOfKey012", 0, function () { let plainArray = new PlainArray(); @@ -219,7 +208,6 @@ describe("PlainArrayTest", function () { * @tc.name: testGetIndexOfValue013 * @tc.desc: Find the index of the key value pair according to the corresponding value. * If no key is specified, return -1. - * @tc.author: wangyong */ it("testGetIndexOfValue013", 0, function () { let plainArray = new PlainArray(); @@ -237,7 +225,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testIsEmpty014 * @tc.desc: Determine whether the PlainArray instance is empty. For example: plainArray.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty014", 0, function () { let plainArray = new PlainArray(); @@ -256,7 +243,6 @@ describe("PlainArrayTest", function () { * @tc.name: testGetKeyAt015 * @tc.desc: Find the key of the key value pair according to the corresponding index. * For example: plainArray.getKeyAt(2). - * @tc.author: wangyong */ it("testGetKeyAt015", 0, function () { let plainArray = new PlainArray(); @@ -267,14 +253,11 @@ describe("PlainArrayTest", function () { plainArray.add(5, "E"); let res = plainArray.getKeyAt(2); expect(res).assertEqual(3); - res = plainArray.getKeyAt(10); - expect(res).assertEqual(undefined); }); /** * @tc.name: testReMove016 * @tc.desc: Delete key value pairs according to key. For example: plainArray.remove(2). - * @tc.author: wangyong */ it("testReMove016", 0, function () { let plainArray = new PlainArray(); @@ -294,7 +277,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testReMoveAt017 * @tc.desc: Delete key value pairs according to index. For example: plainArray.removeAt(2). - * @tc.author: wangyong */ it("testReMoveAt017", 0, function () { let plainArray = new PlainArray(); @@ -307,15 +289,12 @@ describe("PlainArrayTest", function () { expect(res).assertEqual("C"); let value = plainArray.get(3); expect(value).assertEqual(undefined); - res = plainArray.removeAt(12); - expect(res).assertEqual(undefined); }); /** * @tc.name: testReMoveRangeFrom018 * @tc.desc: Deletes the specified number of elements from the specified starting index. * For example: plainArray.removeRangeFrom(2, 2). - * @tc.author: wangyong */ it("testReMoveRangeFrom018", 0, function () { let plainArray = new PlainArray(); @@ -332,15 +311,19 @@ describe("PlainArrayTest", function () { } try { plainArray.removeRangeFrom(15, 5); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - expect(err.message).assertEqual("the index is out-of-bounds"); + 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: 15`); } try { - plainArray.removeRangeFrom(1, -1); + plainArray.removeRangeFrom(1, "a"); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("the size cannot be less than 0"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "size" must be number. Received value is: a`); } }); @@ -348,7 +331,6 @@ describe("PlainArrayTest", function () { * @tc.name: testSetValueAt019 * @tc.desc: Modify the value of the key value pair according to the corresponding index. * For example: plainArray.setValueAt(2, "V"). - * @tc.author: wangyong */ it("testSetValueAt019", 0, function () { let plainArray = new PlainArray(); @@ -365,9 +347,11 @@ describe("PlainArrayTest", function () { } try { plainArray.setValueAt(-1, "X"); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - expect(err.message).assertEqual("the index is out-of-bounds"); + 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`); } }); @@ -375,7 +359,6 @@ describe("PlainArrayTest", function () { * @tc.name: testToString020 * @tc.desc: Use "," to splice the elements in the LightWeightMap instance into a string. * For example: plainArray.toString(). - * @tc.author: wangyong */ it("testToString020", 0, function () { let plainArray = new PlainArray(); @@ -391,7 +374,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testForEach021 * @tc.desc: Traverse all key value pairs in the PlainArray instance. - * @tc.author: wangyong */ it("testForEach021", 0, function () { let plainArray = new PlainArray(); @@ -413,7 +395,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testIterator022 * @tc.desc: Iterate over all key value pairs in the PlainArray. - * @tc.author: wangyong */ it("testIterator022", 0, function () { let plainArray = new PlainArray(); @@ -433,7 +414,6 @@ describe("PlainArrayTest", function () { * @tc.name: testGetValueAt023 * @tc.desc: Get the value of the key value pair according to the corresponding index. * For example: plainArray.getValueAt(2). - * @tc.author: wangyong */ it("testGetValueAt023", 0, function () { let plainArray = new PlainArray(); @@ -444,14 +424,11 @@ describe("PlainArrayTest", function () { plainArray.add(5, "E"); let res = plainArray.getValueAt(2); expect(res).assertEqual("C"); - res = plainArray.getValueAt(12); - expect(res).assertEqual(undefined); }); /** * @tc.name: testAdd024 * @tc.desc: Add a pair of key value pairs to the PlainArray.For example: plainArray.add(1, 3.1). - * @tc.author: wangyong */ it("testAdd024", 0, function () { let plainArray = new PlainArray(); @@ -463,7 +440,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testAdd025 * @tc.desc: Add a pair of key value pairs to the PlainArray.For example: plainArray.add(1, null). - * @tc.author: wangyong */ it("testAdd025", 0, function () { let plainArray = new PlainArray(); @@ -474,23 +450,23 @@ describe("PlainArrayTest", function () { /** * @tc.name: testAdd026 - * @tc.desc: Add a pair of key value pairs to the PlainArray.For example: plainArray.add("123", null). - * @tc.author: wangyong + * @tc.desc: Add a pair of key value pairs to the PlainArray.For example: plainArray.add("a", null). */ it("testAdd026", 0, function () { let plainArray = new PlainArray(); try { - let res = plainArray.add("123", null); + let res = plainArray.add("a", null); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("the index is not integer"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "key" must be number. Received value is: a`); } }); /** * @tc.name: testGet027 * @tc.desc: Get the corresponding value through the key. For example: plainArray.get(8). - * @tc.author: wangyong */ it("testGet027", 0, function () { let plainArray = new PlainArray(); @@ -507,7 +483,6 @@ describe("PlainArrayTest", function () { * @tc.name: testGetIndexOfKey028 * @tc.desc: Find the index of the key value pair according to the corresponding key. * If no key is specified, return -1. - * @tc.author: wangyong */ it("testGetIndexOfKey028", 0, function () { let plainArray = new PlainArray(); @@ -524,7 +499,6 @@ describe("PlainArrayTest", function () { * @tc.name: testGetIndexOfValue029 * @tc.desc: Find the index of the key value pair according to the corresponding value. * If no key is specified, return -1. - * @tc.author: wangyong */ it("testGetIndexOfValue029", 0, function () { let plainArray = new PlainArray(); @@ -541,7 +515,6 @@ describe("PlainArrayTest", function () { * @tc.name: testGetKeyAt030 * @tc.desc: Find the key of the key value pair according to the corresponding index. * For example: plainArray.getKeyAt(50). - * @tc.author: wangyong */ it("testGetKeyAt030", 0, function () { let plainArray = new PlainArray(); @@ -558,7 +531,6 @@ describe("PlainArrayTest", function () { * @tc.name: testGetValueAt031 * @tc.desc: Find the value of the key value pair according to the corresponding index. * For example: plainArray.getValueAt(50). - * @tc.author: wangyong */ it("testGetValueAt031", 0, function () { let plainArray = new PlainArray(); @@ -567,14 +539,19 @@ describe("PlainArrayTest", function () { plainArray.add(3, "C"); plainArray.add(4, "D"); plainArray.add(5, "E"); - let res = plainArray.getValueAt(50); - expect(res).assertEqual(undefined); + try { + plainArray.getValueAt(50); + 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: 50`); + } }); /** * @tc.name: testRemove032 * @tc.desc: Delete key value pairs according to key. For example: plainArray.remove(2). - * @tc.author: wangyong */ it("testRemove032", 0, function () { let plainArray = new PlainArray(); @@ -584,16 +561,17 @@ describe("PlainArrayTest", function () { /** * @tc.name: testRemoveAt033 - * @tc.desc: Delete key value pairs according to index. For example: plainArray.removeAt(2). - * @tc.author: wangyong + * @tc.desc: Delete key value pairs according to index. For example: plainArray.removeAt("a"). */ it("testRemoveAt033", 0, function () { let plainArray = new PlainArray(); try { - let res = plainArray.removeAt(2); + let res = plainArray.removeAt("a"); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - expect(err.message).assertEqual("the index is out-of-bounds"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); } }); @@ -601,7 +579,6 @@ describe("PlainArrayTest", function () { * @tc.name: testReMoveRangeFrom034 * @tc.desc: Deletes the specified number of elements from the specified starting index. * For example: plainArray.removeRangeFrom(0, 5). - * @tc.author: wangyong */ it("testReMoveRangeFrom034", 0, function () { let plainArray = new PlainArray(); @@ -619,7 +596,6 @@ describe("PlainArrayTest", function () { * @tc.name: testSetValueAt035 * @tc.desc: Modify the value of the key value pair according to the corresponding index. * For example: plainArray.setValueAt(8, "V"). - * @tc.author: wangyong */ it("testSetValueAt035", 0, function () { let plainArray = new PlainArray(); @@ -630,16 +606,17 @@ describe("PlainArrayTest", function () { plainArray.add(5, "E"); try { plainArray.setValueAt(8, "V"); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("RangeError"); - expect(err.message).assertEqual("the index is out-of-bounds"); + 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: 8`); } }); /** * @tc.name: testAdd036 * @tc.desc: Add a pair of key value pairs to the PlainArray. - * @tc.author: wangyong */ it("testAdd036", 0, function () { let plainArray = new PlainArray(); @@ -655,7 +632,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testAdd037 * @tc.desc: Add a pair of key value pairs to the PlainArray. - * @tc.author: wangyong */ it("testAdd037", 0, function () { let plainArray = new PlainArray(); @@ -671,7 +647,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testAdd038 * @tc.desc: Add a pair of key value pairs to the PlainArray. - * @tc.author: wangyong */ it("testAdd038", 0, function () { let plainArray = new PlainArray(); @@ -687,7 +662,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testAdd039 * @tc.desc: Add a pair of key value pairs to the PlainArray. - * @tc.author: wangyong */ it("testAdd039", 0, function () { let plainArray = new PlainArray(); @@ -708,16 +682,17 @@ describe("PlainArrayTest", function () { /** * @tc.name: testAdd040 * @tc.desc: Add a pair of key value pairs to the PlainArray. - * @tc.author: wangyong */ it("testAdd040", 0, function () { let plainArray = new PlainArray(); plainArray.add(-2, "b"); try { plainArray.add("a", "c"); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("the index is not integer"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "key" must be number. Received value is: a`); } let res = plainArray.get(-2); expect(res).assertEqual("b"); @@ -726,7 +701,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testAdd041 * @tc.desc: Add a pair of key value pairs to the PlainArray. - * @tc.author: wangyong */ it("testAdd041", 0, function () { let plainArray = new PlainArray(); @@ -744,7 +718,6 @@ describe("PlainArrayTest", function () { /** * @tc.name: testIterator042 * @tc.desc: Iterate over all key value pairs in the PlainArray. - * @tc.author: wangyong */ it("testIterator042", 0, function () { let plainArray = new PlainArray(); @@ -769,19 +742,121 @@ describe("PlainArrayTest", function () { /** * @tc.name: testAdd043 * @tc.desc: Add a pair of key value pairs to the PlainArray. For example: plainArray.add(1.23, "a"). - * @tc.author: wangyong */ it("testAdd043", 0, function () { let plainArray = new PlainArray(); plainArray.add(-2, "b"); try { - plainArray.add(1.23, "a"); + plainArray.add("b", "a"); + expect(true).assertEqual(false); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("the index is not integer"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "key" must be number. Received value is: b`); } let res = plainArray.get(-2); expect(res).assertEqual("b"); }); + + /** + * @tc.name: testHas044 + * @tc.desc: Check whether the PlainArray contains a specified element. For example: plainArray.has("a"). + */ + it("testHas044", 0, function () { + let plainArray = new PlainArray(); + plainArray.add(1, "A"); + plainArray.add(2, "B"); + plainArray.add(3, "C"); + plainArray.add(4, "D"); + plainArray.add(5, "E"); + try { + plainArray.has("a"); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "key" must be number. Received value is: a`); + } + }); + + /** + * @tc.name: testGet045 + * @tc.desc: Get the corresponding value through the key. For example: plainArray.get("a"). + */ + it("testGet045", 0, function () { + let plainArray = new PlainArray(); + plainArray.add(1, "A"); + plainArray.add(2, "B"); + plainArray.add(3, "C"); + plainArray.add(4, "D"); + plainArray.add(5, "E"); + try { + plainArray.get("a"); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "key" must be number. Received value is: a`); + } + }); + + /** + * @tc.name: testGetIndexOfKey046 + * @tc.desc: Find the index of the key value pair according to the corresponding key. + * If no key is specified, return -1. + */ + it("testGetIndexOfKey046", 0, function () { + let plainArray = new PlainArray(); + plainArray.add(1, "A"); + plainArray.add(2, "B"); + plainArray.add(3, "C"); + plainArray.add(4, "D"); + plainArray.add(5, "E"); + try { + plainArray.getIndexOfKey("a"); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "key" must be number. Received value is: a`); + } + }); + + /** + * @tc.name: testGetKeyAt047 + * @tc.desc: Find the key of the key value pair according to the corresponding index. + * For example: plainArray.getKeyAt("a"). + */ + it("testGetKeyAt047", 0, function () { + let plainArray = new PlainArray(); + plainArray.add(1, "A"); + plainArray.add(2, "B"); + plainArray.add(3, "C"); + plainArray.add(4, "D"); + plainArray.add(5, "E"); + try { + plainArray.getKeyAt("a"); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`); + } + }); + + /** + * @tc.name: testReMoveAt048 + * @tc.desc: Delete key value pairs according to index. For example: plainArray.removeAt(12). + */ + it("testReMoveAt048", 0, function () { + let plainArray = new PlainArray(); + plainArray.add(1, "A"); + plainArray.add(2, "B"); + plainArray.add(3, "C"); + plainArray.add(4, "D"); + plainArray.add(5, "E"); + let res = plainArray.removeAt(12); + expect(res).assertEqual(undefined); + }); }); } diff --git a/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/TreeMap.test.js b/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/TreeMap.test.js index 789e2f4fe71274be0f983de0a0b9bdebc044666e..684789b34af7a2bd5e6b68cd1cdef41624ec8486 100644 --- a/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/TreeMap.test.js +++ b/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/TreeMap.test.js @@ -20,22 +20,21 @@ describe("TreeMapTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Create an TreeMap instance. For example: let treeMap = new TreeMap(). - * @tc.author: wangyong */ it("testConstructor001", 0, function () { try { let treeMap = new TreeMap(); expect(treeMap != undefined).assertEqual(true); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("Cannot create new TreeMap"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200012); + expect(err.message).assertEqual("The TreeMap's constructor cannot be directly invoked"); } }); /** * @tc.name: testSet002 * @tc.desc: Add a pair of key value pairs to the TreeMap. For example: treeMap.set(0, "四"). - * @tc.author: wangyong */ it("testSet002", 0, function () { let treeMap = new TreeMap(); @@ -47,7 +46,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testSet003 * @tc.desc: Add a pair of key value pairs to the TreeMap. For example: treeMap.set(0, 8). - * @tc.author: wangyong */ it("testSet003", 0, function () { let treeMap = new TreeMap(); @@ -59,7 +57,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testSet004 * @tc.desc: Add a pair of key value pairs to the TreeMap. - * @tc.author: wangyong */ it("testSet004", 0, function () { let treeMap = new TreeMap(); @@ -72,7 +69,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testSet005 * @tc.desc: Add a pair of key value pairs to the TreeMap. - * @tc.author: wangyong */ it("testSet005", 0, function () { let treeMap = new TreeMap(); @@ -85,7 +81,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testSet006 * @tc.desc: Add a pair of key value pairs to the TreeMap. For example: treeMap.set(2, "*"). - * @tc.author: wangyong */ it("testSet006", 0, function () { let treeMap = new TreeMap(); @@ -97,7 +92,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testSet007 * @tc.desc: Add a pair of key value pairs to the TreeMap. For example: treeMap.set(-2, 3.14). - * @tc.author: wangyong */ it("testSet007", 0, function () { let treeMap = new TreeMap(); @@ -109,7 +103,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testSet008 * @tc.desc: Add a pair of key value pairs to the TreeMap. For example: treeMap.set(100, true). - * @tc.author: wangyong */ it("testSet008", 0, function () { let treeMap = new TreeMap(); @@ -121,7 +114,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testSet009 * @tc.desc: Add a pair of key value pairs to the TreeMap. For example: treeMap.set(100, true). - * @tc.author: wangyong */ it("testSet009", 0, function () { let treeMap = new TreeMap(); @@ -133,7 +125,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testSet010 * @tc.desc: Add a pair of key value pairs to the TreeMap. For example: treeMap.set("a", "四"). - * @tc.author: wangyong */ it("testSet010", 0, function () { let treeMap = new TreeMap(); @@ -145,7 +136,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testSet011 * @tc.desc: Add a pair of key value pairs to the TreeMap. - * @tc.author: wangyong */ it("testSet011", 0, function () { let treeMap = new TreeMap(); @@ -160,7 +150,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testHasKey012 * @tc.desc: Determine whether the TreeMap contains the specified key. For example: treeMap.hasKey(1). - * @tc.author: wangyong */ it("testHasKey012", 0, function () { let treeMap = new TreeMap(); @@ -175,7 +164,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testHasValue013 * @tc.desc: Determine whether the TreeMap contains the specified Value. For example: treeMap.hasValue("a"). - * @tc.author: wangyong */ it("testHasValue013", 0, function () { let treeMap = new TreeMap(); @@ -191,7 +179,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testGet014 * @tc.desc: Get the corresponding value through the key. For example: treeMap.get(1). - * @tc.author: wangyong */ it("testGet014", 0, function () { let treeMap = new TreeMap(); @@ -205,7 +192,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testGet015 * @tc.desc: Get the corresponding value through the key. For example: treeMap.get(1). - * @tc.author: wangyong */ it("testGet015", 0, function () { let treeMap = new TreeMap(); @@ -216,7 +202,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testGet016 * @tc.desc: Get the corresponding value through the key. For example: treeMap.get(0). - * @tc.author: wangyong */ it("testGet016", 0, function () { let treeMap = new TreeMap(); @@ -230,7 +215,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testGetFirstKey017 * @tc.desc: Get the key that ranks first in the TreeMap instance. For example: treeMap.getFirstKey(). - * @tc.author: wangyong */ it("testGetFirstKey017", 0, function () { let treeMap = new TreeMap(); @@ -244,7 +228,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testGetFirstKey018 * @tc.desc: Get the key that ranks first in the TreeMap instance. For example: treeMap.getFirstKey(). - * @tc.author: wangyong */ it("testGetFirstKey018", 0, function () { let treeMap = new TreeMap(); @@ -255,7 +238,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testGetLastKey019 * @tc.desc: Get the last sorted key in the TreeMap instance. For example: treeMap.getLastKey(). - * @tc.author: wangyong */ it("testGetLastKey019", 0, function () { let treeMap = new TreeMap(); @@ -269,7 +251,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testGetLastKey020 * @tc.desc: Get the last sorted key in the TreeMap instance. For example: treeMap.getLastKey(). - * @tc.author: wangyong */ it("testGetLastKey020", 0, function () { let treeMap = new TreeMap(); @@ -280,7 +261,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testSetAll021 * @tc.desc: Copy key value pairs from one HashMap to another. For example: treeMap.setAll(treeMap1). - * @tc.author: wangyong */ it("testSetAll021", 0, function () { let treeMap = new TreeMap(); @@ -302,7 +282,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testRemove022 * @tc.desc: Delete key value pairs according to key. For example: treeMap.remove(1). - * @tc.author: wangyong */ it("testRemove022", 0, function () { let treeMap = new TreeMap(); @@ -316,7 +295,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testRemove023 * @tc.desc: Delete key value pairs according to key. For example: treeMap.remove(1). - * @tc.author: wangyong */ it("testRemove023", 0, function () { let treeMap = new TreeMap(); @@ -328,7 +306,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testClear024 * @tc.desc: Clear all key value pairs in TreeMap. For example: treeMap.clear(). - * @tc.author: wangyong */ it("testClear024", 0, function () { let treeMap = new TreeMap(); @@ -343,7 +320,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testClear025 * @tc.desc: Clear all key value pairs in TreeMap. For example: treeMap.clear(). - * @tc.author: wangyong */ it("testClear025", 0, function () { let treeMap = new TreeMap(); @@ -362,7 +338,6 @@ describe("TreeMapTest", function () { * @tc.name: testGetLowerKey026 * @tc.desc: Get a key that is a little lower than the specified key sort. * For example: treeMap.getLowerKey(2). - * @tc.author: wangyong */ it("testGetLowerKey026", 0, function () { let treeMap = new TreeMap(); @@ -378,7 +353,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testGetLowerKey027 * @tc.desc: Get a key that is a little lower than the specified key sort. For example: treeMap.getLowerKey(2). - * @tc.author: wangyong */ it("testGetLowerKey027", 0, function () { let treeMap = new TreeMap(); @@ -389,7 +363,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testGetHigherKey028 * @tc.desc: Get a key that is a little higher than the specified key sort. For example: treeMap.getLowerKey(2). - * @tc.author: wangyong */ it("testGetHigherKey028", 0, function () { let treeMap = new TreeMap(); @@ -405,7 +378,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testGetHigherKey029 * @tc.desc: Get a key that is a little higher than the specified key sort. For example: treeMap.getLowerKey(2). - * @tc.author: wangyong */ it("testGetHigherKey029", 0, function () { let treeMap = new TreeMap(); @@ -416,7 +388,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testKeys030 * @tc.desc: Get a collection of all the keys in the TreeMap. For example: treeMap.keys(). - * @tc.author: wangyong */ it("testKeys030", 0, function () { let treeMap = new TreeMap(); @@ -436,7 +407,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testValues031 * @tc.desc: Get a collection of all the values in the TreeMap. For example: treeMap.values(). - * @tc.author: wangyong */ it("testValues031", 0, function () { let treeMap = new TreeMap(); @@ -456,7 +426,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testReplace032 * @tc.desc: Modify the corresponding value according to the specified key. For example: treeMap.replace(2, "B"). - * @tc.author: wangyong */ it("testReplace032", 0, function () { let treeMap = new TreeMap(); @@ -473,7 +442,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testReplace033 * @tc.desc: Modify the corresponding value according to the specified key. For example: treeMap.replace(2, "B"). - * @tc.author: wangyong */ it("testReplace033", 0, function () { let treeMap = new TreeMap(); @@ -487,7 +455,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testLength034 * @tc.desc: Get the number of key value pairs in the TreeMap instance. For example: treeMap.length. - * @tc.author: wangyong */ it("testLength034", 0, function () { let treeMap = new TreeMap(); @@ -503,7 +470,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testLength035 * @tc.desc: Get the number of key value pairs in the TreeMap instance. For example: treeMap.length. - * @tc.author: wangyong */ it("testLength035", 0, function () { let treeMap = new TreeMap(); @@ -514,7 +480,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testForEach036 * @tc.desc: Traverse all key value pairs in the TreeMap instance. - * @tc.author: wangyong */ it("testForEach036", 0, function () { let treeMap = new TreeMap(); @@ -544,7 +509,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testEntries037 * @tc.desc: Get all key value pairs collection in TreeMap. - * @tc.author: wangyong */ it("testEntries037", 0, function () { let treeMap = new TreeMap(); @@ -569,7 +533,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testIterator038 * @tc.desc: Traverse all key value pairs in the TreeMap instance. - * @tc.author: wangyong */ it("testIterator038", 0, function () { let treeMap = new TreeMap(); @@ -591,7 +554,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testIterator039 * @tc.desc: Traverse all key value pairs in the TreeMap instance. For example: treeMap[Symbol.iterator](). - * @tc.author: wangyong */ it("testIterator039", 0, function () { let treeMap = new TreeMap(); @@ -616,7 +578,6 @@ describe("TreeMapTest", function () { /** * @tc.name: testIsEmpty040 * @tc.desc: Determine whether the TreeMap instance is empty. For example: treeMap.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty040", 0, function () { let treeMap = new TreeMap(); @@ -631,5 +592,23 @@ describe("TreeMapTest", function () { let res1 = treeMap.isEmpty(); expect(res1).assertEqual(true); }); + + /** + * @tc.name: testSetAll041 + * @tc.desc: Copy key value pairs from one HashMap to another. For example: treeMap.setAll([1, 2, 3]). + */ + it("testSetAll041", 0, function () { + let treeMap = new TreeMap(); + treeMap.set(0, "a"); + treeMap.set(1, "b"); + try { + treeMap.setAll([1, 2, 3]); + expect(true).assertEqual(false); + } catch (err) { + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(401); + expect(err.message).assertEqual(`The type of "map" must be TreeMap. Received value is: 1,2,3`); + } + }); }); } diff --git a/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/TreeSet.test.js b/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/TreeSet.test.js index ceff687b79c0f186ccdb78cf3e50615ccd346457..3ce7a468e92247e1796d6905886f14bb031339cf 100644 --- a/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/TreeSet.test.js +++ b/commonlibrary/ets_utils/containerRelation_lib_standard/src/main/js/test/TreeSet.test.js @@ -20,22 +20,21 @@ describe("TreeSetTest", function () { /** * @tc.name: testConstructor001 * @tc.desc: Create an TreeSet instance. For example: let treeSet = new TreeSet(). - * @tc.author: wangyong */ it("testConstructor001", 0, function () { try { let treeSet = new TreeSet(); expect(treeSet != undefined).assertEqual(true); } catch (err) { - expect(err.name).assertEqual("TypeError"); - expect(err.message).assertEqual("Cannot create new TreeSet"); + expect(err.name).assertEqual("BusinessError"); + expect(err.code).assertEqual(10200012); + expect(err.message).assertEqual("The TreeSet's constructor cannot be directly invoked"); } }); /** * @tc.name: testAdd002 * @tc.desc: Add element to TreeSet instance. For example: treeSet.add("四"). - * @tc.author: wangyong */ it("testAdd002", 0, function () { let treeSet = new TreeSet(); @@ -47,7 +46,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testAdd003 * @tc.desc: Add element to TreeSet instance. For example: treeSet.add("四"). - * @tc.author: wangyong */ it("testAdd003", 0, function () { let treeSet = new TreeSet(); @@ -59,7 +57,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testAdd004 * @tc.desc: Add element to TreeSet instance. For example: let a = [1, 2, 3, 4]; treeSet.add(a). - * @tc.author: wangyong */ it("testAdd004", 0, function () { let treeSet = new TreeSet(); @@ -72,7 +69,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testAdd005 * @tc.desc: Add element to TreeSet instance. For example: treeSet.add("*"). - * @tc.author: wangyong */ it("testAdd005", 0, function () { let treeSet = new TreeSet(); @@ -84,7 +80,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testAdd006 * @tc.desc: Add element to TreeSet instance. - * @tc.author: wangyong */ it("testAdd006", 0, function () { let treeSet = new TreeSet(); @@ -97,7 +92,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testAdd007 * @tc.desc: Add element to TreeSet instance. For example: treeSet.add(1.234). - * @tc.author: wangyong */ it("testAdd007", 0, function () { let treeSet = new TreeSet(); @@ -109,7 +103,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testAdd008 * @tc.desc: Add element to TreeSet instance. For example: treeSet.add(true). - * @tc.author: wangyong */ it("testAdd008", 0, function () { let treeSet = new TreeSet(); @@ -121,7 +114,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testAdd009 * @tc.desc: Add element to TreeSet instance. For example: treeSet.add(""). - * @tc.author: wangyong */ it("testAdd009", 0, function () { let treeSet = new TreeSet(); @@ -133,7 +125,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testAdd010 * @tc.desc: Add element to TreeSet instance. - * @tc.author: wangyong */ it("testAdd010", 0, function () { let treeSet = new TreeSet(); @@ -148,7 +139,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testLength011 * @tc.desc: Get the number of element in the TreeSet instance. For example: treeSet.length. - * @tc.author: wangyong */ it("testLength011", 0, function () { let treeSet = new TreeSet(); @@ -162,7 +152,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testLength012 * @tc.desc: Get the number of element in the TreeSet instance. For example: treeSet.length. - * @tc.author: wangyong */ it("testLength012", 0, function () { let treeSet = new TreeSet(); @@ -173,7 +162,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testHas013 * @tc.desc: Determine whether the TreeSet instance contains the specified element. For example: treeSet.has(2). - * @tc.author: wangyong */ it("testHas013", 0, function () { let treeSet = new TreeSet(); @@ -187,7 +175,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testHas014 * @tc.desc: Determine whether the TreeSet instance contains the specified element. For example: treeSet.has(2). - * @tc.author: wangyong */ it("testHas014", 0, function () { let treeSet = new TreeSet(); @@ -201,7 +188,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testGetFirstValue015 * @tc.desc: Get the value that ranks first in the TreeSet instance. For example: treeSet.getFirstValue(). - * @tc.author: wangyong */ it("testGetFirstValue015", 0, function () { let treeSet = new TreeSet(); @@ -218,7 +204,6 @@ describe("TreeSetTest", function () { * @tc.name: testGetFirstValue016 * @tc.desc: Get the value that ranks first in the TreeSet instance. * For example: treeSet.getFirstValue(). - * @tc.author: wangyong */ it("testGetFirstValue016", 0, function () { let treeSet = new TreeSet(); @@ -229,7 +214,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testGetLastValue017 * @tc.desc: Get the last sorted key in the TreeSet instance. For example: treeSet.getLastValue(). - * @tc.author: wangyong */ it("testGetLastValue017", 0, function () { let treeSet = new TreeSet(); @@ -243,7 +227,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testGetLastValue018 * @tc.desc: Get the last sorted key in the TreeSet instance. For example: treeSet.getLastValue(). - * @tc.author: wangyong */ it("testGetLastValue018", 0, function () { let treeSet = new TreeSet(); @@ -255,7 +238,6 @@ describe("TreeSetTest", function () { * @tc.name: testGetLowerValue019 * @tc.desc: Get a value that is a little lower than the specified value sort. * For example: treeSet.getLowerValue(2). - * @tc.author: wangyong */ it("testGetLowerValue019", 0, function () { let treeSet = new TreeSet(); @@ -272,7 +254,6 @@ describe("TreeSetTest", function () { * @tc.name: testGetLowerValue020 * @tc.desc: Get a value that is a little lower than the specified value sort. * For example: treeSet.getLowerValue(2). - * @tc.author: wangyong */ it("testGetLowerValue020", 0, function () { let treeSet = new TreeSet(); @@ -284,7 +265,6 @@ describe("TreeSetTest", function () { * @tc.name: testGetHigherValue021 * @tc.desc: Get a value that is a little higher than the specified value sort. * For example: treeSet.getHigherValue(3). - * @tc.author: wangyong */ it("testGetHigherValue021", 0, function () { let treeSet = new TreeSet(); @@ -301,7 +281,6 @@ describe("TreeSetTest", function () { * @tc.name: testGetHigherValue022 * @tc.desc: Get a value that is a little higher than the specified value sort. * For example: treeSet.getHigherValue(3). - * @tc.author: wangyong */ it("testGetHigherValue022", 0, function () { let treeSet = new TreeSet(); @@ -312,7 +291,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testPopFirst023 * @tc.desc: Delete first value of sort. For example: treeSet.popFirst(). - * @tc.author: wangyong */ it("testPopFirst023", 0, function () { let treeSet = new TreeSet(); @@ -328,7 +306,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testPopFirst024 * @tc.desc: Delete first value of sort. For example: treeSet.popFirst(). - * @tc.author: wangyong */ it("testPopFirst024", 0, function () { let treeSet = new TreeSet(); @@ -339,7 +316,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testPopLast025 * @tc.desc: Delete last value of sort. For example: treeSet.popLast(). - * @tc.author: wangyong */ it("testPopLast025", 0, function () { let treeSet = new TreeSet(); @@ -355,7 +331,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testPopLast026 * @tc.desc: Delete last value of sort. For example: treeSet.popLast(). - * @tc.author: wangyong */ it("testPopLast026", 0, function () { let treeSet = new TreeSet(); @@ -366,7 +341,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testClear027 * @tc.desc: Clear all elements of the TreeSet instance. For example: treeSet.clear(). - * @tc.author: wangyong */ it("testClear027", 0, function () { let treeSet = new TreeSet(); @@ -381,7 +355,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testClear028 * @tc.desc: Clear all elements of the TreeSet instance. For example: treeSet.clear(). - * @tc.author: wangyong */ it("testClear028", 0, function () { let treeSet = new TreeSet(); @@ -398,7 +371,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testIsEmpty029 * @tc.desc: Determine whether the TreeSet instance is empty. For example: treeSet.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty029", 0, function () { let treeSet = new TreeSet(); @@ -410,7 +382,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testIsEmpty030 * @tc.desc: Determine whether the TreeSet instance is empty. For example: treeSet.isEmpty(). - * @tc.author: wangyong */ it("testIsEmpty030", 0, function () { let treeSet = new TreeSet(); @@ -421,7 +392,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testRemove031 * @tc.desc: Delete the specified value. For example: hashSet.remove("c"). - * @tc.author: wangyong */ it("testRemove031", 0, function () { let treeSet = new TreeSet(); @@ -440,7 +410,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testRemove032 * @tc.desc: Delete the specified value. For example: hashSet.remove("c"). - * @tc.author: wangyong */ it("testRemove032", 0, function () { let treeSet = new TreeSet(); @@ -451,7 +420,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testValues033 * @tc.desc: Get a collection of all the values in the TreeSet. For example: treeSet.values(). - * @tc.author: wangyong */ it("testValues033", 0, function () { let treeSet = new TreeSet(); @@ -471,7 +439,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testForEach034 * @tc.desc: Traverse the collection of all elements of the TreeSet instance. - * @tc.author: wangyong */ it("testForEach034", 0, function () { let treeSet = new TreeSet(); @@ -493,7 +460,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testEntries035 * @tc.desc: Get all key value pairs collection in TreeMap. - * @tc.author: wangyong */ it("testEntries035", 0, function () { let treeSet = new TreeSet(); @@ -514,7 +480,6 @@ describe("TreeSetTest", function () { * @tc.name: testIterator036 * @tc.desc: Iterate over all elements of the TreeSet instance. * For example: for (let item of treeSet) {arr.push(item);} - * @tc.author: wangyong */ it("testIterator036", 0, function () { let treeSet = new TreeSet(); @@ -536,7 +501,6 @@ describe("TreeSetTest", function () { /** * @tc.name: testIterator037 * @tc.desc: Iterate over all elements of the TreeSet instance. For example: treeSet[Symbol.iterator](). - * @tc.author: wangyong */ it("testIterator037", 0, function () { let treeSet = new TreeSet(); @@ -557,5 +521,21 @@ describe("TreeSetTest", function () { expect(arr[i]).assertEqual(arr1[i]); } }); + + /** + * @tc.name: testAdd038 + * @tc.desc: Add element to TreeSet instance. For example: treeSet.add.bind({}, "a")(). + */ + it("testAdd038", 0, function () { + let treeSet = new TreeSet(); + try { + treeSet.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`); + } + }); }); }