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..cb000bf7e9047c7a1bf337daa5a425fd4a42dfbb 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 @@ -27,8 +27,9 @@ describe("ArraylistTest", function () { 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"); } }); @@ -526,13 +527,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`); } }); @@ -550,13 +549,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`); } }); @@ -574,13 +571,11 @@ 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`); } }); @@ -709,13 +704,11 @@ 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`); } }); @@ -736,13 +729,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`); } }); @@ -761,20 +752,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). + * elements at the end position. For example: removeByRange(0, 7). * @tc.author: wangyong */ it("testRemoveByRange039", 0, function () { @@ -787,7 +776,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); @@ -809,13 +798,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`); } }); @@ -832,7 +819,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); @@ -858,13 +845,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`); } }); @@ -901,13 +886,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`); } }); @@ -1058,9 +1041,137 @@ 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({})(). + * @tc.author: liuganlin + */ + 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). + * @tc.author: liuganlin + */ + 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). + * @tc.author: liuganlin + */ + 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). + * @tc.author: liuganlin + */ + 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). + * @tc.author: liuganlin + */ + 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). + * @tc.author: liuganlin + */ + 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..ea0c392be7ab231806e80f47887358d866d6796a 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 @@ -26,8 +26,9 @@ describe("DequeTest", 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"); } }); @@ -540,5 +541,39 @@ 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")(). + * @tc.author: liuganlin + */ + 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). + * @tc.author: wangyong + */ + 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..894124a3c5ab5763ecd065a75330ed72775da231 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 @@ -26,8 +26,9 @@ describe("LinkedListTest", 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"); } }); @@ -343,9 +344,11 @@ 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`); } }); @@ -560,9 +563,11 @@ 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`); } }); @@ -807,9 +812,11 @@ describe("LinkedListTest", 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`); } }); @@ -987,5 +994,170 @@ 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)(). + * @tc.author: wangyong + */ + 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"). + * @tc.author: liuganlin + */ + 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"). + * @tc.author: liuganlin + */ + 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(). + * @tc.author: liuganlin + */ + 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(). + * @tc.author: liuganlin + */ + 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"). + * @tc.author: liuganlin + */ + 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"). + * @tc.author: liuganlin + */ + 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"). + * @tc.author: liuganlin + */ + 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"). + * @tc.author: liuganlin + */ + 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..1e726282d67006283a3c4c92512af61ce6ae6066 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 @@ -27,8 +27,9 @@ describe("ListTest", function () { 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"); } }); @@ -580,9 +581,11 @@ 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`); } }); @@ -612,9 +615,11 @@ 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`); } }); @@ -657,9 +662,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`); } }); @@ -678,9 +685,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`); } }); @@ -699,9 +708,11 @@ 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`); } }); @@ -882,9 +893,11 @@ describe("ListTest", 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`); } }); @@ -1072,5 +1085,136 @@ 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)(). + * @tc.author: wangyong + */ + 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"). + * @tc.author: liuganlin + */ + 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"). + * @tc.author: liuganlin + */ + 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"). + * @tc.author: liuganlin + */ + 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"). + * @tc.author: liuganlin + */ + 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). + * @tc.author: liuganlin + */ + 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). + * @tc.author: liuganlin + */ + 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..33ab22e62175f936854b2262c7ad2ddf3c80189a 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 @@ -26,8 +26,9 @@ describe("QueueTest", 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"); } }); @@ -305,5 +306,22 @@ 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)(). + * @tc.author: wangyong + */ + 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..d4d9d719ac491718f199c08d13da893e3f2517e0 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 @@ -27,8 +27,9 @@ describe("StackTest", function () { 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"); } }); @@ -514,5 +515,22 @@ 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)(). + * @tc.author: wangyong + */ + 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..37e79d3ef60502fe1310b61ed8f9912798c02ee6 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 @@ -820,7 +820,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]); } 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..3cdd95c3932a4475536ac0bae389ddb0d19fb9bc 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 @@ -27,8 +27,9 @@ describe("HashMapTest", function () { 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"); } }); @@ -735,5 +736,58 @@ 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")(). + * @tc.author: liuganlin + */ + 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. + * @tc.author: liuganlin + */ + 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")(). + * @tc.author: liuganlin + */ + 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..54a076782d2bc19873da522653a9a5fc45efe7dc 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 @@ -26,8 +26,9 @@ describe("HashSetTest", 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"); } }); @@ -534,5 +535,44 @@ 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")(). + * @tc.author: liuganlin + */ + 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")(). + * @tc.author: liuganlin + */ + 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..7279a43ec7356de51902f9754cd52cae06e59bda 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 @@ -27,8 +27,9 @@ describe("LightWeightMapTest", function () { 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"); } }); @@ -651,31 +652,35 @@ 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.desc: Delete key value pairs according to index. For example: lightWeightMap.removeAt("a"). * @tc.author: wangyong */ 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"). + * For example: lightWeightMap.getValueAt("a"). * @tc.author: wangyong */ it("testGetValueAt039", 0, function () { @@ -686,17 +691,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"). + * For example: lightWeightMap.getKeyAt("a"). * @tc.author: wangyong */ it("testGetKeyAt040", 0, function () { @@ -707,10 +714,12 @@ 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`); } }); @@ -885,5 +894,127 @@ 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. + * @tc.author: liuganlin + */ + 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). + * @tc.author: liuganlin + */ + 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. + * @tc.author: liuganlin + */ + 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"). + * @tc.author: liuganlin + */ + 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"). + * @tc.author: liuganlin + */ + 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). + * @tc.author: liuganlin + */ + 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..bdf8c904d95b495e5ec031d7621387164bdba6df 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 @@ -27,8 +27,9 @@ describe("LightWeightSetTest", function () { 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"); } }); @@ -526,9 +527,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`); } }); @@ -547,24 +550,28 @@ 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.desc: Delete elements according to index. For example: lightWeightSet.removeAt("a"). * @tc.author: wangyong */ 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`); } }); @@ -587,7 +594,7 @@ describe("LightWeightSetTest", function () { /** * @tc.name: testGetValueAt034 - * @tc.desc: Get the element according to the corresponding index. For example: lightWeightSet.getValueAt("123"). + * @tc.desc: Get the element according to the corresponding index. For example: lightWeightSet.getValueAt("a"). * @tc.author: wangyong */ it("testGetValueAt034", 0, function () { @@ -598,10 +605,12 @@ 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`); } }); @@ -693,12 +702,8 @@ 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); }); /** @@ -755,5 +760,45 @@ 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. + * @tc.author: liuganlin + */ + 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. + * @tc.author: liuganlin + */ + 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..b10dc785c79473b1a54efd03bcf605518d3e0a81 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 @@ -26,8 +26,9 @@ describe("PlainArrayTest", 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"); } }); @@ -180,7 +181,7 @@ describe("PlainArrayTest", function () { /** * @tc.name: testHas011 - * @tc.desc: Check whether the PlainArray contains a specified element. For example: plainArray.has("a"). + * @tc.desc: Check whether the PlainArray contains a specified element. For example: plainArray.has(6). * @tc.author: wangyong */ it("testHas011", 0, function () { @@ -190,7 +191,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); @@ -267,8 +268,6 @@ describe("PlainArrayTest", function () { plainArray.add(5, "E"); let res = plainArray.getKeyAt(2); expect(res).assertEqual(3); - res = plainArray.getKeyAt(10); - expect(res).assertEqual(undefined); }); /** @@ -307,8 +306,6 @@ describe("PlainArrayTest", function () { expect(res).assertEqual("C"); let value = plainArray.get(3); expect(value).assertEqual(undefined); - res = plainArray.removeAt(12); - expect(res).assertEqual(undefined); }); /** @@ -332,15 +329,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`); } }); @@ -365,9 +366,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`); } }); @@ -444,8 +447,6 @@ describe("PlainArrayTest", function () { plainArray.add(5, "E"); let res = plainArray.getValueAt(2); expect(res).assertEqual("C"); - res = plainArray.getValueAt(12); - expect(res).assertEqual(undefined); }); /** @@ -474,16 +475,18 @@ 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.desc: Add a pair of key value pairs to the PlainArray.For example: plainArray.add("a", null). * @tc.author: wangyong */ 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`); } }); @@ -567,8 +570,14 @@ 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`); + } }); /** @@ -584,16 +593,18 @@ describe("PlainArrayTest", function () { /** * @tc.name: testRemoveAt033 - * @tc.desc: Delete key value pairs according to index. For example: plainArray.removeAt(2). + * @tc.desc: Delete key value pairs according to index. For example: plainArray.removeAt("a"). * @tc.author: wangyong */ 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`); } }); @@ -630,9 +641,11 @@ 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`); } }); @@ -715,9 +728,11 @@ describe("PlainArrayTest", function () { 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"); @@ -775,13 +790,121 @@ describe("PlainArrayTest", 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"). + * @tc.author: liuganlin + */ + 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"). + * @tc.author: liuganlin + */ + 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. + * @tc.author: liuganlin + */ + 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"). + * @tc.author: liuganlin + */ + 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). + * @tc.author: liuganlin + */ + 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..8d049a8cbbf21a2e9f3a0e380eb7eead84436309 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 @@ -27,8 +27,9 @@ describe("TreeMapTest", function () { 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"); } }); @@ -631,5 +632,24 @@ 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]). + * @tc.author: liuganlin + */ + 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..9f976021275dad72389c5ee3280a99dc9ad9eba6 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 @@ -27,8 +27,9 @@ describe("TreeSetTest", function () { 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"); } }); @@ -557,5 +558,22 @@ 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")(). + * @tc.author: liuganlin + */ + 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`); + } + }); }); }