未验证 提交 a57c1e1b 编写于 作者: O openharmony_ci 提交者: Gitee

!8113 Add error code cases in the containers module

Merge pull request !8113 from bwx1067111/master
......@@ -1115,5 +1115,121 @@ describe("ArraylistTest", function () {
expect(err.message).assertEqual(`The type of "fromIndex" must be number. Received value is: a`);
}
});
/**
* @tc.name: testHas059
* @tc.desc: Check whether the ArrayList contains a specified element.
* For example: arrayList.has.bind({})().
*/
it('testHas059', 0, function () {
let arrayList = new ArrayList();
try {
arrayList.has.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The has method cannot be bound`);
}
});
/**
* @tc.name: testRemoveByIndex060
* @tc.desc: In the ArrayList instance, delete the element based on its index.
* For example: arrayList.removeByIndex.bind({})().
*/
it('testRemoveByIndex060', 0, function () {
let arrayList = new ArrayList();
try {
arrayList.removeByIndex.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The removeByIndex method cannot be bound`);
}
});
/**
* @tc.name: testRemove061
* @tc.desc: Delete the specified element . For example: arrayList.remove.bind({})().
*/
it('testRemove061', 0, function () {
let arrayList = new ArrayList();
try {
arrayList.remove.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The remove method cannot be bound`);
}
});
/**
* @tc.name: testForEach062
* @tc.desc: Traversing elements in an ArrayList instance.
* For example: arrayList.forEach.bind({}, "a")(() => {}).
*/
it('testForEach062', 0, function () {
let arrayList = new ArrayList();
try {
arrayList.forEach.bind({}, "a")(() => {});
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The forEach method cannot be bound`);
}
});
/**
* @tc.name: testForEach063
* @tc.desc: Traversing elements in an ArrayList instance.
* For example: arrayList.forEach(11).
*/
it('testForEach063', 0, function () {
let arrayList = new ArrayList();
try {
arrayList.forEach(11);
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: 11`);
}
});
/**
* @tc.name: testClear064
* @tc.desc: Clear all elements in the ArrayList instance. For example: arrayList.clear.bind({}, "a")().
*/
it('testClear064', 0, function () {
let arrayList = new ArrayList();
try {
arrayList.clear.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The clear method cannot be bound`);
}
});
/**
* @tc.name: testIsEmpty065
* @tc.desc: Determine whether the ArrayList instance is empty. For example: arrayList.isEmpty.bind({}, "a")().
*/
it('testIsEmpty065', 0, function () {
let arrayList = new ArrayList();
try {
arrayList.isEmpty.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The isEmpty method cannot be bound`);
}
});
});
}
......@@ -1145,5 +1145,69 @@ describe("ListTest", function () {
expect(err.message).assertEqual(`The type of "fromIndex" must be number. Received value is: a`);
}
});
/**
* @tc.name: testAdd072
* @tc.desc: Add a element to the end of the List instance. For example: list.add.bind({}, "a")().
*/
it('testAdd072', 0, function () {
let list = new List();
try {
list.add.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The add method cannot be bound`);
}
});
/**
* @tc.name: testForEach073
* @tc.desc: Traversing elements in an List instance. For example: list.forEach(11).
*/
it('testForEach073', 0, function () {
let list = new List();
try {
list.forEach(11);
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: 11`);
}
});
/**
* @tc.name: testForEach074
* @tc.desc: Traversing elements in an List instance. For example: list.forEach.bind({}, "a")().
*/
it('testForEach074', 0, function () {
let list = new List();
try {
list.forEach.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The forEach method cannot be bound`);
}
});
/**
* @tc.name: testIsEmpty075
* @tc.desc: Determine whether the List instance is empty. For example: list.isEmpty.bind({}, "a")().
*/
it('testIsEmpty075', 0, function () {
let list = new List();
try {
list.isEmpty.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The isEmpty method cannot be bound`);
}
});
});
}
......@@ -496,5 +496,37 @@ describe("StackTest", function () {
expect(err.message).assertEqual(`The push method cannot be bound`);
}
});
/**
* @tc.name: testIsEmpty037
* @tc.desc: Determine whether the Stack instance is empty. For example: stack.isEmpty.bind({}, "a")().
*/
it('testIsEmpty037', 0, function () {
let stack = new Stack();
try {
stack.isEmpty.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The isEmpty method cannot be bound`);
}
});
/**
* @tc.name: testPop038
* @tc.desc: Delete top of stack element. For example: stack.pop.bind({}, "a")().
*/
it('testPop038', 0, function () {
let stack = new Stack();
try {
stack.pop.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The pop method cannot be bound`);
}
});
});
}
......@@ -740,5 +740,117 @@ describe("HashMapTest", function () {
expect(err.message).assertEqual(`The set method cannot be bound`);
}
});
/**
* @tc.name: testIsEmpty050
* @tc.desc: Determine whether the HashMap instance is empty. For example: hashMap.isEmpty.bind({}, "a")().
*/
it('testIsEmpty050', 0, function () {
let hashMap = new HashMap();
try {
hashMap.isEmpty.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The isEmpty method cannot be bound`);
}
});
/**
* @tc.name: testHasKey051
* @tc.desc: Determine whether the HashMap contains the specified key. For example: hashMap.hasKey.bind({}, "a")().
*/
it('testHasKey051', 0, function () {
let hashMap = new HashMap();
try {
hashMap.hasKey.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The hasKey method cannot be bound`);
}
});
/**
* @tc.name: testGet052
* @tc.desc: Get the corresponding value through the key. For example: hashMap.get.bind({}, "a")().
*/
it('testGet052', 0, function () {
let hashMap = new HashMap();
try {
hashMap.get.bind({}, "a")();
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: testSet053
* @tc.desc: Add a pair of key value pairs to the HashMap. For example: hashMap.set(undefined, 11).
*/
it('testSet053', 0, function () {
let hashMap = new HashMap();
try {
hashMap.set(undefined, 11);
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 Key of JS. Received value is: undefined`);
}
});
/**
* @tc.name: testRemove054
* @tc.desc: Delete key value pairs according to key. For example: hashMap.remove.bind({}, "a")().
*/
it('testRemove054', 0, function () {
let hashMap = new HashMap();
try {
hashMap.remove.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The remove method cannot be bound`);
}
});
/**
* @tc.name: testForEach055
* @tc.desc: Traverse all key value pairs in the HashMap instance.For example: hashMap.forEach.bind({}, "a")().
*/
it('testForEach055', 0, function () {
let hashMap = new HashMap();
try {
hashMap.forEach.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The forEach method cannot be bound`);
}
});
/**
* @tc.name: testForEach056
* @tc.desc: Traverse all key value pairs in the HashMap instance.For example: hashMap.forEach(11).
*/
it('testForEach056', 0, function () {
let hashMap = new HashMap();
try {
hashMap.forEach(11);
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: 11`);
}
});
});
}
......@@ -540,5 +540,55 @@ describe("HashSetTest", function () {
expect(err.message).assertEqual(`The add method cannot be bound`);
}
});
/**
* @tc.name: testIsEmpty034
* @tc.desc: Determine whether the HashSet instance is empty. For example: hashSet.isEmpty.bind({}, "a")().
*/
it('testIsEmpty034', 0, function () {
let hashSet = new HashSet();
try {
hashSet.isEmpty.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The isEmpty method cannot be bound`);
}
});
/**
* @tc.name: testForEach035
* @tc.desc: Traverse the collection of all elements of the HashSet instance.
* For example: hashSet.forEach.bind({}, "a")().
*/
it('testForEach035', 0, function () {
let hashSet = new HashSet();
try {
hashSet.forEach.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The forEach method cannot be bound`);
}
});
/**
* @tc.name: testForEach036
* @tc.desc: Traverse the collection of all elements of the HashSet instance.
* For example: hashSet.forEach(11).
*/
it('testForEach036', 0, function () {
let hashSet = new HashSet();
try {
hashSet.forEach(11);
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: 11`);
}
});
});
}
......@@ -537,5 +537,139 @@ describe("TreeSetTest", function () {
expect(err.message).assertEqual(`The add method cannot be bound`);
}
});
/**
* @tc.name: testClear039
* @tc.desc: Clear all elements of the TreeSet instance. For example: treeSet.clear.bind({}, "a")().
*/
it('testClear039', 0, function () {
let treeSet = new TreeSet();
try {
treeSet.clear.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The clear method cannot be bound`);
}
});
/**
* @tc.name: testGetLowerValue040
* @tc.desc: Get a value that is a little lower than the specified value sort.
* For example: treeSet.getLowerValue.bind({}, "a")().
*/
it('testGetLowerValue040', 0, function () {
let treeSet = new TreeSet();
try {
treeSet.getLowerValue.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The getLowerValue method cannot be bound`);
}
});
/**
* @tc.name: testGetLowerValue041
* @tc.desc: Get a value that is a little lower than the specified value sort.
* For example: treeSet.getLowerValue(null).
*/
it('testGetLowerValue041', 0, function () {
let treeSet = new TreeSet();
try {
treeSet.getLowerValue(null);
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 not null. Received value is: null`);
}
});
/**
* @tc.name: testGetHigherValue042
* @tc.desc: Get a value that is a little higher than the specified value sort.
* For example: treeSet.getHigherValue(null).
*/
it('testGetHigherValue042', 0, function () {
let treeSet = new TreeSet();
try {
treeSet.getHigherValue(null);
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 not null. Received value is: null`);
}
});
/**
* @tc.name: testGetHigherValue043
* @tc.desc: Get a value that is a little higher than the specified value sort.
* For example: treeSet.getHigherValue.bind({}, "a")().
*/
it('testGetHigherValue043', 0, function () {
let treeSet = new TreeSet();
try {
treeSet.getHigherValue.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The getHigherValue method cannot be bound`);
}
});
/**
* @tc.name: testForEach044
* @tc.desc: Traverse the collection of all elements of the TreeSet instance.
* For example: treeSet.forEach.bind({}, "a")().
*/
it('testForEach044', 0, function () {
let treeSet = new TreeSet();
try {
treeSet.forEach.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The forEach method cannot be bound`);
}
});
/**
* @tc.name: testForEach045
* @tc.desc: Traverse the collection of all elements of the TreeSet instance.
* For example: treeSet.forEach(11).
*/
it('testForEach045', 0, function () {
let treeSet = new TreeSet();
try {
treeSet.forEach(11);
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: 11`);
}
});
/**
* @tc.name: testValues046
* @tc.desc: Get a collection of all the values in the TreeSet. For example: treeSet.values.bind({}, "a")().
*/
it('testValues046', 0, function () {
let treeSet = new TreeSet();
try {
treeSet.values.bind({}, "a")();
expect(true).assertEqual(false);
} catch (err) {
expect(err.name).assertEqual("BusinessError");
expect(err.code).assertEqual(10200011);
expect(err.message).assertEqual(`The Symbol.iterator method cannot be bound`);
}
});
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册