提交 9b9a6d8f 编写于 作者: L liu-ganlin

container exception information

Signed-off-by: Nliu-ganlin <liuganlin@huawei.com>
上级 6f976da7
...@@ -27,8 +27,9 @@ describe("ArraylistTest", function () { ...@@ -27,8 +27,9 @@ describe("ArraylistTest", function () {
let arrayList = new ArrayList(); let arrayList = new ArrayList();
expect(arrayList != undefined).assertEqual(true); expect(arrayList != undefined).assertEqual(true);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("Cannot create new arrayList"); expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The ArrayList's constructor cannot be directly invoked");
} }
}); });
...@@ -526,13 +527,11 @@ describe("ArraylistTest", function () { ...@@ -526,13 +527,11 @@ describe("ArraylistTest", function () {
arrayList.add("a"); arrayList.add("a");
try { try {
let res = arrayList.insert(8, -1); let res = arrayList.insert(8, -1);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
if (err.message != "the index is out-of-bounds") { expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual("ArrayList: set out-of-bounds"); expect(err.message).assertEqual(`The value of "index" is out of range. It must be >= 0 && <= 4. Received value is: -1`);
} else {
expect(err.message).assertEqual("the index is out-of-bounds");
}
} }
}); });
...@@ -550,13 +549,11 @@ describe("ArraylistTest", function () { ...@@ -550,13 +549,11 @@ describe("ArraylistTest", function () {
arrayList.add("a"); arrayList.add("a");
try { try {
let res = arrayList.insert(8, 10); let res = arrayList.insert(8, 10);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
if (err.message != "the index is out-of-bounds") { expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual("ArrayList: set out-of-bounds"); expect(err.message).assertEqual(`The value of "index" is out of range. It must be >= 0 && <= 4. Received value is: 10`);
} else {
expect(err.message).assertEqual("the index is out-of-bounds");
}
} }
}); });
...@@ -574,13 +571,11 @@ describe("ArraylistTest", function () { ...@@ -574,13 +571,11 @@ describe("ArraylistTest", function () {
arrayList.add("a"); arrayList.add("a");
try { try {
let res = arrayList.insert(8, 11); let res = arrayList.insert(8, 11);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
if (err.message != "the index is out-of-bounds") { expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual("ArrayList: set out-of-bounds"); expect(err.message).assertEqual(`The value of "index" is out of range. It must be >= 0 && <= 4. Received value is: 11`);
} else {
expect(err.message).assertEqual("the index is out-of-bounds");
}
} }
}); });
...@@ -709,13 +704,11 @@ describe("ArraylistTest", function () { ...@@ -709,13 +704,11 @@ describe("ArraylistTest", function () {
arrayList.add("b"); arrayList.add("b");
try { try {
let res = arrayList.removeByIndex(5); let res = arrayList.removeByIndex(5);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
if (err.message != "the index is out-of-bounds") { expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual("removeByIndex is out-of-bounds"); expect(err.message).assertEqual(`The value of "index" is out of range. It must be >= 0 && <= 4. Received value is: 5`);
} else {
expect(err.message).assertEqual("the index is out-of-bounds");
}
} }
}); });
...@@ -736,13 +729,11 @@ describe("ArraylistTest", function () { ...@@ -736,13 +729,11 @@ describe("ArraylistTest", function () {
arrayList.add(1); arrayList.add(1);
try { try {
let res = arrayList.removeByRange(3, 1); let res = arrayList.removeByRange(3, 1);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
if (err.message != "the fromIndex cannot be less than or equal to toIndex") { expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual("fromIndex cannot be less than or equal to toIndex"); expect(err.message).assertEqual(`The value of "fromIndex" is out of range. It must be >= 0 && <= 0. Received value is: 3`);
} else {
expect(err.message).assertEqual("the fromIndex cannot be less than or equal to toIndex");
}
} }
}); });
...@@ -761,20 +752,18 @@ describe("ArraylistTest", function () { ...@@ -761,20 +752,18 @@ describe("ArraylistTest", function () {
arrayList.add(1); arrayList.add(1);
try { try {
let res = arrayList.removeByRange(6, 8); let res = arrayList.removeByRange(6, 8);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
if (err.message != "the fromIndex or the toIndex is out-of-bounds") { expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual("ArrayList: set out-of-bounds"); expect(err.message).assertEqual(`The value of "fromIndex" is out of range. It must be >= 0 && <= 4. Received value is: 6`);
} else {
expect(err.message).assertEqual("the fromIndex or the toIndex is out-of-bounds");
}
} }
}); });
/** /**
* @tc.name: testRemoveByRange039 * @tc.name: testRemoveByRange039
* @tc.desc: Deletes elements from a specified range, including elements at the start position and * @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 * @tc.author: wangyong
*/ */
it("testRemoveByRange039", 0, function () { it("testRemoveByRange039", 0, function () {
...@@ -787,7 +776,7 @@ describe("ArraylistTest", function () { ...@@ -787,7 +776,7 @@ describe("ArraylistTest", function () {
arrayList.add("b"); arrayList.add("b");
arrayList.add("c"); arrayList.add("c");
arrayList.add(1); arrayList.add(1);
arrayList.removeByRange(0, 9); arrayList.removeByRange(0, 8);
let res = arrayList.length; let res = arrayList.length;
let res1 = arrayList.getLastIndexOf(1); let res1 = arrayList.getLastIndexOf(1);
expect(res).assertEqual(0); expect(res).assertEqual(0);
...@@ -809,13 +798,11 @@ describe("ArraylistTest", function () { ...@@ -809,13 +798,11 @@ describe("ArraylistTest", function () {
arrayList.add(14); arrayList.add(14);
try { try {
let subArr = arrayList.subArrayList(4, 2); let subArr = arrayList.subArrayList(4, 2);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
if (err.message != "the fromIndex cannot be less than or equal to toIndex") { expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual("fromIndex cannot be less than or equal to toIndex"); expect(err.message).assertEqual(`The value of "fromIndex" is out of range. It must be >= 0 && <= 1. Received value is: 4`);
} else {
expect(err.message).assertEqual("the fromIndex cannot be less than or equal to toIndex");
}
} }
}); });
...@@ -832,7 +819,7 @@ describe("ArraylistTest", function () { ...@@ -832,7 +819,7 @@ describe("ArraylistTest", function () {
arrayList.add(1); arrayList.add(1);
arrayList.add(2); arrayList.add(2);
arrayList.add(14); arrayList.add(14);
let subArr = arrayList.subArrayList(0, 6); let subArr = arrayList.subArrayList(0, 5);
let arr = []; let arr = [];
arrayList.forEach((item, index) => { arrayList.forEach((item, index) => {
arr.push(item); arr.push(item);
...@@ -858,13 +845,11 @@ describe("ArraylistTest", function () { ...@@ -858,13 +845,11 @@ describe("ArraylistTest", function () {
arrayList.add(14); arrayList.add(14);
try { try {
let subArr = arrayList.subArrayList(6, 9); let subArr = arrayList.subArrayList(6, 9);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
if (err.message != "the fromIndex or the toIndex is out-of-bounds") { expect(err.code).assertEqual(10200001);
expect(err.message).assertEqual("fromIndex or toIndex is out-of-bounds"); expect(err.message).assertEqual(`The value of "fromIndex" is out of range. It must be >= 0 && <= 4. Received value is: 6`);
} else {
expect(err.message).assertEqual("the fromIndex or the toIndex is out-of-bounds");
}
} }
}); });
...@@ -901,13 +886,11 @@ describe("ArraylistTest", function () { ...@@ -901,13 +886,11 @@ describe("ArraylistTest", function () {
arrayList.add(14); arrayList.add(14);
try { try {
let res = arrayList.increaseCapacityTo(); let res = arrayList.increaseCapacityTo();
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
if (err.message != "index is not integer") { expect(err.code).assertEqual(401);
expect(err.message).assertEqual("newCapacity is not Integer"); expect(err.message).assertEqual(`The type of "newCapacity" must be number. Received value is: undefined`);
} else {
expect(err.message).assertEqual("index is not integer");
}
} }
}); });
...@@ -1058,9 +1041,137 @@ describe("ArraylistTest", function () { ...@@ -1058,9 +1041,137 @@ describe("ArraylistTest", function () {
arrayList.add("b"); arrayList.add("b");
arrayList.add("c"); arrayList.add("c");
arrayList.add(1); arrayList.add(1);
arrayList.removeByRange(0, 9); try {
let res = arrayList.length; arrayList.removeByRange(0, 9);
expect(res).assertEqual(0); 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`);
}
}); });
}); });
} }
...@@ -26,8 +26,9 @@ describe("DequeTest", function () { ...@@ -26,8 +26,9 @@ describe("DequeTest", function () {
try { try {
let deque = new Deque(); let deque = new Deque();
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("Cannot create new deque"); expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The Deque's constructor cannot be directly invoked");
} }
}); });
...@@ -540,5 +541,39 @@ describe("DequeTest", function () { ...@@ -540,5 +541,39 @@ describe("DequeTest", function () {
let size = deque.length; let size = deque.length;
expect(size).assertEqual(7); 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`);
}
});
}); });
} }
...@@ -26,8 +26,9 @@ describe("LinkedListTest", function () { ...@@ -26,8 +26,9 @@ describe("LinkedListTest", function () {
try { try {
let linkedList = new LinkedList(); let linkedList = new LinkedList();
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("Cannot create new linkedList"); expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The LinkedList's constructor cannot be directly invoked");
} }
}); });
...@@ -343,9 +344,11 @@ describe("LinkedListTest", function () { ...@@ -343,9 +344,11 @@ describe("LinkedListTest", function () {
linkedList.add("b"); linkedList.add("b");
try { try {
let res = linkedList.removeByIndex(10); let res = linkedList.removeByIndex(10);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is out-of-bounds"); 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 () { ...@@ -560,9 +563,11 @@ describe("LinkedListTest", function () {
linkedList.add("b"); linkedList.add("b");
try { try {
let res = linkedList.insert(8, "d"); let res = linkedList.insert(8, "d");
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is out-of-bounds"); 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 () { ...@@ -807,9 +812,11 @@ describe("LinkedListTest", function () {
let linkedList = new LinkedList(); let linkedList = new LinkedList();
try { try {
let res = linkedList.removeByIndex(1); let res = linkedList.removeByIndex(1);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is out-of-bounds"); 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 () { ...@@ -987,5 +994,170 @@ describe("LinkedListTest", function () {
expect(arr[i]).assertEqual(a[i]); 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`);
}
});
}); });
} }
...@@ -27,8 +27,9 @@ describe("ListTest", function () { ...@@ -27,8 +27,9 @@ describe("ListTest", function () {
let list = new List(); let list = new List();
expect(list != undefined).assertEqual(true); expect(list != undefined).assertEqual(true);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("cannot create new list"); expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The List's constructor cannot be directly invoked");
} }
}); });
...@@ -580,9 +581,11 @@ describe("ListTest", function () { ...@@ -580,9 +581,11 @@ describe("ListTest", function () {
list.add("b"); list.add("b");
try { try {
let res = list.removeByIndex(5); let res = list.removeByIndex(5);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is out-of-bounds"); 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 () { ...@@ -612,9 +615,11 @@ describe("ListTest", function () {
list.add("b"); list.add("b");
try { try {
let res = list.insert("d", 8); let res = list.insert("d", 8);
expect(true).assertEqual(false);
} catch(err) { } catch(err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is out-of-bounds"); 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 () { ...@@ -657,9 +662,11 @@ describe("ListTest", function () {
list.add("14"); list.add("14");
try { try {
list.getSubList(2, 8); list.getSubList(2, 8);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the fromIndex or the toIndex is out-of-bounds"); 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 () { ...@@ -678,9 +685,11 @@ describe("ListTest", function () {
list.add("14"); list.add("14");
try { try {
let res = list.getSubList(6, 8); let res = list.getSubList(6, 8);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the fromIndex or the toIndex is out-of-bounds"); 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 () { ...@@ -699,9 +708,11 @@ describe("ListTest", function () {
list.add("14"); list.add("14");
try { try {
let res = list.getSubList(6, 2); let res = list.getSubList(6, 2);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the toIndex cannot be less than or equal to fromIndex"); 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 () { ...@@ -882,9 +893,11 @@ describe("ListTest", function () {
let list = new List(); let list = new List();
try { try {
let res = list.removeByIndex(1); let res = list.removeByIndex(1);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is out-of-bounds"); 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 () { ...@@ -1072,5 +1085,136 @@ describe("ListTest", function () {
expect(arr[i]).assertEqual(a[i]); 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`);
}
});
}); });
} }
...@@ -26,8 +26,9 @@ describe("QueueTest", function () { ...@@ -26,8 +26,9 @@ describe("QueueTest", function () {
try { try {
let queue = new Queue(); let queue = new Queue();
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("Cannot create new queue"); expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The Queue's constructor cannot be directly invoked");
} }
}); });
...@@ -305,5 +306,22 @@ describe("QueueTest", function () { ...@@ -305,5 +306,22 @@ describe("QueueTest", function () {
expect(arr[i]).assertEqual(a[i]); 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`);
}
});
}); });
} }
...@@ -27,8 +27,9 @@ describe("StackTest", function () { ...@@ -27,8 +27,9 @@ describe("StackTest", function () {
let stack = new Stack(); let stack = new Stack();
expect(stack != undefined).assertEqual(true); expect(stack != undefined).assertEqual(true);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("Cannot create new stack"); expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The Stack's constructor cannot be directly invoked");
} }
}); });
...@@ -514,5 +515,22 @@ describe("StackTest", function () { ...@@ -514,5 +515,22 @@ describe("StackTest", function () {
expect(arr[i]).assertEqual(a[i]); 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`);
}
});
}); });
} }
...@@ -820,7 +820,7 @@ describe("VectorTest", function () { ...@@ -820,7 +820,7 @@ describe("VectorTest", function () {
vector.add(14); vector.add(14);
let arr1 = ["a", "b", "c"]; let arr1 = ["a", "b", "c"];
vector.copyToArray(arr1); 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++) { for (let i = 0; i < a.length; i++) {
expect(arr1[i]).assertEqual(a[i]); expect(arr1[i]).assertEqual(a[i]);
} }
......
...@@ -27,8 +27,9 @@ describe("HashMapTest", function () { ...@@ -27,8 +27,9 @@ describe("HashMapTest", function () {
let hashMap = new HashMap(); let hashMap = new HashMap();
expect(hashMap != undefined).assertEqual(true); expect(hashMap != undefined).assertEqual(true);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("Cannot create new HashMap"); expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The HashMap's constructor cannot be directly invoked");
} }
}); });
...@@ -735,5 +736,58 @@ describe("HashMapTest", function () { ...@@ -735,5 +736,58 @@ describe("HashMapTest", function () {
} }
expect(flag).assertEqual(true); 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`);
}
});
}); });
} }
...@@ -26,8 +26,9 @@ describe("HashSetTest", function () { ...@@ -26,8 +26,9 @@ describe("HashSetTest", function () {
try { try {
let hashSet = new HashSet(); let hashSet = new HashSet();
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("Cannot create new HashSet"); expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The HashSet's constructor cannot be directly invoked");
} }
}); });
...@@ -534,5 +535,44 @@ describe("HashSetTest", function () { ...@@ -534,5 +535,44 @@ describe("HashSetTest", function () {
expect(arr[i]).assertEqual(arr1[i]); 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`);
}
});
}); });
} }
...@@ -27,8 +27,9 @@ describe("LightWeightMapTest", function () { ...@@ -27,8 +27,9 @@ describe("LightWeightMapTest", function () {
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
expect(lightWeightMap != undefined).assertEqual(true); expect(lightWeightMap != undefined).assertEqual(true);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("Cannot create new TreeMap"); expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The LightWeightMap's constructor cannot be directly invoked");
} }
}); });
...@@ -651,31 +652,35 @@ describe("LightWeightMapTest", function () { ...@@ -651,31 +652,35 @@ describe("LightWeightMapTest", function () {
lightWeightMap.set("e", "E"); lightWeightMap.set("e", "E");
try { try {
lightWeightMap.increaseCapacityTo("qwe"); lightWeightMap.increaseCapacityTo("qwe");
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the size is not integer"); expect(err.code).assertEqual(401);
expect(err.message).assertEqual(`The type of "minimumCapacity" must be number. Received value is: qwe`);
} }
}); });
/** /**
* @tc.name: testRemoveAt038 * @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 * @tc.author: wangyong
*/ */
it("testRemoveAt038", 0, function () { it("testRemoveAt038", 0, function () {
let lightWeightMap = new LightWeightMap(); let lightWeightMap = new LightWeightMap();
try { try {
let res = lightWeightMap.removeAt("123"); let res = lightWeightMap.removeAt("a");
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("index is not integer"); expect(err.code).assertEqual(401);
expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`);
} }
}); });
/** /**
* @tc.name: testGetValueAt039 * @tc.name: testGetValueAt039
* @tc.desc: Get the value of the key value pair according to the corresponding index. * @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 * @tc.author: wangyong
*/ */
it("testGetValueAt039", 0, function () { it("testGetValueAt039", 0, function () {
...@@ -686,17 +691,19 @@ describe("LightWeightMapTest", function () { ...@@ -686,17 +691,19 @@ describe("LightWeightMapTest", function () {
lightWeightMap.set(4, "D"); lightWeightMap.set(4, "D");
lightWeightMap.set(5, "E"); lightWeightMap.set(5, "E");
try { try {
let res = lightWeightMap.getValueAt("123"); let res = lightWeightMap.getValueAt("a");
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is not integer"); expect(err.code).assertEqual(401);
expect(err.message).assertEqual(`The type of "index" must be number. Received value is: a`);
} }
}); });
/** /**
* @tc.name: testGetKeyAt040 * @tc.name: testGetKeyAt040
* @tc.desc: Find the key of the key value pair according to the corresponding index. * @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 * @tc.author: wangyong
*/ */
it("testGetKeyAt040", 0, function () { it("testGetKeyAt040", 0, function () {
...@@ -707,10 +714,12 @@ describe("LightWeightMapTest", function () { ...@@ -707,10 +714,12 @@ describe("LightWeightMapTest", function () {
lightWeightMap.set(4, "D"); lightWeightMap.set(4, "D");
lightWeightMap.set(5, "E"); lightWeightMap.set(5, "E");
try { try {
let res = lightWeightMap.getKeyAt("123"); let res = lightWeightMap.getKeyAt("a");
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is not integer"); 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 () { ...@@ -885,5 +894,127 @@ describe("LightWeightMapTest", function () {
let res = lightWeightMap.hasAll(lightWeightMap1); let res = lightWeightMap.hasAll(lightWeightMap1);
expect(res).assertEqual(false); 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`);
}
});
}); });
} }
...@@ -27,8 +27,9 @@ describe("LightWeightSetTest", function () { ...@@ -27,8 +27,9 @@ describe("LightWeightSetTest", function () {
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
expect(lightWeightSet != undefined).assertEqual(true); expect(lightWeightSet != undefined).assertEqual(true);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("Cannot create new TreeMap"); expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The LightWeightSet's constructor cannot be directly invoked");
} }
}); });
...@@ -526,9 +527,11 @@ describe("LightWeightSetTest", function () { ...@@ -526,9 +527,11 @@ describe("LightWeightSetTest", function () {
lightWeightSet.add(5); lightWeightSet.add(5);
try { try {
lightWeightSet.increaseCapacityTo(3); lightWeightSet.increaseCapacityTo(3);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is not integer"); 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 () { ...@@ -547,24 +550,28 @@ describe("LightWeightSetTest", function () {
lightWeightSet.add(5); lightWeightSet.add(5);
try { try {
let res = lightWeightSet.increaseCapacityTo("qwe"); let res = lightWeightSet.increaseCapacityTo("qwe");
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is not integer"); expect(err.code).assertEqual(401);
expect(err.message).assertEqual(`The type of "minimumCapacity" must be number. Received value is: qwe`);
} }
}); });
/** /**
* @tc.name: testRemoveAt032 * @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 * @tc.author: wangyong
*/ */
it("testRemoveAt032", 0, function () { it("testRemoveAt032", 0, function () {
let lightWeightSet = new LightWeightSet(); let lightWeightSet = new LightWeightSet();
try { try {
let res = lightWeightSet.removeAt("123"); let res = lightWeightSet.removeAt("a");
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is not integer"); 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 () { ...@@ -587,7 +594,7 @@ describe("LightWeightSetTest", function () {
/** /**
* @tc.name: testGetValueAt034 * @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 * @tc.author: wangyong
*/ */
it("testGetValueAt034", 0, function () { it("testGetValueAt034", 0, function () {
...@@ -598,10 +605,12 @@ describe("LightWeightSetTest", function () { ...@@ -598,10 +605,12 @@ describe("LightWeightSetTest", function () {
lightWeightSet.add(4); lightWeightSet.add(4);
lightWeightSet.add(5); lightWeightSet.add(5);
try { try {
let res = lightWeightSet.getValueAt("123"); let res = lightWeightSet.getValueAt("a");
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is not integer"); 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 () { ...@@ -693,12 +702,8 @@ describe("LightWeightSetTest", function () {
lightWeightSet.add(3); lightWeightSet.add(3);
lightWeightSet.add(4); lightWeightSet.add(4);
lightWeightSet.add(5); lightWeightSet.add(5);
try { let res = lightWeightSet.remove("A");
let res = lightWeightSet.remove("A"); expect(res).assertEqual(undefined);
} catch (err) {
expect(err.name).assertEqual("TypeError");
expect(err.message).assertEqual("the index is not integer");
}
}); });
/** /**
...@@ -755,5 +760,45 @@ describe("LightWeightSetTest", function () { ...@@ -755,5 +760,45 @@ describe("LightWeightSetTest", function () {
let res = lightWeightSet.equal(obj); let res = lightWeightSet.equal(obj);
expect(res).assertEqual(false); 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`);
}
});
}); });
} }
...@@ -26,8 +26,9 @@ describe("PlainArrayTest", function () { ...@@ -26,8 +26,9 @@ describe("PlainArrayTest", function () {
try { try {
let plainArray = new PlainArray(); let plainArray = new PlainArray();
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("Cannot create new PlainArray"); expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The PlainArray's constructor cannot be directly invoked");
} }
}); });
...@@ -180,7 +181,7 @@ describe("PlainArrayTest", function () { ...@@ -180,7 +181,7 @@ describe("PlainArrayTest", function () {
/** /**
* @tc.name: testHas011 * @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 * @tc.author: wangyong
*/ */
it("testHas011", 0, function () { it("testHas011", 0, function () {
...@@ -190,7 +191,7 @@ describe("PlainArrayTest", function () { ...@@ -190,7 +191,7 @@ describe("PlainArrayTest", function () {
plainArray.add(3, "C"); plainArray.add(3, "C");
plainArray.add(4, "D"); plainArray.add(4, "D");
plainArray.add(5, "E"); plainArray.add(5, "E");
let res = plainArray.has("a"); let res = plainArray.has(6);
expect(res).assertEqual(false); expect(res).assertEqual(false);
let res1 = plainArray.has(1); let res1 = plainArray.has(1);
expect(res1).assertEqual(true); expect(res1).assertEqual(true);
...@@ -267,8 +268,6 @@ describe("PlainArrayTest", function () { ...@@ -267,8 +268,6 @@ describe("PlainArrayTest", function () {
plainArray.add(5, "E"); plainArray.add(5, "E");
let res = plainArray.getKeyAt(2); let res = plainArray.getKeyAt(2);
expect(res).assertEqual(3); expect(res).assertEqual(3);
res = plainArray.getKeyAt(10);
expect(res).assertEqual(undefined);
}); });
/** /**
...@@ -307,8 +306,6 @@ describe("PlainArrayTest", function () { ...@@ -307,8 +306,6 @@ describe("PlainArrayTest", function () {
expect(res).assertEqual("C"); expect(res).assertEqual("C");
let value = plainArray.get(3); let value = plainArray.get(3);
expect(value).assertEqual(undefined); expect(value).assertEqual(undefined);
res = plainArray.removeAt(12);
expect(res).assertEqual(undefined);
}); });
/** /**
...@@ -332,15 +329,19 @@ describe("PlainArrayTest", function () { ...@@ -332,15 +329,19 @@ describe("PlainArrayTest", function () {
} }
try { try {
plainArray.removeRangeFrom(15, 5); plainArray.removeRangeFrom(15, 5);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is out-of-bounds"); 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 { try {
plainArray.removeRangeFrom(1, -1); plainArray.removeRangeFrom(1, "a");
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the size cannot be less than 0"); 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 () { ...@@ -365,9 +366,11 @@ describe("PlainArrayTest", function () {
} }
try { try {
plainArray.setValueAt(-1, "X"); plainArray.setValueAt(-1, "X");
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is out-of-bounds"); 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 () { ...@@ -444,8 +447,6 @@ describe("PlainArrayTest", function () {
plainArray.add(5, "E"); plainArray.add(5, "E");
let res = plainArray.getValueAt(2); let res = plainArray.getValueAt(2);
expect(res).assertEqual("C"); expect(res).assertEqual("C");
res = plainArray.getValueAt(12);
expect(res).assertEqual(undefined);
}); });
/** /**
...@@ -474,16 +475,18 @@ describe("PlainArrayTest", function () { ...@@ -474,16 +475,18 @@ describe("PlainArrayTest", function () {
/** /**
* @tc.name: testAdd026 * @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 * @tc.author: wangyong
*/ */
it("testAdd026", 0, function () { it("testAdd026", 0, function () {
let plainArray = new PlainArray(); let plainArray = new PlainArray();
try { try {
let res = plainArray.add("123", null); let res = plainArray.add("a", null);
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is not integer"); 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 () { ...@@ -567,8 +570,14 @@ describe("PlainArrayTest", function () {
plainArray.add(3, "C"); plainArray.add(3, "C");
plainArray.add(4, "D"); plainArray.add(4, "D");
plainArray.add(5, "E"); plainArray.add(5, "E");
let res = plainArray.getValueAt(50); try {
expect(res).assertEqual(undefined); 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 () { ...@@ -584,16 +593,18 @@ describe("PlainArrayTest", function () {
/** /**
* @tc.name: testRemoveAt033 * @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 * @tc.author: wangyong
*/ */
it("testRemoveAt033", 0, function () { it("testRemoveAt033", 0, function () {
let plainArray = new PlainArray(); let plainArray = new PlainArray();
try { try {
let res = plainArray.removeAt(2); let res = plainArray.removeAt("a");
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is out-of-bounds"); 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 () { ...@@ -630,9 +641,11 @@ describe("PlainArrayTest", function () {
plainArray.add(5, "E"); plainArray.add(5, "E");
try { try {
plainArray.setValueAt(8, "V"); plainArray.setValueAt(8, "V");
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("RangeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is out-of-bounds"); 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 () { ...@@ -715,9 +728,11 @@ describe("PlainArrayTest", function () {
plainArray.add(-2, "b"); plainArray.add(-2, "b");
try { try {
plainArray.add("a", "c"); plainArray.add("a", "c");
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is not integer"); 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); let res = plainArray.get(-2);
expect(res).assertEqual("b"); expect(res).assertEqual("b");
...@@ -775,13 +790,121 @@ describe("PlainArrayTest", function () { ...@@ -775,13 +790,121 @@ describe("PlainArrayTest", function () {
let plainArray = new PlainArray(); let plainArray = new PlainArray();
plainArray.add(-2, "b"); plainArray.add(-2, "b");
try { try {
plainArray.add(1.23, "a"); plainArray.add("b", "a");
expect(true).assertEqual(false);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("the index is not integer"); 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); let res = plainArray.get(-2);
expect(res).assertEqual("b"); 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);
});
}); });
} }
...@@ -27,8 +27,9 @@ describe("TreeMapTest", function () { ...@@ -27,8 +27,9 @@ describe("TreeMapTest", function () {
let treeMap = new TreeMap(); let treeMap = new TreeMap();
expect(treeMap != undefined).assertEqual(true); expect(treeMap != undefined).assertEqual(true);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("Cannot create new TreeMap"); expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The TreeMap's constructor cannot be directly invoked");
} }
}); });
...@@ -631,5 +632,24 @@ describe("TreeMapTest", function () { ...@@ -631,5 +632,24 @@ describe("TreeMapTest", function () {
let res1 = treeMap.isEmpty(); let res1 = treeMap.isEmpty();
expect(res1).assertEqual(true); 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`);
}
});
}); });
} }
...@@ -27,8 +27,9 @@ describe("TreeSetTest", function () { ...@@ -27,8 +27,9 @@ describe("TreeSetTest", function () {
let treeSet = new TreeSet(); let treeSet = new TreeSet();
expect(treeSet != undefined).assertEqual(true); expect(treeSet != undefined).assertEqual(true);
} catch (err) { } catch (err) {
expect(err.name).assertEqual("TypeError"); expect(err.name).assertEqual("BusinessError");
expect(err.message).assertEqual("Cannot create new TreeSet"); expect(err.code).assertEqual(10200012);
expect(err.message).assertEqual("The TreeSet's constructor cannot be directly invoked");
} }
}); });
...@@ -557,5 +558,22 @@ describe("TreeSetTest", function () { ...@@ -557,5 +558,22 @@ describe("TreeSetTest", function () {
expect(arr[i]).assertEqual(arr1[i]); 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`);
}
});
}); });
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册