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

!1759 Add XTS test cases

Merge pull request !1759 from 冷昌晶/weekly_20220125
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License')
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import {Deque} from '@ohos.deque'
describe('DequeTest', function () {
it('SR000GGR3K_testConstructor001', 0, function () {
try{
let deque = new Deque();
}catch(err){
expect(err).assertEqual("Error:Cannot create new deque")
}
})
it('SR000GGR3K_testInsertFront001', 0, function () {
let deque = new Deque();
deque.insertFront("");
let res = deque.getFirst();
expect(res).assertEqual("");
})
it('SR000GGR3K_testInsertFront002', 0, function () {
let deque = new Deque();
deque.insertFront(8);
let res = deque.getFirst();
expect(res).assertEqual(8)
})
it('SR000GGR3K_testInsertFront003', 0, function () {
let deque = new Deque();
let a ={name:'lala',age:'15'}
deque.insertFront(a);
let res = deque.getFirst();
expect(res).assertEqual(a)
})
it('SR000GGR3K_testInsertFront004', 0, function () {
let deque = new Deque();
let a =[1,2,3,4]
deque.insertFront(a);
let res = deque.getFirst();
expect(res).assertEqual(a)
})
it('SR000GGR3K_testInsertEnd005', 0, function () {
let deque = new Deque();
deque.insertEnd(8);
let res = deque.getLast()
expect(res).assertEqual(8)
})
it('SR000GGR3K_testInsertEnd006', 0, function () {
let deque = new Deque();
let a = ['a','b','c']
deque.insertEnd(a);
let res = deque.getLast()
expect(res).assertEqual(a)
})
it('SR000GGR3K_testInsertEnd007', 0, function () {
let deque = new Deque();
let a = { class:'6班',say:'we'}
deque.insertEnd(a);
let res = deque.getLast()
expect(res).assertEqual(a)
})
it('SR000GGR3K_testGetFirst007', 0, function () {
let deque = new Deque();
deque.insertEnd("");
deque.insertEnd("");
let res = deque.getFirst()
expect(res).assertEqual("")
})
it('SR000GGR3K_testGetLast008', 0, function () {
let deque = new Deque();
deque.insertEnd(8);
deque.insertEnd("");
let res = deque.getLast()
expect(res).assertEqual("")
})
it('SR000GGR3K_testHas009', 0, function () {
let deque = new Deque();
deque.insertEnd(6);
let res = deque.has(6)
expect(res).assertEqual(true)
})
it('SR000GGR3K_testHas010', 0, function () {
let deque = new Deque();
deque.insertEnd(8);
let res = deque.has(6)
expect(res).assertEqual(false)
})
it('SR000GGR3K_testPopFirst011', 0, function () {
let deque = new Deque();
deque.insertEnd(8);
deque.insertFront("")
let res = deque.popFirst()
expect(res).assertEqual("")
})
it('SR000GGR3K_testPopLast012', 0, function () {
let deque = new Deque();
deque.insertEnd(8);
deque.insertFront("")
deque.insertFront("")
let res = deque.popLast()
expect(res).assertEqual(8)
})
it('SR000GGR3K_testForEach013', 0, function () {
let deque = new Deque();
deque.insertEnd(8);
deque.insertFront("")
deque.insertFront("")
deque.insertEnd(1);
deque.insertEnd(2);
deque.insertEnd(3);
deque.insertEnd(4);
deque.insertEnd(5);
deque.insertEnd(6);
deque.insertFront("")
deque.insertFront("")
let arr = []
deque.forEach((item,index)=>{
arr.push(item);
})
let a=["","","","",8,1,2,3,4,5,6]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR3K_testIterator014', 0, function () {
let deque = new Deque();
deque.insertEnd(8);
deque.insertFront("")
deque.insertFront("")
deque.insertEnd(5);
deque.insertEnd(6);
deque.insertFront("")
deque.insertFront("")
let arr =[]
for(let item of deque) {
arr.push(item);
}
let a = ["","","","",8,5,6]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR3K_testInsertFront015', 0, function () {
let deque = new Deque();
deque.insertFront('$');
let res = deque.getFirst();
expect(res).assertEqual("$");
})
it('SR000GGR3K_testInsertFront016', 0, function () {
let deque = new Deque();
deque.insertFront(" ");
let res = deque.getFirst();
expect(res).assertEqual(" ");
})
it('SR000GGR3K_testInsertFront017', 0, function () {
let deque = new Deque();
deque.insertFront(null);
let res = deque.getFirst();
expect(res).assertEqual(null);
})
it('SR000GGR3K_testInsertFront018', 0, function () {
let deque = new Deque();
deque.insertFront(undefined);
let res = deque.getFirst();
expect(res).assertEqual(undefined);
})
it('SR000GGR3K_testInsertFront019', 0, function () {
let deque = new Deque();
let i = 0
for (; i < 100; i++) {
deque.insertFront(i);
}
let res = deque.getFirst();
let res1 = deque.length;
expect(res).assertEqual(i - 1);
expect(res1).assertEqual(100);
})
it('SR000GGR3K_testInsertEnd020', 0, function () {
let deque = new Deque();
deque.insertEnd('$');
let res = deque.getLast()
expect(res).assertEqual('$')
})
it('SR000GGR3K_testInsertEnd021', 0, function () {
let deque = new Deque();
deque.insertEnd(" ");
let res = deque.getLast()
expect(res).assertEqual(" ")
})
it('SR000GGR3K_testInsertEnd022', 0, function () {
let deque = new Deque();
deque.insertEnd(null);
let res = deque.getLast()
expect(res).assertEqual(null)
})
it('SR000GGR3K_testInsertEnd023', 0, function () {
let deque = new Deque();
deque.insertEnd(undefined);
let res = deque.getLast()
expect(res).assertEqual(undefined)
})
it('SR000GGR3K_testInsertFront024', 0, function () {
let deque = new Deque();
let i = 0
for (; i < 100; i++) {
deque.insertEnd(i);
}
let res = deque.getLast();
let res1 = deque.length;
expect(res).assertEqual(i - 1);
expect(res1).assertEqual(100);
})
it('SR000GGR3K_testHas025', 0, function () {
let deque = new Deque();
let res = deque.has(6)
expect(res).assertEqual(false)
})
it('SR000GGR3K_testPopFirst026', 0, function () {
let deque = new Deque();
let res = deque.popFirst();
expect(res).assertEqual(undefined);
})
it('SR000GGR3K_testGetFirst027', 0, function () {
let deque = new Deque();
let res = deque.getFirst();
expect(res).assertEqual(undefined)
})
it('SR000GGR3K_testPopLast028', 0, function () {
let deque = new Deque();
try{
let res = deque.popLast();
}catch(err){
expect(err).assertEqual("Error: Deque: get out-of-bounds");
}
})
it('SR000GGR3K_testGetLast029', 0, function () {
let deque = new Deque();
try{
let res = deque.getLast();
}catch(err){
expect(err).assertEqual("Error: Deque: get out-of-bounds")
}
})
it('SR000GGR3K_testForEach030', 0, function () {
let deque = new Deque();
deque.insertEnd(8);
deque.insertEnd(1);
deque.insertEnd(2);
deque.insertEnd(3);
deque.insertEnd(3);
deque.insertEnd(4);
deque.insertEnd(5);
deque.insertEnd(6);
deque.popFirst();
deque.popLast();
deque.insertFront(8);
deque.insertEnd(6);
let arr = [];
deque.forEach((item,index)=>{
arr.push(item);
})
let a=[8,1,2,3,3,4,5,6]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR3K_testIterator031', 0, function () {
let deque = new Deque();
deque.insertEnd(8);
deque.insertFront("")
deque.insertFront("")
deque.insertEnd(5);
deque.insertEnd(6);
deque.insertFront("")
deque.insertFront("")
deque.popFirst();
deque.popLast();
deque.insertFront("");
deque.insertEnd(6);
let arr =[];
for(let item of deque) {
arr.push(item);
}
let a = ["","","","",8,5,6]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
})
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License')
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import {HashMap} from '@ohos.hashmap'
describe('HashMapTest', function () {
it('SR000GGR4B_testConstructor001', 0, function () {
try{
let hashmap = new HashMap();
expect(hashmap != undefined).assertEqual(true);
}catch(err){
expect(err).assertEqual("Error: Cannot create new HashMap")
}
})
it('SR000GGR4B_testSet002', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
let res = hashmap.get(1);
expect(res).assertEqual("A");
})
it('SR000GGR4B_testSet003', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,2);
let res = hashmap.get(1);
expect(res).assertEqual(2);
})
it('SR000GGR4B_testSet004', 0, function () {
let hashmap = new HashMap();
let c = [1,2,3]
hashmap.set(1,c);
let res = hashmap.get(1);
expect(res).assertEqual(c);
})
it('SR000GGR4B_testSet005', 0, function () {
let hashmap = new HashMap();
let c = { name: 'lili', age: '13' }
hashmap.set(1,c);
let res = hashmap.get(1);
expect(res).assertEqual(c);
})
it('SR000GGR4B_testSet006', 0, function () {
let hashmap = new HashMap();
hashmap.set("a","A");
let res = hashmap.get("a");
expect(res).assertEqual("A");
})
it('SR000GGR4B_testLength007', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
let res = hashmap.length;
expect(res).assertEqual(5);
})
it('SR000GGR4B_testHasKey008', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
let res = hashmap.hasKey(3);
expect(res).assertEqual(true);
let res1 = hashmap.hasKey(8);
expect(res1).assertEqual(false);
})
it('SR000GGR4B_testHasValue009', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
let res = hashmap.hasValue("C");
expect(res).assertEqual(true);
let res1 = hashmap.hasValue(8);
expect(res1).assertEqual(false);
})
it('SR000GGR4B_testGet010', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
let res = hashmap.get(3);
expect(res).assertEqual("C");
})
it('SR000GGR4B_testSetAll011', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
let hashmap1 = new HashMap();
hashmap1.set(1,1);
hashmap1.set(2,2);
hashmap.setAll(hashmap1);
let arr = [];
for(let [key,value] of hashmap) {
arr.push([key,value]);
}
arr.sort(function(a, b){return a[0] - b[0]});
for(let i = 0; i < arr.length; i++){
expect(arr[i][0]).assertEqual(i + 1);
expect(arr[i][1]).assertEqual(hashmap.get(i + 1));
}
})
it('SR000GGR4B_testRemove012', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
let res= hashmap.remove(3);
expect(res).assertEqual("C");
let res1 = hashmap.length;
expect(res1).assertEqual(4);
})
it('SR000GGR4B_testClear013', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
let res = hashmap.length;
expect(res).assertEqual(5);
hashmap.clear();
let res1 = hashmap.length;
expect(res1).assertEqual(0);
})
it('SR000GGR4B_testKeys014', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
let res = hashmap.keys();
for(let i = 0; i < hashmap.length; i++){
}
})
it('SR000GGR4B_testValues015', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
let res = hashmap.values();
let i = 0;
for(; i < hashmap.length; i++){
let has = hashmap.hasValue(res.next().value);
expect(has).assertEqual(true);
}
})
it('SR000GGR4B_testReplace016', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
let res = hashmap.replace(2,"G");
expect(res).assertEqual(true);
expect(hashmap.get(2)).assertEqual("G");
})
it('SR000GGR4B_testForEach017', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
let vals = [];
let keys = [];
hashmap.forEach((value,key)=>{
keys.push(key);
vals.push(value);
})
for(let i = 0; i < keys.length; i++){
let has = hashmap.hasKey(keys[i]);
expect(has).assertEqual(true);
}
for(let i = 0; i < vals.length; i++){
let has = hashmap.hasValue(vals[i]);
expect(has).assertEqual(true);
}
})
it('SR000GGR4B_testIterator018', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
let arr = [];
for(let [key,value] of hashmap) {
arr.push([key,value]);
}
arr.sort(function(a, b){return a[0] - b[0]});
for(let i = 0; i < arr.length; i++){
expect(arr[i][0]).assertEqual(i + 1);
expect(arr[i][1]).assertEqual(hashmap.get(i + 1));
}
})
it('SR000GGR4B_testEntries019', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
let res = hashmap.entries();
let arr = [];
for(let i = 0; i < hashmap.length; i++){
let obj = res.next();
arr.push([obj.value[0], obj.value[1]]);
}
arr.sort(function(a, b){return a[0] - b[0]});
for(let i = 0; i < arr.length; i++){
expect(arr[i][0]).assertEqual(i + 1);
expect(arr[i][1]).assertEqual(hashmap.get(i + 1));
}
})
it('SR000GGR4B_testSet020', 0, function () {
let hashmap = new HashMap();
hashmap.set('',"A");
let res = hashmap.get('');
expect(res).assertEqual("A");
})
it('SR000GGR4B_testSet021', 0, function () {
let hashmap = new HashMap();
hashmap.set('$',"A");
let res = hashmap.get('$');
expect(res).assertEqual("A");
})
it('SR000GGR4B_testSet022', 0, function () {
let hashmap = new HashMap();
hashmap.set(3.14,"A");
let res = hashmap.get(3.14);
expect(res).assertEqual("A");
})
it('SR000GGR4B_testSet007', 0, function () {
let hashmap = new HashMap();
hashmap.set(0.3,"A");//key值为浮点数
let res = hashmap.get(0.3);
expect(res).assertEqual("A");
})
it('SR000GGR4B_testSet023', 0, function () {
let hashmap = new HashMap();
hashmap.set(-1,"A");
let res = hashmap.get(-1);
expect(res).assertEqual("A");
})
it('SR000GGR4B_testSet024', 0, function () {
let hashmap = new HashMap();
let a = {};
hashmap.set(a,"A");
let res = hashmap.get(a);
expect(res).assertEqual("A");
})
it('SR000GGR4B_testSet025', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,null);
try{
let res = hashmap.get(1);
expect(res).assertEqual(null);
}catch(err){
expect(err).assertEqual("Error: this hashmap don't find the key")
}
})
it('SR000GGR4B_testSet026', 0, function () {
let hashmap = new HashMap();
hashmap.set(1, '$');
let res = hashmap.get(1);
expect(res).assertEqual('$');
})
it('SR000GGR4B_testSet027', 0, function () {
let hashmap = new HashMap();
hashmap.set(1, 3.14);
let res = hashmap.get(1);
expect(res).assertEqual(3.14);
})
it('SR000GGR4B_testSet028', 0, function () {
let hashmap = new HashMap();
hashmap.set(1, -1);
let res = hashmap.get(1);
expect(res).assertEqual(-1);
})
it('SR000GGR4B_testSet029', 0, function () {
let hashmap = new HashMap();
let a = {};
hashmap.set(1,a);
let res = hashmap.get(1);
expect(res).assertEqual(a);
})
it('SR000GGR4B_testSet030', 0, function () {
let hashmap = new HashMap();
let i = 0;
for (; i < 100; i++) {
hashmap.set(1, i);
}
let res = hashmap.get(1);
let res1 = hashmap.length;
expect(res).assertEqual(99);
expect(res1).assertEqual(1);
})
it('SR000GGR4B_testSet031', 0, function () {
let hashmap = new HashMap();
let i = 0;
for (; i < 100; i++) {
hashmap.set(i, 1);
}
let res = hashmap.get(i - 1);
let res1 = hashmap.length;
expect(res).assertEqual(1);
expect(res1).assertEqual(100);
})
it('SR000GGR4B_testIterator032', 0, function () {
let hashmap = new HashMap();
let arr = [];
try {
for (let item of hashmap) {
arr.push(item);
}
} catch (err) {
expect(err).assertEqual("Error: Cannot create new HashMap")
}
expect(arr.length).assertEqual(0);
})
it('SR000GGR4B_testForEach033', 0, function () {
let hashmap = new HashMap();
let arr = [];
try {
hashmap.forEach((item, index) => {
arr.push(item);
})
} catch (err) {
expect(err).assertEqual("Error:Cannot create new stack")
}
expect(arr.length).assertEqual(0);
})
it('SR000GGR4B_testIsEmpty034', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
let res = hashmap.length;
let res1 = hashmap.isEmpty();
expect(res).assertEqual(5);
expect(res1).assertEqual(false);
})
it('SR000GGR4B_testIsEmpty035', 0, function () {
let hashmap = new HashMap();
hashmap.set(1,"A");
hashmap.set(2,"B");
hashmap.set(3,"C");
hashmap.set(4,"D");
hashmap.set(5,"E");
hashmap.clear();
let res = hashmap.length;
let res1 = hashmap.isEmpty();
expect(res).assertEqual(0);
expect(res1).assertEqual(true);
})
it('SR000GGR4B_testHasKey036', 0, function () {
let hashmap = new HashMap();
let res = hashmap.hasKey(8);
expect(res).assertEqual(false);
})
it('SR000GGR4B_testHasValue037', 0, function () {
let hashmap = new HashMap();
let res = hashmap.hasValue(8);
expect(res).assertEqual(false);
})
it('SR000GGR4B_testRemove038', 0, function () {
let hashmap = new HashMap();
try{
let res= hashmap.remove(3);
}catch(err){
expect(err).assertEqual("Error: The removed element does not exist in this container")
}
})
it('SR000GGR4B_testReplace039', 0, function () {
let hashmap = new HashMap();
let res = hashmap.replace(2,"G");
expect(res).assertEqual(false);
})
it('SR000GGR4B_testGet040', 0, function () {
let hashmap = new HashMap();
try{
let res = hashmap.get(3);
}catch(err){
expect(err).assertEqual("Error: this hashmap don't find the key")
}
})
it('SR000GGR4B_testSetAll041', 0, function () {
let hashmap = new HashMap();
let hashmap1 = new HashMap();
hashmap1.set(1,1);
hashmap1.set(2,2);
hashmap.setAll(hashmap1);
let arr = [];
for(let [key,value] of hashmap) {
arr.push([key,value]);
}
arr.sort(function(a, b){return a[0] - b[0]});
for(let i = 0; i < arr.length; i++){
expect(arr[i]).assertEqual([i + 1,hashmap.get(i + 1)]);
}
})
it('SR000GGR4B_testClear042', 0, function () {
let hashmap = new HashMap();
hashmap.clear();
let res = hashmap.length;
expect(res).assertEqual(0);
})
it('SR000GGR4B_testEntries043', 0, function () {
let hashmap = new HashMap();
let res = hashmap.entries();
expect(undefined).assertEqual(res.next().value);
})
})
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License')
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import {HashSet} from '@ohos.hashset'
describe('HashSetTest', function () {
it('SR000GGR3J_testNew001', 0, function () {
try{
let hashset = new HashSet();
}catch(err){
expect(err).assertEqual("Error: Cannot create new HashSet")
}
})
it('SR000GGR3J_testAdd001', 0, function () {
let hashset = new HashSet();
hashset.add(1);
let res = hashset.has(1);
expect(res).assertEqual(true);
})
it('SR000GGR3J_testAdd002', 0, function () {
let hashset = new HashSet();
hashset.add("b");
hashset.add("c");
hashset.add("d");
hashset.add("a");
hashset.add("g");
let res = hashset.has("a");
expect(res).assertEqual(true);
})
it('SR000GGR3J_testAdd004',0, function () {
let hashset = new HashSet();
let c = [1,2,3]
hashset.add(c);
let res = hashset.has(c);
expect(res).assertEqual(true);
})
it('SR000GGR3J_testAdd005', 0, function () {
let hashset = new HashSet();
let c = { name: 'lili', age: '13' }
hashset.add(c);
let res = hashset.has(c);
expect(res).assertEqual(true);
})
it('SR000GGR3J_testLength006', 0, function () {
let hashset = new HashSet();
hashset.add(1);
hashset.add(2);
hashset.add(3);
hashset.add(4);
hashset.add(5);
let res = hashset.length;
expect(res).assertEqual(5);
})
it('SR000GGR3J_testHas007', 0, function () {
let hashset = new HashSet();
hashset.add(4);
hashset.add(1);
hashset.add(3);
hashset.add(2);
hashset.add(5);
let res = hashset.has(1);
expect(res).assertEqual(true);
let res1 = hashset.has("A");
expect(res1).assertEqual(false);
})
it('SR000GGR3J_testIsEmpty008', 0, function () {
let hashset = new HashSet();
hashset.add(4);
hashset.add(1);
hashset.add(3);
hashset.add(2);
hashset.add(5);
let res = hashset.isEmpty();
expect(res).assertEqual(false);
})
it('SR000GGR3J_testRemove009', 0, function () {
let hashset = new HashSet();
hashset.add(4);
hashset.add(1);
hashset.add(3);
hashset.add(2);
hashset.add(5);
let res = hashset.remove(1);
expect(res).assertEqual(true);
let arr = []
hashset.forEach((value,index)=>{
arr.push(value);
})
let i = 0;
for(; i < arr.length; i++){
let has = hashset.has(arr[i]);
expect(has).assertEqual(true);
}
})
it('SR000GGR3J_testClear010', 0, function () {
let hashset = new HashSet();
hashset.add(4);
hashset.add(1);
hashset.add(3);
hashset.add(2);
hashset.add(5);
let res = hashset.length;
expect(res).assertEqual(5);
hashset.clear();
let res1 = hashset.length;
expect(res1).assertEqual(0);
})
it('SR000GGR3J_testValues011', 0, function () {
let hashset = new HashSet();
hashset.add("A");
hashset.add("B");
hashset.add("C");
hashset.add("D");
hashset.add("E");
let res = hashset.values();
let i = 0;
for(; i < hashset.length; i++){
let has = hashset.has(res.next().value);
expect(has).assertEqual(true);
}
})
it('SR000GGR3J_testForEach012', 0, function () {
let hashset = new HashSet();
hashset.add(1);
hashset.add(2);
hashset.add(3);
hashset.add(4);
hashset.add(5);
let arr = []
hashset.forEach((value,index)=>{
arr.push(value);
})
for(let i = 0; i < arr.length; i++){
let has = hashset.has(arr[i]);
expect(has).assertEqual(true);
}
})
it('SR000GGR3J_testIterator013', 0, function () {
let hashset = new HashSet();
hashset.add(1);
hashset.add(2);
hashset.add(3);
hashset.add(4);
hashset.add(5);
let arr=[]
for(let item of hashset){
arr.push(item)
}
for(let i = 0; i < arr.length; i++){
let has = hashset.has(arr[i]);
expect(has).assertEqual(true);
}
})
it('SR000GGR3J_testIterator014', 0, function () {
let hashset = new HashSet();
hashset.add("A");
hashset.add("B");
hashset.add("C");
hashset.add("D");
hashset.add("E");
let arr=[]
for(let item of hashset){
arr.push(item)
}
for(let i = 0; i < arr.length; i++){
let has = hashset.has(arr[i]);
expect(has).assertEqual(true);
}
})
it('SR000GGR3J_testEntries015', 0, function () {
let hashset = new HashSet();
hashset.add(1);
hashset.add(2);
hashset.add(3);
hashset.add(4);
hashset.add(5);
let res = hashset.entries();
let i = 0;
for(; i < hashset.length; i++){
let has = hashset.has(res.next().value[1]);
expect(has).assertEqual(true);
}
})
it('SR000GGR3J_testAdd016',0, function () {
let hashset = new HashSet();
hashset.add('');
let res = hashset.has('');
expect(res).assertEqual(true);
})
it('SR000GGR3J_testAdd017',0, function () {
let hashset = new HashSet();
hashset.add('$');
let res = hashset.has('$');
expect(res).assertEqual(true);
})
it('SR000GGR3J_testAdd017',0, function () {
let hashset = new HashSet();
hashset.add(1.34);
let res = hashset.has(1.34);
expect(res).assertEqual(true);
})
it('SR000GGR3J_testAdd018',0, function () {
let hashset = new HashSet();
hashset.add(-1);
let res = hashset.has(-1);
expect(res).assertEqual(true);
})
it('SR000GGR3J_testAdd019',0, function () {
let hashset = new HashSet();
let a = {};
hashset.add(a);
let res = hashset.has(a);
expect(res).assertEqual(true);
})
it('SR000GGR3J_testAdd020',0, function () {
let hashset = new HashSet();
let i = 0;
for (; i < 100; i++) {
hashset.add(i);
}
let res = hashset.has(i - 1);
let res1 = hashset.length;
expect(res).assertEqual(true);
expect(res1).assertEqual(100);
})
it('SR000GGR3J_testIterator021', 0, function () {
let hashset = new HashSet();
let i = 0;
for(let item of hashset){
expect(item).assertEqual(i);
i++;
}
})
it('SR000GGR3J_testForEach022', 0, function () {
let hashset = new HashSet();
let arr = [];
hashset.forEach((value,index)=>{
arr.push(value);
})
expect(arr.length).assertEqual(0);
})
it('SR000GGR3J_testIsEmpty023', 0, function () {
let hashset = new HashSet();
hashset.add(4);
hashset.add(1);
hashset.add(3);
hashset.add(2);
hashset.add(5);
hashset.clear();
let res = hashset.isEmpty();
expect(res).assertEqual(true);
})
it('SR000GGR3J_testHas024', 0, function () {
let hashset = new HashSet();
let res = hashset.has(1);
expect(res).assertEqual(false);
})
it('SR000GGR3J_testRemove025', 0, function () {
let hashset = new HashSet();
let res = hashset.remove(1);
expect(res).assertEqual(false);
})
it('SR000GGR3J_testClear026', 0, function () {
let hashset = new HashSet();
let res = hashset.clear();
expect(res).assertEqual(undefined);
})
it('SR000GGR3J_testEntries027', 0, function () {
let hashset = new HashSet();
let res = hashset.entries();
expect(res.next().value).assertEqual(undefined);
})
it('SR000GGR3J_testIterator028', 0, function () {
let hashset = new HashSet();
let i = 0;
for (; i < 100; i++) {
let text = hashset.add(i);
}
let arr = [];
for(let item of hashset){
arr.push(Number.parseInt(item));
}
for (i = 0; i < 100; i++) {
let a = arr[i];
let res = hashset.has(a);
expect(res).assertEqual(true);
}
})
it('SR000GGR3J_testForEach029', 0, function () {
let hashset = new HashSet();
let i = 0;
for (; i < 100; i++) {
hashset.add(i);
}
let arr = [];
hashset.forEach((value,index)=>{
arr.push(value);
})
for (i = 0; i < 100; i++) {
let a = arr[i];
let res = hashset.has(a);
expect(res).assertEqual(true);
}
})
it('SR000GGR3J_testAdd030', 0, function () {
let hashset = new HashSet();
hashset.add(1);
hashset.add(1);
let has = hashset.has(1);
let size = hashset.length;
expect(has).assertEqual(true);
expect(size).assertEqual(1);
})
})
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License')
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import {LightWeightSet} from '@ohos.lightweightset'
import {Struct} from "@ohos.struct"
describe('LightWeightSetTest', function () {
it('SR000GGR43_testNew001', 0, function () {
try{
let lightweightset = new LightWeightSet();
expect(lightweightset != undefined).assertEqual(true);
}catch(err){
expect(err).assertEqual("Error:Cannot create new TreeMap");
}
})
it('SR000GGR43_testAdd002', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
let res = lightweightset.has(1);
expect(res).assertEqual(true);
})
it('SR000GGR43_testAdd003', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add("a");
let res = lightweightset.has("a");
expect(res).assertEqual(true);
})
it('SR000GGR43_testAdd004', 0, function () {
let lightweightset = new LightWeightSet();
let a =[1,2,3,4]
lightweightset.add(a);
let res = lightweightset.has(a);
expect(res).assertEqual(true);
})
it('SR000GGR43_testAdd005', 0, function () {
let lightweightset = new LightWeightSet();
let c = { name: 'lili', age: '13' }
lightweightset.add(c);
let res = lightweightset.has(c);
expect(res).assertEqual(true);
})
it('SR000GGR43_testAdd006', 0, function () {
let lightweightset = new LightWeightSet();
let c = false;
lightweightset.add(c);
let res = lightweightset.has(c);
expect(res).assertEqual(true);
})
it('SR000GGR43_testLength007', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let res = lightweightset.length;
expect(res).assertEqual(5);
})
it('SR000GGR43_testAddAll008', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let lightweightset1 = new LightWeightSet();
lightweightset1.add(6);
lightweightset1.add(7);
let res1 = lightweightset.addAll(lightweightset1);
for(let item of lightweightset) {
}
for(let item of lightweightset1) {
}
for(let i=1; i < 8; i++) {
expect(lightweightset.has(i)).assertEqual(true);
}
expect(res1).assertEqual(true);
})
it('SR000GGR43_testHasAll009', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add("a");
lightweightset.add("b");
lightweightset.add("c");
lightweightset.add("d");
lightweightset.add("e");
let lightweightset1 = new LightWeightSet();
lightweightset1.add("a");
lightweightset1.add("d");
let res = lightweightset.hasAll(lightweightset1);
expect(res).assertEqual(true);
})
it('SR000GGR43_testHasAllr010', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add("a");
lightweightset.add("b");
lightweightset.add("c");
lightweightset.add("e");
let lightweightset1 = new LightWeightSet();
lightweightset1.add("a");
lightweightset1.add("d");
let res = lightweightset.hasAll(lightweightset1);
expect(res).assertEqual(false);
})
it('SR000GGR43_testHas011', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add("a");
lightweightset.add("b");
lightweightset.add("c");
lightweightset.add("d");
lightweightset.add("e");
let res = lightweightset.has("a");
expect(res).assertEqual(true);
let res1 = lightweightset.has(1);
expect(res1).assertEqual(false);
})
it('SR000GGR43_testEntries012', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let res = lightweightset.entries();
expect(JSON.stringify(res.next().value)).assertEqual("[1,1]");
expect(JSON.stringify(res.next().value)).assertEqual("[2,2]");
expect(JSON.stringify(res.next().value)).assertEqual("[3,3]");
expect(JSON.stringify(res.next().value)).assertEqual("[4,4]");
expect(JSON.stringify(res.next().value)).assertEqual("[5,5]");
})
it('SR000GGR43_testGetIndexOf013', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let res = lightweightset.getIndexOf(2);
expect(res).assertEqual(1);
})
it('SR000GGR43_testIsEmpty014', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let res = lightweightset.isEmpty();
expect(res).assertEqual(false);
})
it('SR000GGR43_testRemove015', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let res = lightweightset.remove(1);
expect(res).assertEqual(1);
let arr=[];
lightweightset.forEach((value,index)=>{
arr.push(value);
})
let arr1 =[2,3,4,5];
for(let i=0;i<arr.length;i++){
expect(arr1[i]).assertEqual(arr[i]);
}
})
it('SR000GGR43_testRemoveAt016', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let res = lightweightset.removeAt(1);
expect(res).assertEqual(true);
let arr=[];
lightweightset.forEach((value,index)=>{
arr.push(value);
})
let arr1 =[1,3,4,5];
for(let i=0;i<arr.length;i++){
expect(arr1[i]).assertEqual(arr[i]);
}
})
it('SR000GGR43_testClear017', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
lightweightset.clear();
let res = lightweightset.length;
expect(res).assertEqual(0);
})
it('SR000GGR43_testForEach018', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let arr = []
lightweightset.forEach((value,index)=>{
arr.push(value);
})
let arr1= [1,2,3,4,5];
for(let i=0;i<arr1.length;i++){
expect(arr[i]).assertEqual(arr1[i]);
}
})
it('SR000GGR43_testToString019', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
let res = lightweightset.toString();
expect(res).assertEqual("1,2,3");
})
it('SR000GGR43_testToArray020', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let res = lightweightset.toArray();
let arr1= [1,2,3,4,5];
for(let i=0;i<arr1.length;i++){
expect(res[i]).assertEqual(arr1[i]);
}
})
it('SR000GGR43_testGetValueAt021', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let res = lightweightset.getValueAt(1);
expect(res).assertEqual(2);
})
it('SR000GGR43_testIterator022', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let arr=[]
for(let item of lightweightset) {
let res = arr.push(item);
}
let arr1= [1,2,3,4,5];
for(let i=0;i<arr1.length;i++){
expect(arr[i]).assertEqual(arr1[i]);
}
})
it('SR000GGR43_testValues023', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let res = lightweightset.values()
expect(res.next().value).assertEqual(1);
expect(res.next().value).assertEqual(2);
expect(res.next().value).assertEqual(3);
expect(res.next().value).assertEqual(4);
expect(res.next().value).assertEqual(5);
})
it('SR000GGR43_testAdd024', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(null);
let res = lightweightset.has(null);
expect(res).assertEqual(true);
})
it('SR000GGR43_testAdd025', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1.23);
let res1 = lightweightset.has(1.23);
expect(res1).assertEqual(true);
})
it('SR000GGR43_testHasAll026', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let lightweightset1 = new LightWeightSet();
lightweightset1.add("a1");
lightweightset1.add("d1");
let res = lightweightset.hasAll(lightweightset1);
expect(res).assertEqual(false);
})
it('SR000GGR43_testHasAll027', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let lightweightset1 = new LightWeightSet();
lightweightset1.add(1);
lightweightset1.add("d");
let res = lightweightset.hasAll(lightweightset1);
expect(res).assertEqual(false);
})
it('SR000GGR43_testRemove028', 0, function () {
let lightweightset = new LightWeightSet();
try{
let res = lightweightset.remove(3);
}catch(err){
expect(err).assertEqual("Error: don't find the key in lightweight")
}
})
it('SR000GGR43_testRemoveAt029', 0, function () {
let lightweightset = new LightWeightSet();
let res = lightweightset.removeAt(1);
expect(res).assertEqual(false);
})
it('SR000GGR43_testIncreaseCapacityTo030', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
try{
let res = lightweightset.increaseCapacityTo(3);
}catch(err){
expect(err).assertEqual("Unable to shrink capacity")
}
})
it('SR000GGR43_testIncreaseCapacityTo031', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
try{
let res = lightweightset.increaseCapacityTo("qwe");
}catch(err){
expect(err).assertEqual("lightweightset: index must be int")
}
})
it('SR000GGR43_testRemoveAt032', 0, function () {
let lightweightset = new LightWeightSet();
try{
let res = lightweightset.removeAt("123");
}catch(err){
expect(err).assertEqual("lightweightset: index must be int")
}
})
it('SR000GGR43_testIncreaseCapacityTo033', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let res = lightweightset.increaseCapacityTo(20);
expect(res).assertEqual(undefined);
})
it('SR000GGR43_testGetValueAt034', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
try{
let res = lightweightset.getValueAt("123");
}catch(err){
expect(err).assertEqual("lightweightset: index must be int")
}
})
it('SR000GGR43_testIsEmpty035', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
lightweightset.clear();
let res = lightweightset.isEmpty();
expect(res).assertEqual(true);
})
it('SR000GGR43_testAdd036', 0, function () {
let lightweightset = new LightWeightSet();
for (let i = 0; i < 10000; i++) {
lightweightset.add(i);
}
let res = lightweightset.getValueAt(9999);
let res1 = lightweightset.length;
expect(res).assertEqual(9999);
expect(res1).assertEqual(10000);
})
it('SR000GGR43_testAdd037', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add('');
let res = lightweightset.has('');
expect(res).assertEqual(true);
})
it('SR000GGR43_testAdd038', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add('$');
let res = lightweightset.has('$');
expect(res).assertEqual(true);
})
it('SR000GGR43_testClear039', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
let res = lightweightset.length;
lightweightset.clear();
let res1 = lightweightset.length;
expect(res).assertEqual(5);
expect(res1).assertEqual(0);
})
it('SR000GGR43_testRemove040', 0, function () {
let lightweightset = new LightWeightSet();
lightweightset.add(1);
lightweightset.add(2);
lightweightset.add(3);
lightweightset.add(4);
lightweightset.add(5);
try{
let res = lightweightset.remove("A");
}catch(err){
expect(err).assertEqual("Error: don't find the key in lightweight")
}
})
})
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License')
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import {LinkedList} from '@ohos.linkedlist'
describe('LinkedListTest', function () {
it('SR000GGR46_testConstructor001', 0, function () {
try{
let linkedlist = new LinkedList();
}catch(err){
expect(err).assertEqual("Error:Cannot create new linkedlist")
}
})
it('SR000GGR46_testAdd002', 0, function () {
let linkedlist = new LinkedList();
linkedlist.add("");
let res = linkedlist.get(0)
expect(res).assertEqual("")
})
it('SR000GGR46_testAdd003', 0, function () {
let linkedlist = new LinkedList();
linkedlist .add(8);
let res = linkedlist .get(0)
expect(res).assertEqual(8)
})
it('SR000GGR46_testAdd004', 0, function () {
let linkedlist = new LinkedList();
let a=[1,2,3,4]
linkedlist .add(a);
let res = linkedlist.get(0)
expect(res).assertEqual(a)
})
it('SR000GGR46_testAdd005', 0, function () {
let linkedlist = new LinkedList();
let a={name:"lala",age:"13"}
linkedlist .add(a);
let res = linkedlist.get(0)
expect(res).assertEqual(a)
})
it('SR000GGR46_testAdd006', 0, function () {
let linkedlist = new LinkedList();
let a = '.';
linkedlist .add(a);
let res = linkedlist.get(0)
expect(res).assertEqual(a)
})
it('SR000GGR46_testAdd007', 0, function () {
let linkedlist = new LinkedList();
let a = '*';
linkedlist .add(a);
let res = linkedlist.get(0)
expect(res).assertEqual(a)
})
it('SR000GGR46_testAdd008', 0, function () {
let linkedlist = new LinkedList();
let a = '/"';
linkedlist .add(a);
let res = linkedlist.get(0)
expect(res).assertEqual(a)
})
it('SR000GGR46_testAdd009', 0, function () {
let linkedlist = new LinkedList();
let a = '';
linkedlist .add(a);
let res = linkedlist.get(0)
expect(res).assertEqual(a)
})
it('SR000GGR46_testAdd010', 0, function () {
let linkedlist = new LinkedList();
let a = 'a';
linkedlist .add(a);
linkedlist .add(a);
let res = linkedlist.get(0)
expect(res).assertEqual(a)
let res1 = linkedlist.get(1)
expect(res1).assertEqual(a)
})
it('SR000GGR46_testHas011', 0, function () {
let linkedlist = new LinkedList();
linkedlist.add("a");
linkedlist .add("b");
linkedlist .add("c");
let res = linkedlist.has("a");
expect(res).assertEqual(true);
let res1 = linkedlist.has("d");
expect(res1).assertEqual(false);
})
it('SR000GGR46_testClone012', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
let list1 = list.clone();
list1.addFirst("e");
let res = list1.removeLast();
expect(res).assertEqual("c");
let arr = []
list1.forEach((item,index)=>{
arr.push(item);
})
let a=["e","a","b"]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR46_testAddFirst013', 0, function () {
let linkedlist= new LinkedList();
linkedlist.add("a");
linkedlist.add("b");
linkedlist.add("c");
linkedlist.addFirst("e");
let res = linkedlist.get(0);
expect(res).assertEqual("e");
})
it('SR000GGR46_testRemoveFirst014', 0, function () {
let linkedlist= new LinkedList();
linkedlist.add("a");
linkedlist.add("b");
linkedlist.add("c");
let res = linkedlist.removeFirst();
expect(res).assertEqual("a");
let arr = []
linkedlist.forEach((item,index)=>{
arr.push(item);
})
let a=["b","c"]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR46_testGetLastIndexOf015', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list.add('b')
let res = list.getLastIndexOf("a");
expect(res).assertEqual(3);
})
it('SR000GGR46_testGetLastIndexOf016', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list.add('b')
let res = list.getLastIndexOf("f");
expect(res).assertEqual(-1);
})
it('SR000GGR46_testGetIndexOf017', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list.add('b')
let res = list.getIndexOf("b");
expect(res).assertEqual(1);
})
it('SR000GGR46_testGetIndexOf018', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list.add('b')
try {
let res = list.getIndexOf("f");
} catch(err) {
expect(err).assertEqual("");
}
})
it('SR000GGR46_testRemoveByIndex019', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.removeByIndex(2);
let arr=[];
list.forEach((item,index)=>{
arr.push(item);
})
let a=["a","b","a","b"]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR46_testRemoveByIndex020', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
try {
let res = list.removeByIndex(10);
} catch (err) {
expect(err).assertEqual("Error: removeByIndex is out-of-bounds")
}
})
it('SR000GGR46_testRemove0021', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.remove("a");
let arr=[];
list.forEach((item,index)=>{
arr.push(item);
})
let a=["b","c","a","b"];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR46_testRemove022', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.remove("d");
expect(res).assertEqual(false)
})
it('SR000GGR46_testRemove023', 0, function () {
let list= new LinkedList();
let res = list.remove("d");
expect(res).assertEqual(false)
})
it('SR000GGR46_testRemoveFirstFound024', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.removeFirstFound("b");
let arr=[];
list.forEach((item,index)=>{
arr.push(item);
})
let a=["a","c","a","b"];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR46_testRemoveLastFound025', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.removeLastFound("b");
let arr=[];
list.forEach((item,index)=>{
arr.push(item);
})
let a=["a","b","c","a"];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR46_testGetFirst026', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.getFirst();
expect(res).assertEqual("a")
})
it('SR000GGR46_testGetLast027', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.getLast();
expect(res).assertEqual("b")
})
it('SR000GGR46_testInsert028', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.insert(3,"d");
let arr=[];
list.forEach((item,index)=>{
arr.push(item);
})
let a=["a","b","c","d","a","b"];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR46_testInsert029', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.insert(0,"d");
let arr=[];
list.forEach((item,index)=>{
arr.push(item);
})
let a=["d","a","b","c","a","b"];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR46_testInsert030', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.insert(5,"d");
let arr=[];
list.forEach((item,index)=>{
arr.push(item);
})
let a=["a","b","c","a","b","d"];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR46_testInsert031', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
try {
let res = list.insert(8,"d");
} catch(err) {
expect(err).assertEqual("Error: index cannot Less than 0 and more than this length")
}
})
it('SR000GGR46_testSet032', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
let res = list.set(2,"d");
let res1 = list.get(2);
expect(res1).assertEqual("d")
})
it('SR000GGR46_testConvertToArray033', 0, function () {
let list= new LinkedList();
list.add(4);
list.add(3);
list.add(1);
list.add(2);
list.add(14);
let res = list.convertToArray();
let a=[4,3,1,2,14];
for(let i=0;i<a.length;i++){
expect(res[i]).assertEqual(a[i])
}
})
it('SR000GGR46_testLength034', 0, function () {
let list= new LinkedList();
list.add(4);
list.add(3);
list.add(1);
list.add(2);
list.add(14);
let res = list.length;
expect(res).assertEqual(5);
})
it('SR000GGR46_testClear035', 0, function () {
let list= new LinkedList();
list.add(4);
list.add(3);
list.add(1);
list.add(2);
list.add(14);
list.clear()
let res = list.length;
expect(res).assertEqual(0);
})
it('SR000GGR46_testIterator036', 0, function () {
let list = new LinkedList();
list.add(8);
list.add("")
list.add("")
list.add(5);
let c=[1,2,3,4];
list.add(c);
list.add(6);
list.add("")
list.add("")
let arr = [];
let a = [8,"","",5,c,6,"",""];
for (let item of list) {
arr.push(item);
}
for (let index = 0; index < list.length; index++) {
expect(arr[index]).assertEqual(a[index]);
}
})
it('SR000GGR46_testForEach037', 0, function () {
let list = new LinkedList();
list.add(8);
list.add("")
list.add("")
list.add(5);
let c=[1,2,3,4];
list.add(c);
list.add(6);
list.add("")
list.add("")
let arr =[]
list.forEach((item,index)=>{
arr.push(item);
})
let a = [8,"","",5,c,6,"",""]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR46_testRemoveLast038', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.addFirst("e");
let res = list.removeLast();
expect(res).assertEqual("c");
let arr = []
list.forEach((item,index)=>{
arr.push(item);
})
let a=["e","a","b"]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR46_testGet039', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.get(1);
expect(res).assertEqual("b")
})
it('SR000GGR46_testGet040', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
try{
let res = list.get(10);
}catch(err){
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
})
it('SR000GGR46_testListGet041', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list[1];
list.forEach((item,index)=>{
})
expect(res).assertEqual("b")
})
it('SR000GGR46_testListSet042', 0, function () {
let list= new LinkedList();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list[1] = "f";
let res = list[1];
list.forEach((item,index)=>{
})
expect(res).assertEqual("f")
})
it('SR000GGR46_testAdd043', 0, function () {
let linkedlist = new LinkedList();
for (let i = 0; i < 100; i++) {
linkedlist .add(i);
}
let res = linkedlist.get(99);
expect(res).assertEqual(99);
})
it('SR000GGR46_testRemoveByIndex044', 0, function () {
let linkedlist= new LinkedList();
try {
let res = linkedlist.removeByIndex(1);
} catch (err) {
expect(err).assertEqual("Error: removeByIndex is out-of-bounds");
}
})
it('SR000GGR46_testClone045', 0, function () {
let linkedlist= new LinkedList();
try {
let newlist = linkedlist.clone();
} catch (err) {
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
})
it('SR000GGR46_testGetIndexOf046', 0, function () {
let linkedlist= new LinkedList();
let res = linkedlist.getIndexOf(1);
expect(res).assertEqual(-1);
})
it('SR000GGR46_testForEach047', 0, function () {
let linkedlist= new LinkedList();
let num = 0
try {
linkedlist.forEach((item, index)=>{
num++;
})
} catch (err) {
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
expect(num).assertEqual(0);
})
it('SR000GGR46_testIsEmpty048', 0, function () {
let linkedlist= new LinkedList();
try {
let res = linkedlist.IsEmpty();
} catch (err) {
expect(err).assertEqual("TypeError: is not callable")
}
})
it('SR000GGR46_testHas049', 0, function () {
let linkedlist= new LinkedList();
try {
let res = linkedlist.has(1);
} catch (err) {
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
})
it('SR000GGR46_testGet050', 0, function () {
let linkedlist= new LinkedList();
try {
let res = linkedlist.get(1);
} catch (err) {
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
})
it('SR000GGR46_testClear051', 0, function () {
let linkedlist= new LinkedList();
linkedlist.clear();
const len = linkedlist.length;
expect(len).assertEqual(0);
})
it('SR000GGR46_testGetLast052', 0, function () {
let linkedlist= new LinkedList();
try {
let res = linkedlist.getLast();
} catch (err) {
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
})
it('SR000GGR46_testGetFirst053', 0, function () {
let linkedlist= new LinkedList();
try {
let res = linkedlist.getFirst();
} catch (err) {
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
})
it('SR000GGR46_testAdd054', 0, function () {
let linkedlist= new LinkedList();
linkedlist.add(null);
let res = linkedlist.get(0)
expect(res).assertEqual(null);
})
it('SR000GGR46_testAdd055', 0, function () {
let linkedlist= new LinkedList();
linkedlist.add(0.1);
let res = linkedlist.get(0)
expect(res).assertEqual(0.1);
})
it('SR000GGR46_testAdd056', 0, function () {
let linkedlist= new LinkedList();
linkedlist.add(-1);
let res = linkedlist.get(0)
expect(res).assertEqual(-1);
})
it('SR000GGR46_testAdd057', 0, function () {
let linkedlist= new LinkedList();
const obj = {}
linkedlist.add(obj);
let res = linkedlist.get(0)
expect(res).assertEqual(obj);
})
})
\ No newline at end of file
......@@ -14,4 +14,18 @@
*/
require('./ExampleJsunit.test.js')
require('./util.test.js')
\ No newline at end of file
require('./util.test.js')
require('./Deque.test.js')
require('./ArrayList.test.js')
require('./Queue.test.js')
require('./Stack.test.js')
require('./ContainerList.test.js')
require('./LinkedList.test.js')
require('./Vector.test.js')
require('./LightWeightMap.test.js')
require('./LightWeightSet.test.js')
require('./HashMap.test.js')
require('./HashSet.test.js')
require('./PlainArray.test.js')
require('./TreeMap.test.js')
require('./TreeSet.test.js')
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License')
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import {PlainArray} from '@ohos.plainarray'
describe('SR000GGR45_PlainArrayTest', function () {
it('SR000GGR45_testConstructor001', 0, function () {
try{
let plainarray = new PlainArray();
}catch(err){
expect(err).assertEqual("Error:Cannot create new PlainArray")
}
})
it('SR000GGR45_testAdd002', 0, function () {
let plainarray = new PlainArray();
plainarray.add(1,"A");
let res = plainarray.get(1);
expect(res).assertEqual("A");
})
it('SR000GGR45_testAdd003', 0, function () {
let plainarray = new PlainArray();
let a=[1,2,3,4]
plainarray.add(2,a);
let res = plainarray.get(2);
expect(res).assertEqual(a);
})
it('SR000GGR45_testAdd004', 0, function () {
let plainarray = new PlainArray();
let c = { name: 'lili', age: '13' }
plainarray.add(1,c);
let res = plainarray.get(1);
expect(res).assertEqual(c);
})
it('SR000GGR45_testAdd005', 0, function () {
let plainarray = new PlainArray();
let c = false
plainarray.add(1,c);
let res = plainarray.get(1);
expect(res).assertEqual(false);
})
it('SR000GGR45_testAdd006', 0, function () {
let plainarray = new PlainArray();
plainarray.add(1,3);
let res = plainarray.get(1);
expect(res).assertEqual(3);
})
it('SR000GGR45_testGet007', 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.get(4);
expect(res).assertEqual("D");
try{
res = plainarray.get(10);
}catch(err){
expect(err).assertEqual("Error: Key error found");
}
})
it('SR000GGR45_testLength008', 0, function () {
let plainarray = new PlainArray();
let res = plainarray.length;
expect(res).assertEqual(0);
plainarray.add(1,"A");
plainarray.add(2,"B");
plainarray.add(3,"C");
plainarray.add(4,"D");
plainarray.add(5,"E");
res = plainarray.length;
expect(res).assertEqual(5);
})
it('SR000GGR45_testClone009', 0, function () {
let plainarray = new PlainArray();
let clonePlainarray = plainarray.clone();
let cloneLength = clonePlainarray.length; // 克隆空集
expect(cloneLength).assertEqual(0);
plainarray.add(1,"A");
plainarray.add(2,"B");
plainarray.add(3,"C");
plainarray.add(4,"D");
plainarray.add(5,"E");
let res = plainarray.clone();
let arr=[];
res.forEach((value,index)=>{
arr.push(value);
})
let arr1=["A","B","C","D","E"];
for(let i=0;i<arr.length;i++){
expect(arr[i]).assertEqual(arr1[i]);
}
})
it('SR000GGR45_testClear010', 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.length;
expect(res).assertEqual(5);
plainarray.clear();
let res1 = plainarray.length;
expect(res1).assertEqual(0);
plainarray.clear();
let res2 = plainarray.length;
expect(res2).assertEqual(0);
})
it('SR000GGR45_testHas011', 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.has("a");
expect(res).assertEqual(false);
let res1 = plainarray.has(1);
expect(res1).assertEqual(true);
})
it('SR000GGR45_testGetIndexOfKey012', 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.getIndexOfKey(2);
expect(res).assertEqual(1);
res = plainarray.getIndexOfKey(12);
expect(res).assertEqual(-1);
})
it('SR000GGR45_testGetIndexOfValue013', 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.getIndexOfValue("A");
expect(res).assertEqual(0);
res = plainarray.getIndexOfValue("Z");
expect(res).assertEqual(-1);
})
it('SR000GGR45_testIsEmpty014', 0, function () {
let plainarray = new PlainArray();
let result = plainarray.length;
expect(result).assertEqual(0);
plainarray.add(1,"A");
plainarray.add(2,"B");
plainarray.add(3,"C");
plainarray.add(4,"D");
plainarray.add(5,"E");
let res = plainarray.isEmpty();
expect(res).assertEqual(false);
})
it('SR000GGR45_testGetKeyAt015', 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.getKeyAt(2);
expect(res).assertEqual(3);
res = plainarray.getKeyAt(10);
expect(res).assertEqual(undefined);
})
it('SR000GGR45_testReMove016', 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.remove(2);
expect(res).assertEqual("B");
try{
res = plainarray.remove(12);
}catch(err){
expect(err).assertEqual("Error: element not in this plainarray");
}
let arr=[];
for(let item of plainarray){
arr.push(item);
}
let arr1=["1,A","3,C","4,D","5,E"];
for(let i=0;i<arr.length;i++){
expect(arr[i]).assertEqual(arr1[i]);
}
})
it('SR000GGR45_testReMoveAt017', 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(2);
expect(res).assertEqual("C");
try{
res = plainarray.removeAt(12);
}catch(err){
expect(err).assertEqual("Error: index not in this plainarray range");
}
let arr=[];
for(let item of plainarray){
arr.push(item);
}
let arr1=["1,A","2,B","4,D","5,E"];
for(let i=0;i<arr.length;i++){
expect(arr[i]).assertEqual(arr1[i]);
}
})
it('SR000GGR45_testReMoveRangeFrom018', 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");
plainarray.removeRangeFrom(2,2);
let arr=[];
for(let item of plainarray){
arr.push(item);
}
let arr1=["1,A","2,B","5,E"];
for(let i=0;i<arr.length;i++){
expect(arr[i]).assertEqual(arr1[i]);
}
try{
plainarray.removeRangeFrom(15, 5);
}catch(err){
expect(err).assertEqual("Error: index not in this plainarray range");
}
try{
plainarray.removeRangeFrom(1, -1);
}catch(err){
expect(err).assertEqual("index not in this plainarray range");
}
})
it('SR000GGR45_testSetValueAt019', 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");
plainarray.setValueAt(2,"V");
let arr=[];
for(let item of plainarray){
arr.push(item);
}
let arr1=["1,A","2,B","3,V","4,D","5,E"];
for(let i=0;i<arr.length;i++){
expect(arr[i]).assertEqual(arr1[i]);
}
try{
plainarray.setValueAt(-1, "X");
}catch(err){
expect(err).assertEqual("Error: index Out Of Bounds");
}
})
it('SR000GGR45_testToString020', 0, function () {
let plainarray = new PlainArray();
let res1 = plainarray.toString();
expect(res1).assertEqual("");
plainarray.add(1,"A");
plainarray.add(2,"B");
plainarray.add(3,"C");
let res = plainarray.toString();
expect(res).assertEqual("1:A,2:B,3:C");
})
it('SR000GGR45_testForEach021', 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 arr = []
let keyArr = []
plainarray.forEach((key,index)=>{
keyArr.push(key);
})
plainarray.forEach((value,index)=>{
arr.push(value);
})
let arr1= ["A","B","C","D","E"];
for(let i=0;i<arr1.length;i++){
expect(arr[i]).assertEqual(arr1[i]);
}
let keyArr1= [1,2,3,4,5];
for(let i=0;i<keyArr1.length;i++){
expect(keyArr[i]).assertEqual(keyArr[i]);
}
})
it('SR000GGR45_testIterator022', 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 arr=[]
for(let item of plainarray){
arr.push(item)
}
let arr1= ["1,A","2,B","3,C","4,D","5,E"];
for(let i=0;i<arr1.length;i++){
expect(arr[i]).assertEqual(arr1[i]);
}
})
it('SR000GGR45_testGetValueAt023', 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.getValueAt(2);
expect(res).assertEqual("C")
res = plainarray.getValueAt(12);
expect(res).assertEqual(undefined)
})
it('SR000GGR45_testAdd024', 0, function () {
let plainarray = new PlainArray();
plainarray.add(1, 3.1);
let res = plainarray.get(1);
expect(res).assertEqual(3.1);
})
it('SR000GGR45_testAdd024', 0, function () {
let plainarray = new PlainArray();
plainarray.add(1, null);
let res = plainarray.get(1);
expect(res).assertEqual(null);
})
it('SR000GGR45_testAdd025', 0, function () {
let plainarray = new PlainArray();
try{
let res = plainarray.add("123", null);
}catch(err){
expect(err).assertEqual("Error: PlainArray's only number is allowed")
}
})
it('SR000GGR45_testGet026', 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{
let res = plainarray.get(8);
}catch(err){
expect(err).assertEqual("Error: Key error found")
}
})
it('SR000GGR45_testGetIndexOfKey027', 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.getIndexOfKey(9);
expect(res).assertEqual(-1);
})
it('SR000GGR45_testGetIndexOfValue028', 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.getIndexOfValue("Asad");
expect(res).assertEqual(-1);
})
it('SR000GGR45_testGetKeyAt029', 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.getKeyAt(50);
expect(res).assertEqual(null);
})
it('SR000GGR45_testGetValueAt030', 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.getValueAt(50);
expect(res).assertEqual(null);
})
it('SR000GGR45_testRemove031', 0, function () {
let plainarray = new PlainArray();
try{
let res = plainarray.remove(2);
}catch(err){
expect(err).assertEqual("Error: element not in this plainarray")
}
})
it('SR000GGR45_testRemoveAt032', 0, function () {
let plainarray = new PlainArray();
try{
let res = plainarray.removeAt(2);
}catch(err){
expect(err).assertEqual("Error: index not in this plainarray range")
}
})
it('SR000GGR45_testReMoveRangeFrom033', 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");
plainarray.removeRangeFrom(0, 5);
let res = plainarray.length;
expect(res).assertEqual(0);
})
it('SR000GGR45_testSetValueAt034', 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.setValueAt(8,"V");
}catch(err){
expect(err).assertEqual("Error: index Out Of Bounds")
}
})
it('SR000GGR45_testAdd035', 0, function () {
let plainarray = new PlainArray();
for (let i = 0; i < 100; i++) {
plainarray.add(i, i+1);
}
let res = plainarray.get(1);
let res1 = plainarray.length;
expect(res).assertEqual(2);
expect(res1).assertEqual(100);
})
it('SR000GGR45_testAdd036', 0, function () {
let plainarray = new PlainArray();
for (let i = 0; i < 1000; i++) {
plainarray.add(i, i+1);
}
let res = plainarray.get(99);
let res1 = plainarray.length;
expect(res).assertEqual(100);
expect(res1).assertEqual(1000);
})
it('SR000GGR45_testAdd037', 0, function () {
let plainarray = new PlainArray();
plainarray.add(3,"a");
plainarray.add(1,"b");
plainarray.add(2,"c");
plainarray.add(5,"d");
plainarray.add(4,"e");
let res = plainarray.get(2);
expect(res).assertEqual("c");
})
it('SR000GGR45_testAdd038', 0, function () {
let plainarray = new PlainArray();
plainarray.add(1,"ABCd");
plainarray.add(2,"~!@#$^&*()_+-*/=.?<>:;\|{}[]");
plainarray.add(3,null);
plainarray.add(4,undefined);
plainarray.add(5,[]);
plainarray.add(6,{});
plainarray.add(7,true);
plainarray.add(8,1234);
plainarray.add(9,1.234);
plainarray.add(10,-1234);
let res = plainarray.get(2);
expect(res).assertEqual("~!@#$^&*()_+-*/=.?<>:;\|{}[]");
})
it('SR000GGR45_testAdd039', 0, function () {
let plainarray = new PlainArray();
plainarray.add(1.23,"a");
plainarray.add(-2,"b");
try{
plainarray.add("a","c");
}catch(err){
expect(err).assertEqual("Error: PlainArray's only number is allowed")
}
let res = plainarray.get(-2);
expect(res).assertEqual("b");
})
it('SR000GGR45_testAdd040', 0, function () {
let plainarray = new PlainArray();
plainarray.add(1,1);
plainarray.add(2,"b");
plainarray.add(3,true);
plainarray.add(4,[1,2,3,4]);
plainarray.add(5,{ name: 'lili', age: '13' });
plainarray.add(6,undefined);
plainarray.add(7,null);
let res = plainarray.get(2);
expect(res).assertEqual("b");
})
})
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License')
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import {Queue} from '@ohos.queue'
describe('QueueTest', function () {
it('SR000GGR48_test_Constructor001', 0, function () {
try{
let queue = new Queue();
}catch(err){
expect(err).assertEqual("Error:Cannot create new queue")
}
})
it('SR000GGR48_test_add002', 0, function () {
let queue = new Queue();
queue.add("");
let res = queue.getFirst()
expect(res).assertEqual("")
})
it('SR000GGR48_test_add003', 0, function () {
let queue = new Queue();
queue.add(8);
let res = queue.getFirst()
expect(res).assertEqual(8)
})
it('SR000GGR48_test_add004', 0, function () {
let queue = new Queue();
let a = ['a','b','c']
queue.add(a);
let res = queue.getFirst()
expect(res).assertEqual(a)
})
it('SR000GGR48_test_getFirst005', 0, function () {
let queue = new Queue();
queue.add(6);
queue.add('')
let res = queue.getFirst()
expect(res).assertEqual(6)
})
it('SR000GGR48_test_pop006', 0, function () {
let queue = new Queue();
queue.add(6);
queue.add('')
let res = queue.pop();
let res1 = queue.getFirst();
expect(res).assertEqual(6)
expect(res1).assertEqual('')
})
it('SR000GGR48_test_forEach007', 0, function () {
let queue = new Queue();
queue.add(8);
queue.add("")
queue.add("")
queue.add(1);
queue.add(2);
queue.add(3);
queue.add(4);
queue.add(5);
queue.add(6);
let c =['a','b','c','d'];
queue.add(c)
let arr = []
queue.forEach((item,index)=>{
arr.push(item);
})
let a=[8,"","",1,2,3,4,5,6,c]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR48_test_iterator008', 0, function () {
let queue= new Queue();
queue.add(8);
queue.add("")
queue.add("")
queue.add(5);
queue.add(6);
queue.add("")
queue.add("")
let arr =[]
for(let item of queue) {
arr.push(item);
}
let a = [8,"","",5,6,"",""]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR48_test_length009', 0, function () {
let queue = new Queue();
queue.add(8);
queue.add("")
queue.add("")
queue.add(1);
queue.add(2);
queue.add(3);
queue.add(4);
queue.add(5);
queue.add(6);
let res = queue.length;
expect(9).assertEqual(res)
})
it('SR000GGR48_test_add010', 0, function () {
let queue = new Queue();
queue.add("$");
let res = queue.getFirst()
expect(res).assertEqual("$")
})
it('SR000GGR48_test_add011', 0, function () {
let queue = new Queue();
queue.add(" ");
let res = queue.getFirst()
expect(res).assertEqual(" ")
})
it('SR000GGR48_test_add012', 0, function () {
let queue = new Queue();
queue.add(null);
let res = queue.getFirst()
expect(res).assertEqual(null)
})
it('SR000GGR48_test_add013', 0, function () {
let queue = new Queue();
queue.add(undefined);
let res = queue.getFirst()
expect(res).assertEqual(undefined)
})
it('SR000GGR48_test_add014', 0, function () {
let queue = new Queue();
let i = 0;
for (; i < 100; i++) {
queue.add(i);
}
let res = queue.length;
expect(res).assertEqual(100)
})
it('SR000GGR48_test_getFirst015', 0, function () {
let queue = new Queue();
let res = queue.getFirst()
expect(res).assertEqual(undefined)
})
it('SR000GGR48_test_pop016', 0, function () {
let queue = new Queue();
let res = queue.pop()
expect(res).assertEqual(undefined)
})
it('SR000GGR48_test_foreach017', 0, function () {
let queue = new Queue();
let arr = [];
try {
queue.forEach((item, index) => {
arr.push(item);
})
} catch (err) {
expect(err).assertEqual("Error: Queue: get out-of-bounds")
}
expect(arr.length).assertEqual(1);
})
it('SR000GGR48_test_iterator018', 0, function () {
let queue = new Queue();
let arr = [];
try {
for(let item of queue) {
arr.push(item);
}
} catch (err) {
expect(err).assertEqual("Error:Cannot create new stack")
}
expect(arr.length).assertEqual(0);
})
})
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册