未验证 提交 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 {ArrayList} from '@ohos.arraylist'
describe('ArraylistTest', function () {
it('SR000GGR44_testConstructor001', 0, function () {
try{
let arraylist = new ArrayList();
expect(arraylist != undefined).assertEqual(true)
}catch(err){
expect(err).assertEqual("Error: Cannot create new arraylist")
}
})
it('SR000GGR44_testAdd002', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
let res = arraylist.has("")
expect(res).assertEqual(true)
})
it('SR000GGR44_testAdd003', 0, function () {
let arraylist = new ArrayList();
arraylist.add(8);
let res = arraylist.has(8)
expect(res).assertEqual(true)
})
it('SR000GGR44_testAdd004 ', 0, function () {
let arraylist = new ArrayList();
let a={name:'lala',age:'13岁'}
arraylist.add(a);
let res = arraylist.has(a)
expect(res).assertEqual(true)
})
it('SR000GGR44_testAdd005 ', 0, function () {
let arraylist = new ArrayList();
let a=[1,2,3,4]
arraylist.add(a);
let res = arraylist.has(a)
expect(res).assertEqual(true)
})
it('SR000GGR44_testAdd006 ', 0, function () {
let arraylist = new ArrayList();
let a = true
arraylist.add(a);
let res = arraylist.has(a)
expect(res).assertEqual(true)
})
it('SR000GGR44_testInsert007', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add('a')
arraylist.insert(8,2)
let arr=[];
arraylist.forEach((item,index)=>{
arr.push(item);
})
let a=["","",8,1,"a"];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR44_testLength008', 0, function () {
let arraylist= new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add('a')
arraylist.insert(8,2)
let res = arraylist.length;
expect(res).assertEqual(5)
})
it('SR000GGR44_testHas009', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add('a')
arraylist.insert(8,2)
let res = arraylist.has(8);
expect(res).assertEqual(true);
})
it('SR000GGR44_testGetIndexOf010', 0, function () {
let arraylist = new ArrayList();
arraylist.add(1);
arraylist.add("");
arraylist.add(1);
arraylist.add('a')
arraylist.insert(1,2)
let res1 = arraylist.getIndexOf(1)
expect(res1).assertEqual(0);
})
it('SR000GGR44_testRemoveByIndex011', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add("a")
arraylist.removeByIndex(2);
let arr=[];
arraylist.forEach((item,index)=>{
arr.push(item);
})
let a=["","","a"];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR44_testRemove012', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add('a')
arraylist.remove("");
let res=arraylist.has("");
expect(res).assertEqual(false);
})
it('SR000GGR44_testGetLastIndexOf013', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add('a');
arraylist.add(1);
arraylist.add("b");
let res = arraylist.getLastIndexOf(1);
expect(res).assertEqual(4);
})
it('SR000GGR44_testRemoveByRange014', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add("a");
arraylist.add(1);
arraylist.add("b");
arraylist.add("c");
arraylist.add(1);
arraylist.removeByRange(1,3);
let arr=[];
arraylist.forEach((item,index)=>{
arr.push(item);
})
let a=["","a",1,"b","c",1];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR44_testReplaceAllElements015', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
arraylist.replaceAllElements((item, index) => {
return (item = 2 * item);
});
let arr=[];
arraylist.forEach((item,index)=>{
arr.push(item);
})
let a=[8,6,2,4,28];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR44_testForEach016', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
let arr=[];
arraylist.forEach((item,index)=>{
arr.push(item);
})
let a=[4,3,1,2,14];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR44_testSubArrayList017', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
let subArr = arraylist.subArrayList(2,4);
let arr=[];
subArr.forEach((item,index)=>{
arr.push(item);
})
let a=[1,2];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR44_testClear018', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
arraylist.clear();
let res = arraylist.length;
expect(res).assertEqual(0)
})
it('SR000GGR44_testConvertToArray19', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
let arr= arraylist.convertToArray()
let a=[4,3,1,2,14];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR44_testClone020', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
let res = arraylist.clone();
let arr =[]
res.forEach((item,index)=>{
arr.push(item);
})
let a=[4,3,1,2,14];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR44_testGetCapacity021', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
let res = arraylist.getCapacity();
expect(res).assertEqual(10)
})
it('SR000GGR44_testGetCapacity022', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
arraylist.add('a');
arraylist.add('b');
arraylist.add('c');
arraylist.add('d');
arraylist.add('v');
let a=[1,2,3,4];
arraylist.add(a);
let res = arraylist.getCapacity();
expect(res).assertEqual(15)
})
it('SR000GGR44_testIncreaseCapacityTo023', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
arraylist.increaseCapacityTo(8);
let res = arraylist.getCapacity();
expect(res).assertEqual(8)
})
it('SR000GGR44_testTrimToCurrentLength024', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
arraylist.trimToCurrentLength();
let res = arraylist.getCapacity();
expect(res).assertEqual(5)
})
it('SR000GGR44_testIterator025', 0, function () {
let arraylist = new ArrayList();
arraylist.add(8);
arraylist.add("")
arraylist.add("")
arraylist.add(5);
let c=[1,2,3,4];
arraylist.add(c);
arraylist.add(6);
arraylist.add("")
arraylist.add("")
let arr =[]
for(let item of arraylist) {
arr.push(item);
}
let a = [8,"","",5,c,6,"",""]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR44_testSort026', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
arraylist.sort((a,b) => a-b);
let arr=[];
arraylist.forEach((item,index)=>{
arr.push(item);
})
let a=[1,2,3,4,14];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR44_testInsert0027', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add('a')
try{
let res = arraylist.insert(8,-1);
}catch(err){
expect(err).assertEqual("Error: ArrayList: get out-of-bounds")
}
})
it('SR000GGR44_testInsert0028', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add('a')
try{
let res = arraylist.insert(8,10);
}catch(err){
expect(err).assertEqual("Error: ArrayList: set out-of-bounds")
}
})
it('SR000GGR44_testInsert029', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add('a')
try{
let res = arraylist.insert(8,11);
}catch(err){
expect(err).assertEqual("Error: ArrayList: set out-of-bounds")
}
})
it('SR000GGR44_testisEmpty030', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
arraylist.clear();
let res = arraylist.isEmpty();
expect(res).assertEqual(true)
})
it('SR000GGR44_testisEmpty031', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
let res = arraylist.isEmpty();
expect(res).assertEqual(false)
})
it('SR000GGR44_testHas032', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add('a')
arraylist.insert(8,2)
let res = arraylist.has("")
expect(res).assertEqual(false);
})
it('SR000GGR44_testGetIndexOf033', 0, function () {
let arraylist = new ArrayList();
arraylist.add(1);
arraylist.add("");
arraylist.add(1);
arraylist.add('a')
arraylist.insert(1,2)
let res = arraylist.getIndexOf("A")
expect(res).assertEqual(-1);
})
it('SR000GGR44_testRemove034', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add('a');
let res = arraylist.remove("A");
expect(res).assertEqual(false);
})
it('SR000GGR44_testRemoveByIndex035', 0, function () {
let arraylist = new ArrayList();
arraylist.add(0);
arraylist.add(1);
arraylist.add(2);
arraylist.add(1);
arraylist.add(3);
arraylist.add(1);
arraylist.forEach((item,index)=>{
if(item == 1){
arraylist.remove(item);
}
})
let arr=[];
arraylist.forEach((item,index)=>{
arr.push(item);
})
let a = [0,2,3];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR44_testRemoveByIndex036', 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(5);
} catch (err) {
expect(err).assertEqual("Error: removeByIndex is out-of-bounds")
}
})
it('SR000GGR44_testRemoveByRange037', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add("a");
arraylist.add(1);
arraylist.add("b");
arraylist.add("c");
arraylist.add(1);
try{
let res = arraylist.removeByRange(3,1);
}catch(err){
expect(err).assertEqual("Error: fromIndex cannot be less than or equal to toIndex")
}
})
it('SR000GGR44_testRemoveByRange038', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add("a");
arraylist.add(1);
try{
let res = arraylist.removeByRange(6,8);
}catch(err){
expect(err).assertEqual("Error: ArrayList: set out-of-bounds")
}
})
it('SR000GGR44_testRemoveByRange039', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("");
arraylist.add(1);
arraylist.add("a");
arraylist.add(1);
arraylist.add("b");
arraylist.add("c");
arraylist.add(1);
arraylist.removeByRange(0,9);
let res = arraylist.length;
let res1 = arraylist.getLastIndexOf(1);
expect(res).assertEqual(1);
expect(res1).assertEqual(0);
})
it('SR000GGR44_testSubArrayList040', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
try{
let subArr = arraylist.subArrayList(4,2);
}catch(err){
expect(err).assertEqual("Error: fromIndex cannot be less than or equal to toIndex")
}
})
it('SR000GGR44_testSubArrayList041', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
let subArr = arraylist.subArrayList(0,6);
let arr=[];
arraylist.forEach((item,index)=>{
arr.push(item);
})
let a=[4,3,1,2,14];
for(let i=0;i<a.length;i++){
expect(a[i]).assertEqual(arr[i])
}
})
it('SR000GGR44_testSubArrayList042', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
try{
let subArr = arraylist.subArrayList(6,9);
}catch(err){
expect(err).assertEqual("Error: fromIndex or toIndex is out-of-bounds")
}
})
it('SR000GGR44_testIncreaseCapacityTo043', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
arraylist.increaseCapacityTo(-1);
let res = arraylist.getCapacity();
expect(res).assertEqual(10)
})
it('SR000GGR44_testIncreaseCapacityTo044', 0, function () {
let arraylist = new ArrayList();
arraylist.add(4);
arraylist.add(3);
arraylist.add(1);
arraylist.add(2);
arraylist.add(14);
try{
let res = arraylist.increaseCapacityTo();
}catch(err){
expect(err).assertEqual("ArrayList: set out-of-bounds")
}
})
it('SR000GGR44_testAdd045', 0, function () {
let arraylist = new ArrayList();
for (let i = 0; i < 100; i++) {
arraylist.add(i);
}
let res = arraylist.getIndexOf(99);
let res1 = arraylist.length;
expect(res).assertEqual(99);
expect(res1).assertEqual(100);
})
it('SR000GGR44_testAdd046', 0, function () {
let arraylist = new ArrayList();
let a = "*"
arraylist.add(a);
let res = arraylist.has(a)
expect(res).assertEqual(true);
})
it('SR000GGR44_testAdd047', 0, function () {
let arraylist = new ArrayList();
let a = "3.14"
arraylist.add(a);
let res = arraylist.has(a)
expect(res).assertEqual(true);
})
it('SR000GGR44_testAdd048', 0, function () {
let arraylist = new ArrayList();
let a = ""
arraylist.add(a);
let res = arraylist.has(a)
expect(res).assertEqual(true);
})
it('SR000GGR44_testSort049', 0, function () {
let arraylist = new ArrayList();
arraylist.add("");
arraylist.add("张三");
arraylist.add(1);
arraylist.add(2);
arraylist.add("李四");
arraylist.sort((a,b) => a-b);
let arr=[];
arraylist.forEach((item,index)=>{
arr.push(item);
})
let a=["","张三",1,2,"李四"];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR44_testSort050', 0, function () {
let arraylist = new ArrayList();
arraylist.add("c");
arraylist.add("a");
arraylist.add("b");
arraylist.add("e");
arraylist.add("d");
arraylist.sort((a,b) => a-b);
let arr=[];
arraylist.forEach((item,index)=>{
arr.push(item);
})
let a=["c","a","b","e","d"];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
})
/*
* 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 {List} from '@ohos.list'
describe('QueueTest', function () {
it('SR000GGR4A_testConstructor001', 0, function () {
try{
let list = new List();
expect(list != undefined).assertEqual(true);
}catch(err){
expect(err).assertEqual("Error:Cannot create new queue")
}
})
it('SR000GGR4A_testGet002', 0, function () {
let list = new List();
list.add("");
let res = list.get(0);
expect(res).assertEqual("")
})
it('SR000GGR4A_testAdd002', 0, function () {
let list = new List();
list.add(8);
let res = list.get(0)
expect(res).assertEqual(8)
})
it('SR000GGR4A_testAdd003', 0, function () {
let list = new List();
let a=[1,2,3,4]
list.add(a);
let res = list.get(0)
expect(res).assertEqual(a)
})
it('SR000GGR4A_testAdd004', 0, function () {
let list = new List();
let a={name:"lala",age:"13"}
list.add(a);
let res = list.get(0)
expect(res).assertEqual(a)
})
it('SR000GGR4A_testHas005', 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
let res = list.has("a");
expect(res).assertEqual(true);
})
it('SR000GGR4A_testHas006', 0, function () {
let list = new List();
list.add("a");
list.add("b");
list.add("c");
let res = list.has("d");
expect(res).assertEqual(false);
})
it('SR000GGR4A_testEqual007', 0, function () {
let list= new List();
let list1 = new List();
list.add("a");
list.add("b");
list.add("c");
list1.add("a");
list1.add("b");
list1.add("d");
let res = list.equal(list1);
expect(res).assertEqual(false);
})
it('SR000GGR4A_testEqual008', 0, function () {
let list= new List();
let list1 = new List();
list.add("a");
list.add("b");
list.add("c");
list1.add("a");
list1.add("b");
list1.add("c");
let res = list.equal(list1);
expect(res).assertEqual(true);
})
it('SR000GGR4A_testEqual009', 0, function () {
let list= new List();
let list1 = new List();
list.add("a");
list.add("b");
list.add("c");
list1.add("a");
list1.add("b");
let res = list.equal(list1);
expect(res).assertEqual(false);
})
it('SR000GGR4A_testGet010', 0, function () {
let list= new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list.add('b')
let res = list.get(2);
expect(res).assertEqual("c");
})
it('SR000GGR4A_testGetLastIndexOf011', 0, function () {
let list= new List();
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('SR000GGR4A_testGetIndexOf012', 0, function () {
let list= new List();
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('SR000GGR4A_testRemoveByIndex013', 0, function () {
let list= new List();
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('SR000GGR4A_testRemove014', 0, function () {
let list= new List();
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('SR000GGR4A_testConstructor015', 0, function () {
let list= new List();
list.add(1);
list.add(2);
list.add(4);
list.add(5);
list.replaceAllElements((item, index) => {
return (item = 2 * item);
});
let arr=[];
list.forEach((item,index)=>{
arr.push(item);
})
let a=[2,4,8,10];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR4A_testGetFirst016', 0, function () {
let list= new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.getFirst();
expect(res).assertEqual("a")
})
it('SR000GGR4A_testGetLast017', 0, function () {
let list= new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.getLast();
expect(res).assertEqual("b")
})
it('SR000GGR4A_testInsert018', 0, function () {
let list= new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.insert("d",3);
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('SR000GGR4A_testSet019', 0, function () {
let list= new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
let res = list.set(2,"d");
let res1 = list.getNode(2).element;
expect(res1).assertEqual("d")
})
it('SR000GGR4A_testSort020', 0, function () {
let list= new List();
list.add(4);
list.add(3);
list.add(1);
list.add(2);
list.add(14);
list.sort((a,b) => a-b);
let arr=[];
list.forEach((item,index)=>{
arr.push(item);
})
let a=[1,2,3,4,14];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR4A_testGetSubList021', 0, function () {
let list= new List();
list.add(4);
list.add(3);
list.add(1);
list.add(2);
list.add(14);
let res = list.getSubList(2,4);
let arr=[];
res.forEach((item,index)=>{
arr.push(item);
})
let a=[1,2];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR4A_testConvertToArray022', 0, function () {
let list= new List();
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('SR000GGR4A_testLength023', 0, function () {
let list= new List();
list.add(4);
list.add(3);
list.add(1);
list.add(2);
list.add(14);
let res = list.length;
expect(res).assertEqual(5);
})
it('SR000GGR4A_testConstructor024', 0, function () {
let list = new List();
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 =[]
for(let item of list) {
arr.push(item);
}
let a = [8,"","",5,c,6,"",""]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR4A_testForEach025', 0, function () {
let list = new List();
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('SR000GGR4A_testIsEmpty026', 0, function () {
let list = new List();
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 res = list.isEmpty();
expect(res).assertEqual(false)
})
it('SR000GGR4A_testClear027', 0, function () {
let list= new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.clear();
let res = list.length;
expect(res).assertEqual(0)
})
it('SR000GGR4A_testGet028', 0, function () {
let list= new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
list.add('b')
try {
let res = list.get(6);
} catch (err) {
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
})
it('SR000GGR4A_testGetLastIndexOf029', 0, function () {
let list= new List();
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('SR000GGR4A_testRemoveByIndex030', 0, function () {
let list= new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
try {
let res = list.removeByIndex(5);
} catch (err) {
expect(err).assertEqual("Error: removeByIndex is out-of-bounds")
}
})
it('SR000GGR4A_testRemove031', 0, function () {
let list= new List();
list.add();
let res = list.remove();
expect(res).assertEqual(true)
})
it('SR000GGR4A_testInsert032', 0, function () {
let list= new List();
list.add("a");
list.add("b");
list.add("c");
list.add("a");
list.add("b");
let res = list.insert("d",8);
expect(res).assertEqual(undefined);
})
it('SR000GGR4A_testSort033', 0, function () {
let list= new List();
list.add(";");
list.add("");
list.add("a");
list.add("1");
list.add("2");
list.add("14");
list.sort((a,b) => a-b);
let arr=[];
list.forEach((item,index)=>{
arr.push(item);
})
let a=[";", "","a","1","2","14"];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR4A_testGetSubList034', 0, function () {
let list= new List();
list.add("4");
list.add("3");
list.add("1");
list.add("2");
list.add("14");
let res = list.getSubList(2,8);
let arr=[];
res.forEach((item,index)=>{
arr.push(item);
})
let a=["1","2"];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR4A_testGetSubList035', 0, function () {
let list= new List();
list.add("4");
list.add("3");
list.add("1");
list.add("2");
list.add("14");
try {
let res = list.getSubList(6,8);
} catch (err) {
expect(err).assertEqual("Error: fromIndex or toIndex is out-of-bounds")
}
})
it('SR000GGR4A_testGetSubList036', 0, function () {
let list = new List();
list.add("4");
list.add("3");
list.add("1");
list.add("2");
list.add("14");
try {
let res = list.getSubList(6, 2);
} catch (err) {
expect(err).assertEqual("Error: toIndex cannot be less than or equal to fromIndex")
}
})
it('SR000GGR4A_testAdd037', 0, function () {
let list = new List();
list.add('.');
list.add('*');
list.add('|');
let res = list.get(0);
expect(res).assertEqual('.');
})
it('SR000GGR4A_testAdd038', 0, function () {
let list = new List();
list.add('.');
list.add('*');
list.add('|');
let arr=[];
list.forEach((item,index)=>{
arr.push(item);
})
let a = ['.','*','|'];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR4A_testAdd039', 0, function () {
let list = new List();
list.add(' ');
let res = list.get(0);
expect(res).assertEqual(' ');
})
it('SR000GGR4A_testAdd040', 0, function () {
let list = new List();
list.add('a');
list.add('a');
let res = list.get(0);
let res1 = list.get(1);
expect(res).assertEqual('a');
expect(res1).assertEqual('a');
})
it('SR000GGR4A_testListGet041', 0, function () {
let list = new List();
list.add('a');
list.add('b');
let res = list[0];
expect(res).assertEqual('a');
})
it('SR000GGR4A_testListSet042', 0, function () {
let list = new List();
list.add('a');
list.add('b');
list[0] = 'c';
let res = list[0];
expect(res).assertEqual('c');
list.forEach((item,index)=>{
})
})
it('SR000GGR4A_testAdd043', 0, function () {
let list = new List();
for (let i = 0; i < 100; i++) {
list.add(i);
}
let res = list.get(99);
let res1 = list.length;
expect(res).assertEqual(99);
expect(res1).assertEqual(100);
})
it('SR000GGR4A_testAdd044', 0, function () {
let list = new List();
list.add(null);
let res = list.get(0);
expect(res).assertEqual(null);
})
it('SR000GGR4A_testAdd045', 0, function () {
let list = new List();
list.add(0.1111);
let res = list.get(0);
expect(res).assertEqual(0.1111);
})
it('SR000GGR4A_testAdd046', 0, function () {
let list = new List();
list.add(-1);
let res = list.get(0);
expect(res).assertEqual(-1);
})
it('SR000GGR4A_testAdd047', 0, function () {
let list = new List();
const obj = {};
list.add(obj);
let res = list.get(0);
expect(res).assertEqual(obj);
})
it('SR000GGR4A_testSort048', 0, function () {
let list= new List();
list.sort((a,b) => a-b);
let res1 = list.length;
expect(res1).assertEqual(0);
})
it('SR000GGR4A_testRemoveByIndex049', 0, function () {
let list= new List();
try {
let res = list.removeByIndex(1);
} catch (err) {
expect(err).assertEqual("Error: removeByIndex is out-of-bounds")
}
})
it('SR000GGR4A_testEqual050', 0, function () {
let list = new List();
let list1 = new List();
try {
let res = list.equal(list1);
} catch (err) {
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
})
it('SR000GGR4A_testGetIndexOf051', 0, function () {
let list= new List();
let res = list.getIndexOf(1);
expect(res).assertEqual(-1);
})
it('SR000GGR4A_testForEach052', 0, function () {
let list= new List();
let num = 0
try {
list.forEach((item, index)=>{
num++;
})
} catch (err) {
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
expect(num).assertEqual(0);
})
it('SR000GGR4A_testIsEmpty053', 0, function () {
let list= new List();
try {
let res = list.IsEmpty();
} catch (err) {
expect(err).assertEqual("TypeError: is not callable")
}
})
it('SR000GGR4A_testHas054', 0, function () {
let list= new List();
try {
let res = list.has(1);
} catch (err) {
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
})
it('SR000GGR4A_testGet055', 0, function () {
let list= new List();
try {
let res = list.get(1);
} catch (err) {
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
})
it('SR000GGR4A_testClear056', 0, function () {
let list= new List();
list.clear();
let res1 = list.length;
expect(res1).assertEqual(0);
})
it('SR000GGR4A_testGetLast057', 0, function () {
let list= new List();
try {
let res = list.getLast();
} catch (err) {
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
})
it('SR000GGR4A_testReplaceAllElements058', 0, function () {
let list= new List();
let num = 0
try {
list.replaceAllElements((item, index)=>{
num++;
})
} catch (err) {
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
expect(num).assertEqual(0);
})
it('SR000GGR4A_testConvertToArray059', 0, function () {
let list= new List();
const res = list.convertToArray()
expect(res.length).assertEqual(0);
})
it('SR000GGR4A_testConvertToArray060', 0, function () {
let list= new List();
const res = list.convertToArray()
expect(res.length).assertEqual(0);
})
it('SR000GGR4A_testlterator061', 0, function () {
let list= new List();
for (let index = 0; index < 10; index++) {
list.add(index);
}
let num = 0;
for (const iterator of list) {
expect(iterator).assertEqual(num);
num++;
}
})
it('SR000GGR4A_testGetFirst062', 0, function () {
let list= new List();
try {
let res = list.getFirst();
} catch (err) {
expect(err).assertEqual("TypeError: Obj is not a valid object")
}
})
})
\ 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 {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 {LightWeightMap} from '@ohos.lightweightmap'
describe('SR00GGR3L_LightWeightMapTest', function () {
it('SR00GGR3L_testConstructor001', 0, function () {
try{
let lightweightmap = new LightWeightMap();
expect(lightweightmap != undefined).assertEqual(true);
}catch(err){
expect(err).assertEqual("Error:Cannot create new TreeMap")
}
})
it('SR00GGR3L_testSet002', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set(1,"A");
let res = lightweightmap.hasValue("A");
expect(res).assertEqual(true);
let res1 = lightweightmap.hasKey(1);
expect(res1).assertEqual(true);
})
it('SR00GGR3L_testSet003', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set("a","A");
let res = lightweightmap.hasValue("A");
expect(res).assertEqual(true);
let res1 = lightweightmap.hasKey("a");
expect(res1).assertEqual(true);
})
it('SR00GGR3L_testSet004', 0, function () {
let lightweightmap = new LightWeightMap();
let a =[1,2,3,4]
lightweightmap.set(1,a);
let res = lightweightmap.hasValue(a);
expect(res).assertEqual(true);
let res1 = lightweightmap.hasKey(1);
expect(res1).assertEqual(true);
})
it('SR00GGR3L_testSet005', 0, function () {
let lightweightmap = new LightWeightMap();
let c = { name: 'lili', age: '13' }
lightweightmap.set(1,c);
let res = lightweightmap.hasValue(c);
expect(res).assertEqual(true);
let res1 = lightweightmap.hasKey(1);
expect(res1).assertEqual(true);
})
it('SR00GGR3L_testGet006', 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");
let res = lightweightmap.get(4);
expect(res).assertEqual("D");
})
it('SR00GGR3L_testLength007', 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");
let res = lightweightmap.length;
expect(res).assertEqual(5);
})
it('SR00GGR3L_testHasAll008', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set("a","A");
lightweightmap.set("b","B");
lightweightmap.set("c","C");
lightweightmap.set("d","D");
lightweightmap.set("e","E");
let lightweightmap1 = new LightWeightMap();
lightweightmap1.set("a","A");
lightweightmap1.set("d","D");
let res = lightweightmap.hasAll(lightweightmap1);
expect(res).assertEqual(true);
})
it('SR00GGR3L_testHasKey009', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set("a", "A");
lightweightmap.set("b", "B");
lightweightmap.set("c", "C");
lightweightmap.set("d", "D");
lightweightmap.set("e", "E");
let res = lightweightmap.hasKey("a");
expect(res).assertEqual(true);
let res1 = lightweightmap.hasKey(1);
expect(res1).assertEqual(false);
})
it('SR00GGR3L_testHasValue010', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set("a", "A");
lightweightmap.set("b", "B");
lightweightmap.set("c", "C");
lightweightmap.set("d", "D");
lightweightmap.set("e", "E");
let res = lightweightmap.hasValue("A");
expect(res).assertEqual(true);
let res1 = lightweightmap.hasValue(1);
expect(res1).assertEqual(false);
})
it('SR00GGR3L_testIncreaseCapacityTo011', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set("a", "A");
lightweightmap.set("b", "B");
lightweightmap.set("c", "C");
lightweightmap.set("d", "D");
lightweightmap.set("e", "E");
let res = lightweightmap.increaseCapacityTo(3);
expect(res).assertEqual(undefined);
})
it('SR00GGR3L_testEntries012', 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");
let res = lightweightmap.entries();
expect(JSON.stringify(res.next().value)).assertEqual("[1,\"A\"]");
expect(JSON.stringify(res.next().value)).assertEqual("[2,\"B\"]");
expect(JSON.stringify(res.next().value)).assertEqual("[3,\"C\"]");
expect(JSON.stringify(res.next().value)).assertEqual("[4,\"D\"]");
expect(JSON.stringify(res.next().value)).assertEqual("[5,\"E\"]");
})
it('SR00GGR3L_testGetIndexOfKey013', 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");
let res = lightweightmap.getIndexOfKey(2);
expect(res).assertEqual(1);
})
it('SR00GGR3L_testGetIndexOfValue014', 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");
lightweightmap.setValueAt(4, "F");
let res = lightweightmap.getIndexOfValue("F");
expect(res).assertEqual(4);
})
it('SR00GGR3L_testIsEmpty015', 0, function () {
let lightweightmap = new LightWeightMap();
let res1 = lightweightmap.isEmpty();
expect(res1).assertEqual(true);
lightweightmap.set(1, "A");
lightweightmap.set(2, "B");
lightweightmap.set(3, "C");
lightweightmap.set(4, "D");
lightweightmap.set(5, "E");
let res2 = lightweightmap.isEmpty();
expect(res2).assertEqual(false);
})
it('SR00GGR3L_testGetKeyAt016', 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");
let res = lightweightmap.getKeyAt(1);
expect(res).assertEqual(2);
})
it('SR00GGR3L_testKeys017', 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");
let res = lightweightmap.keys();
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('SR00GGR3L_testSetAll018', 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");
let lightweightmap1 = new LightWeightMap();
lightweightmap1.set(6, "A");
lightweightmap1.set(7, "B");
lightweightmap.setAll(lightweightmap1);
for(let i=1; i < 8; i++) {
expect(lightweightmap1.hasKey(i)).assertEqual(true);
}
})
it('SR00GGR3L_testRemove019', 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");
let res = lightweightmap.remove(3);
expect(res).assertEqual("C");
let res1 = lightweightmap.hasValue("C");
expect(res1).assertEqual(false);
})
it('SR00GGR3L_testRemoveAt020', 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");
let res = lightweightmap.removeAt(1);
expect(res).assertEqual(true);
let res1 = lightweightmap.hasValue("A");
expect(res1).assertEqual(true);
let res2 = lightweightmap.hasValue("B");
expect(res2).assertEqual(false);
let res3 = lightweightmap.removeAt(10);
expect(res3).assertEqual(false);
})
it('SR00GGR3L_testClear021', 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");
lightweightmap.clear();
let res = lightweightmap.length;
expect(res).assertEqual(0);
let isEmpty = lightweightmap.isEmpty();
expect(isEmpty).assertEqual(true);
})
it('SR00GGR3L_testSetValueAt022', 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");
lightweightmap.setValueAt(0,"a");
let res = lightweightmap.get(1);
expect(res).assertEqual("a");
})
it('SR00GGR3L_testForEach023', 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");
let arr = []
lightweightmap.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]);
}
})
it('SR00GGR3L_testToString024', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set(1, "A");
lightweightmap.set(2, "B");
lightweightmap.set(3, "C");
let res = lightweightmap.toString();
expect(res).assertEqual("1:A,2:B,3:C");
})
it('SR00GGR3L_testValues025', 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");
let res = lightweightmap.values();
// for(let i = 0; i < lightweightmap.length; i++){
// }
expect(res.next().value).assertEqual("A");
expect(res.next().value).assertEqual("B");
expect(res.next().value).assertEqual("C");
expect(res.next().value).assertEqual("D");
expect(res.next().value).assertEqual("E");
})
it('SR00GGR3L_testGetValueAt026', 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");
let res = lightweightmap.getValueAt(1);
expect(res).assertEqual("B");
})
it('SR00GGR3L_testIterator027', 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");
let arr=[]
for(let item of lightweightmap){
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('SR00GGR3L_testSet028', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set(1, null);
let res = lightweightmap.hasValue(null);
expect(res).assertEqual(true);
let res1 = lightweightmap.hasKey(1);
expect(res1).assertEqual(true);
})
it('SR00GGR3L_testSet029', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set(null, null);
let res = lightweightmap.hasValue(null);
expect(res).assertEqual(true);
let res1 = lightweightmap.hasKey(null);
expect(res1).assertEqual(true);
})
it('SR00GGR3L_testSet030', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set(true, false);
let res = lightweightmap.hasValue(false);
expect(res).assertEqual(true);
let res1 = lightweightmap.hasKey(true);
expect(res1).assertEqual(true);
})
it('SR00GGR3L_testSet031', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set(1.23, 321);
let res = lightweightmap.hasValue(321);
expect(res).assertEqual(true);
let res1 = lightweightmap.hasKey(1.23);
expect(res1).assertEqual(true);
})
it('SR00GGR3L_testHasAll032', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set("a","A");
lightweightmap.set("b","B");
lightweightmap.set("c","C");
lightweightmap.set("d","D");
lightweightmap.set("e","E");
let lightweightmap1 = new LightWeightMap();
lightweightmap1.set("a1","A1");
lightweightmap1.set("d1","D1");
let res = lightweightmap.hasAll(lightweightmap1);
expect(res).assertEqual(false);
})
it('SR00GGR3L_testHasAll033', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set("a","A");
lightweightmap.set("b","B");
lightweightmap.set("c","C");
lightweightmap.set("d","D");
lightweightmap.set("e","E");
let lightweightmap1 = new LightWeightMap();
lightweightmap1.set("a","A1");
lightweightmap1.set("d","D1");
let res = lightweightmap.hasAll(lightweightmap1);
expect(res).assertEqual(false);
})
it('SR00GGR3L_testRemove034', 0, function () {
let lightweightmap = new LightWeightMap();
try{
let res = lightweightmap.remove(3);
}catch(err){
expect(err).assertEqual("Error: don't find the key in lightweight")
}
})
it('SR00GGR3L_testRemoveAt035', 0, function () {
let lightweightmap = new LightWeightMap();
let res = lightweightmap.removeAt(1);
expect(res).assertEqual(false);
})
it('SR00GGR3L_testIncreaseCapacityTo036', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set("a", "A");
lightweightmap.set("b", "B");
lightweightmap.set("c", "C");
lightweightmap.set("d", "D");
lightweightmap.set("e", "E");
let res = lightweightmap.increaseCapacityTo(10);
expect(res).assertEqual(undefined);
})
it('SR00GGR3L_testIncreaseCapacityTo037', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set("a", "A");
lightweightmap.set("b", "B");
lightweightmap.set("c", "C");
lightweightmap.set("d", "D");
lightweightmap.set("e", "E");
try{
let res = lightweightmap.increaseCapacityTo("qwe");
}catch(err){
expect(err).assertEqual("lightweightmap: index must be int")
}
})
it('SR00GGR3L_testRemoveAt038', 0, function () {
let lightweightmap = new LightWeightMap();
try{
let res = lightweightmap.removeAt("123");
}catch(err){
expect(err).assertEqual("lightweightmap: index must be int")
}
})
it('SR00GGR3L_testGetValueAt040', 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.getValueAt("123");
}catch(err){
expect(err).assertEqual("lightweightmap: index must be int")
}
})
it('SR00GGR3L_testGetKeyAt041', 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("123");
}catch(err){
expect(err).assertEqual("lightweightmap: index must be int")
}
})
it('SR00GGR3L_testHasAll042', 0, function () {
let lightweightmap = new LightWeightMap();
let lightweightmap1 = new LightWeightMap();
let res = lightweightmap.hasAll(lightweightmap1);
expect(res).assertEqual(true);
})
it('SR00GGR3L_testSet043', 0, function () {
let lightweightmap = new LightWeightMap();
for (let i = 0; i < 100; i++) {
lightweightmap.set(i,"A");
}
let res = lightweightmap.get(99);
expect(res).assertEqual("A");
let res1 = lightweightmap.length;
expect(res1).assertEqual(100);
})
it('SR00GGR3L_testSet044', 0, function () {
let lightweightmap = new LightWeightMap();
for (let i = 0; i < 100; i++) {
lightweightmap.set(1,i);
}
let res = lightweightmap.get(1);
expect(res).assertEqual(99);
let res1 = lightweightmap.length;
expect(res1).assertEqual(1);
})
it('SR00GGR3L_testSet045', 0, function () {
let lightweightmap = new LightWeightMap();
for (let i = 0; i < 10000; i++) {
lightweightmap.set(i, i);
}
let res1 = lightweightmap.length;
expect(res1).assertEqual(10000);
for (let index = 0; index < 10000; index++) {
let resKey = lightweightmap.hasKey(index);
expect(resKey).assertEqual(true);
let resValue = lightweightmap.hasValue(index);
expect(resValue).assertEqual(true);
}
})
it('SR00GGR3L_testSet046', 0, function () {
let lightweightmap = new LightWeightMap();
for (let i = 0; i < 5000; i++) {
lightweightmap.set(i, i);
}
for (let i = -1; i > -5001; i--) {
lightweightmap.set(i, i);
}
let res1 = lightweightmap.length;
expect(res1).assertEqual(10000);
for (let index = 0; index < 5000; index++) {
let resKey = lightweightmap.hasKey(index);
expect(resKey).assertEqual(true);
let resValue = lightweightmap.hasValue(index);
expect(resValue).assertEqual(true);
}
for (let i = -1; i > -5001; i--) {
let resKey = lightweightmap.hasKey(i);
expect(resKey).assertEqual(true);
let resValue = lightweightmap.hasValue(i);
expect(resValue).assertEqual(true);
}
})
it('SR00GGR3L_testSet047', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set(true, 0.001);
let res = lightweightmap.hasValue(0.001);
expect(res).assertEqual(true);
let res1 = lightweightmap.hasKey(true);
expect(res1).assertEqual(true);
})
it('SR00GGR3L_testSet048', 0, function () {
let lightweightmap = new LightWeightMap();
let a =[1,2,3,4]
lightweightmap.set(a, 1);
let res = lightweightmap.hasValue(1);
expect(res).assertEqual(true);
let res1 = lightweightmap.hasKey(a);
expect(res1).assertEqual(true);
})
it('SR00GGR3L_testSet049', 0, function () {
let lightweightmap = new LightWeightMap();
let a = { abc: 1 }
lightweightmap.set(a, '');
let res = lightweightmap.hasValue('');
expect(res).assertEqual(true);
let res1 = lightweightmap.hasKey(a);
expect(res1).assertEqual(true);
})
it('SR00GGR3L_testGet050', 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");
let res = lightweightmap.get(10);
expect(res).assertEqual(null);
})
it('SR00GGR3L_testHasAll051', 0, function () {
let lightweightmap = new LightWeightMap();
lightweightmap.set("a","A");
lightweightmap.set("b","B");
lightweightmap.set("c","C");
lightweightmap.set("d","D");
lightweightmap.set("e","E");
let lightweightmap1 = new LightWeightMap();
lightweightmap1.set("a","A");
lightweightmap1.set("d","D1");
let res = lightweightmap.hasAll(lightweightmap1);
expect(res).assertEqual(false);
})
})
\ 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
......@@ -15,3 +15,17 @@
require('./ExampleJsunit.test.js')
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
/*
* 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 {Stack} from '@ohos.stack'
describe('StackTest', function () {
it('SR000GGR49_test_Constructor001', 0, function () {
try {
let stack = new Stack();
expect(stack != undefined).assertEqual(true)
} catch (err) {
expect(err).assertEqual("Error: Cannot create new stack")
}
})
it('SR000GGR49_test_push002', 0, function () {
let stack = new Stack();
stack.push("");
let res = stack.peek()
expect(res).assertEqual("")
})
it('SR000GGR49_test_push003', 0, function () {
let stack = new Stack();
stack.push(8);
let res = stack.peek()
expect(res).assertEqual(8)
})
it('SR000GGR49_test_push004', 0, function () {
let stack = new Stack();
let a = { name: 'lala', age: '13岁' }
stack.push(a);
let res = stack.peek()
expect(res).assertEqual(a)
})
it('SR000GGR49_test_push005', 0, function () {
let stack = new Stack();
let a = [1, 2, 3, 4]
stack.push(a);
let res = stack.peek()
expect(res).assertEqual(a)
})
it('SR000GGR49_test_peek006', 0, function () {
let stack = new Stack();
let a = [1, 2, 3, 4]
stack.push(a);
stack.push("A");
stack.push("B");
stack.push(1);
let res = stack.peek()
expect(res).assertEqual(1)
})
it('SR000GGR49_test_locate007', 0, function () {
let stack = new Stack();
let a = [1, 2, 3, 4];
stack.push(8);
stack.push(a);
stack.push("A");
stack.push("B");
stack.push(1);
let res = stack.locate("A");
let res1 = stack.locate("C");
expect(res).assertEqual(2);
expect(res1).assertEqual(-1);
})
it('SR000GGR49_test_pop008', 0, function () {
let stack = new Stack();
stack.push("B");
stack.push(1);
let res = stack.pop();
let res1 = stack.peek();
expect(res).assertEqual(1);
expect(res1).assertEqual("B");
})
it('SR000GGR49_test_forEach009', 0, function () {
let stack = new Stack();
stack.push(8);
stack.push("")
stack.push(5);
let c = { name: 'lili', age: '13' };
stack.push(c);
stack.push(6);
stack.push("");
let arr = [];
stack.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('SR000GGR49_test_iterator010', 0, function () {
let stack = new Stack();
stack.push(8);
stack.push("")
stack.push("")
stack.push(5);
let c = [1, 2, 3, 4];
stack.push(c);
stack.push(6);
stack.push("")
stack.push("")
let arr = []
for (let item of stack) {
arr.push(item);
}
let a = [8, "", "", 5, c,6, "", ""]
for (let i = 0;i < a.length; i++) {
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR49_test_length011_1', 0, function () {
let stack = new Stack();
stack.push(8);
stack.push("")
stack.push("")
stack.push(5);
let res = stack.length;
expect(4).assertEqual(res)
})
it('SR000GGR49_test_length011_2', 0, function () {
let stack = new Stack();
let res = stack.length;
expect(0).assertEqual(res)
})
it('SR000GGR49_test_isEmpty012_1', 0, function () {
let stack = new Stack();
stack.push(8);
stack.push("")
stack.push("")
stack.push(5);
let res = stack.isEmpty();
expect(res).assertEqual(false)
})
it('SR000GGR49_test_isEmpty012_2', 0, function () {
let stack = new Stack();
let res = stack.isEmpty();
expect(res).assertEqual(true)
})
it('SR000GGR49_test_push013', 0, function () {
let stack = new Stack();
stack.push("你好世界");
let res = stack.peek()
expect(res).assertEqual("你好世界")
})
it('SR000GGR49_test_push014', 0, function () {
let stack = new Stack();
stack.push(1234);
let res = stack.peek()
expect(res).assertEqual(1234)
})
it('SR000GGR49_test_push015', 0, function () {
let stack = new Stack();
stack.push(1.234);
let res = stack.peek()
expect(res).assertEqual(1.234)
})
it('SR000GGR49_test_push016', 0, function () {
let stack = new Stack();
stack.push(-1234);
let res = stack.peek()
expect(res).assertEqual(-1234)
})
it('SR000GGR49_test_push017', 0, function () {
let stack = new Stack();
stack.push(0);
let res = stack.peek()
expect(res).assertEqual(0)
})
it('SR000GGR49_test_push018', 0, function () {
let stack = new Stack();
stack.push(10);
stack.push(3.14);
stack.push(-2);
stack.push("AB");
stack.push("*");
let res = stack.peek()
expect(res).assertEqual("*")
})
it('SR000GGR49_test_push019', 0, function () {
let stack = new Stack();
let arr = {};
stack.push(arr);
let res = stack.peek()
expect(res).assertEqual(arr)
})
it('SR000GGR49_test_push020', 0, function () {
let stack = new Stack();
let arr = [];
stack.push(arr);
let res = stack.peek()
expect(res).assertEqual(arr)
})
it('SR000GGR49_test_push021', 0, function () {
let stack = new Stack();
stack.push("hello world");
let res = stack.peek()
expect(res).assertEqual("hello world")
})
it('SR000GGR49_test_push022', 0, function () {
let stack = new Stack();
stack.push("~!@#$^&*()_+-*/=.?<>:;\|{}[]");
let res = stack.peek();
expect(res).assertEqual("~!@#$^&*()_+-*/=.?<>:;\|{}[]");
})
it('SR000GGR49_test_push023', 0, function () {
let stack = new Stack();
stack.push("");
let res = stack.peek();
expect(res).assertEqual("");
})
it('SR000GGR49_test_push024', 0, function () {
let stack = new Stack();
stack.push(true);
let res = stack.peek();
expect(res).assertEqual(true);
})
it('SR000GGR49_test_push025', 0, function () {
let stack = new Stack();
stack.push(false);
let res = stack.peek();
expect(res).assertEqual(false);
})
it('SR000GGR49_test_push026', 0, function () {
let stack = new Stack();
stack.push(null);
let res = stack.peek();
expect(res).assertEqual(null);
})
it('SR000GGR49_test_push027', 0, function () {
let stack = new Stack();
stack.push(undefined);
let res = stack.peek();
expect(res).assertEqual(undefined);
})
it('SR000GGR49_test_peek028', 0, function () {
let stack = new Stack();
try {
let res = stack.peek();
} catch (err) {
expect(err).assertEqual("Error: Stack: get out-of-bounds")
}
})
it('SR000GGR49_test_pop029', 0, function () {
let stack = new Stack();
try {
let res = stack.pop();
} catch (err) {
expect(err).assertEqual("Error: Stack: get out-of-bounds")
}
})
it('SR000GGR49_test_forEach030', 0, function () {
let stack = new Stack();
let arr = [];
try {
stack.forEach((item, index) => {
arr.push(item);
})
} catch (err) {
expect(err).assertEqual("Error:Cannot create new stack")
}
expect(arr.length).assertEqual(0);
})
it('SR000GGR49_test_iterator031', 0, function () {
let stack = new Stack();
let arr = [];
try {
for (let item of stack) {
arr.push(item);
}
} catch (err) {
expect(err).assertEqual("Error:Cannot create new stack")
}
expect(arr.length).assertEqual(0);
})
it('SR000GGR49_test_push032', 0, function () {
let stack = new Stack();
for (let i = 0; i < 1000; i++) {
stack.push(i);
}
let res = stack.length;
expect(res).assertEqual(1000);
let res1 = stack.peek();
expect(res1).assertEqual(999);
})
})
\ 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 {TreeMap} from '@ohos.treemap'
describe('TreeMapTest', function () {
it('SR000GGR3H_testConstructor001', 0, function () {
try{
let treemap = new TreeMap();
expect(treemap != undefined).assertEqual(true)
}catch(err){
expect(err).assertEqual("Error: Cannot create new TreeMap")
}
})
it('SR000GGR3H_testSet002_1', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"");
let res = treemap.get(0);
expect(res).assertEqual("")
})
it('SR000GGR3H_testSet002_2', 0, function () {
let treemap = new TreeMap();
treemap.set(0,8);
let res = treemap.get(0)
expect(res).assertEqual(8)
})
it('SR000GGR3H_testSet002_3', 0, function () {
let treemap = new TreeMap();
let a=[1,2,3,4]
treemap.set(0,a);
let res = treemap.get(0)
expect(res).assertEqual(a)
})
it('SR000GGR3H_testSet002_4', 0, function () {
let treemap = new TreeMap();
let a={name:"lala",age:"13"}
treemap.set(0,a);
let res = treemap.get(0)
expect(res).assertEqual(a)
})
it('SR000GGR3H_testSet002_5', 0, function () {
let treemap = new TreeMap();
treemap.set(2,"*");
let res = treemap.get(2)
expect(res).assertEqual("*")
})
it('SR000GGR3H_testSet002_6', 0, function () {
let treemap = new TreeMap();
treemap.set(-2,3.14);
let res = treemap.get(-2)
expect(res).assertEqual(3.14)
})
it('SR000GGR3H_testSet002_7', 0, function () {
let treemap = new TreeMap();
treemap.set(100,true);
let res = treemap.get(100)
expect(res).assertEqual(true)
})
it('SR000GGR3H_testSet002_8', 0, function () {
let treemap = new TreeMap();
treemap.set(100,"");
let res = treemap.get(100)
expect(res).assertEqual("")
})
it('SR000GGR3H_testSet002_9', 0, function () {
let treemap = new TreeMap();
treemap.set("a","");
let res = treemap.get("a")
expect(res).assertEqual("")
})
it('SR000GGR3H_testSet002_10', 0, function () {
let treemap = new TreeMap();
for(let i = 0; i < 10000; i++){
treemap.set(0,8);
}
let res = treemap.get(0)
expect(res).assertEqual(8)
expect(treemap.length).assertEqual(1)
})
it('SR000GGR3H_testHasKey003', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
let res = treemap.hasKey(1);
expect(res).assertEqual(true);
let res1 = treemap.hasKey(6);
expect(res1).assertEqual(false);
})
it('SR000GGR3H_testHasValue004', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
let res = treemap.hasValue("a");
expect(res).assertEqual(true);
let res1 = treemap.hasValue("d");
expect(res1).assertEqual(false);
})
it('SR000GGR3H_testGet005_1', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
let res = treemap.get(1);
expect(res).assertEqual("b");
})
it('SR000GGR3H_testGet005_2', 0, function () {
let treemap = new TreeMap();
let res = treemap.get(1);
expect(res).assertEqual(null);
})
it('SR000GGR3H_testGet005_3', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.clear();
expect(treemap.length).assertEqual(0)
let res = treemap.get(0);
expect(res).assertEqual(null);
})
it('SR000GGR3H_testGetFirstKey006_1', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
let res = treemap.getFirstKey();
expect(res).assertEqual(0);
})
it('SR000GGR3H_testGetFirstKey006_2', 0, function () {
let treemap = new TreeMap();
try{
let res = treemap.getFirstKey();
}catch(err){
expect(err).assertEqual("Error: don't find this key,this tree is null");
}
})
it('SR000GGR3H_testGetLastKey007_1', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
let res = treemap.getLastKey();
expect(res).assertEqual(2);
})
it('SR000GGR3H_testGetLastKey007_2', 0, function () {
let treemap = new TreeMap();
try{
let res = treemap.getLastKey();
}catch(err){
expect(err).assertEqual("Error: don't find this key,this tree is null");
}
})
it('SR000GGR3H_testSetAll008', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
let treemap1 = new TreeMap();
treemap1.set(0,"a");
treemap1.set(1,"b");
treemap.setAll(treemap1);
let res=treemap1.get(0);
expect(res).assertEqual("a");
let res1=treemap1.get(1);
expect(res1).assertEqual("b");
let res2=treemap1.get(2);
expect(res2).assertEqual("c");
})
it('SR000GGR3H_testRemove009_1', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
let res = treemap.remove(1);
expect(res).assertEqual("b");
})
it('SR000GGR3H_testRemove009_2', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
let res = treemap.remove(1);
expect(res).assertEqual(null);
})
it('SR000GGR3H_testClear010_1', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
treemap.clear();
let res = treemap.length;
expect(res).assertEqual(0)
})
it('SR000GGR3H_testClear010_2', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
treemap.clear();
let res = treemap.length;
expect(res).assertEqual(0)
treemap.set(3,"d");
let va = treemap.get(3);
expect(va).assertEqual("d")
})
it('SR000GGR3H_testGetLowerKey011_1', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
treemap.set(3,"d");
treemap.set(4,"g");
let res = treemap.getLowerKey(2);
expect(res).assertEqual(1)
})
it('SR000GGR3H_testGetLowerKey011_2', 0, function () {
let treemap = new TreeMap();
try{
let res = treemap.getLowerKey(2);
}catch(err){
expect(err).assertEqual("Error: don't find this key,this node is undefine")
}
})
it('SR000GGR3H_testGetHigherKey012_1', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
treemap.set(3,"d");
treemap.set(4,"g");
let res = treemap.getHigherKey(2);
expect(res).assertEqual(3)
})
it('SR000GGR3H_testGetHigherKey012_2', 0, function () {
let treemap = new TreeMap();
try{
let res = treemap.getHigherKey(2);
}catch(err){
expect(err).assertEqual("Error: don't find this key,this node is undefine")
}
})
it('SR000GGR3H_testKeys013', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
treemap.set(3,"d");
treemap.set(4,"g");
let res = treemap.keys();
expect(res.next().value).assertEqual(0);
expect(res.next().value).assertEqual(1);
expect(res.next().value).assertEqual(2);
expect(res.next().value).assertEqual(3);
expect(res.next().value).assertEqual(4);
})
it('SR000GGR3H_testValues014', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
treemap.set(3,"d");
treemap.set(4,"g");
let res = treemap.values();
expect(res.next().value).assertEqual("a");
expect(res.next().value).assertEqual("b");
expect(res.next().value).assertEqual("c");
expect(res.next().value).assertEqual("d");
expect(res.next().value).assertEqual("g");
})
it('SR000GGR3H_testReplace015_1', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
treemap.set(3,"d");
treemap.set(4,"g");
let res = treemap.replace(2,"B");
let res1 = treemap.get(2);
expect(res1).assertEqual("B");
})
it('SR000GGR3H_testReplace015_2', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
let res = treemap.replace(2,"B");
expect(res).assertEqual(false);
let res1 = treemap.get(2);
expect(res1).assertEqual(null);
})
it('SR000GGR3H_testLength016_1', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
treemap.set(3,"d");
treemap.set(4,"g");
let res = treemap.length;
expect(res).assertEqual(5)
})
it('SR000GGR3H_testLength016_2', 0, function () {
let treemap = new TreeMap();
let res = treemap.length;
expect(res).assertEqual(0)
})
it('SR000GGR3H_testForEach017', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
treemap.set(3,"d");
treemap.set(4,"g");
let arr1=[];
let arr2 = [];
treemap.forEach((value,key)=>{
arr1.push(value);
})
treemap.forEach((value,key)=>{
arr2.push(key);
})
let arr=["a","b","c","d","g"];
for(let i=0;i<arr1.length;i++){
expect(arr[i]).assertEqual(arr1[i]);
}
let arr3=[0,1,2,3,4]
for(let i=0;i<arr3.length;i++){
expect(arr3[i]).assertEqual(arr2[i]);
}
})
it('SR000GGR3H_testEntries018', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
treemap.set(3,"d");
treemap.set(4,"g");
let res = treemap.entries();
let arr = ["0,a","1,b","2,c","3,d","4,g"];
for(let i = 0; i < treemap.length; i++){
expect(arr[i]).assertEqual(res.next().value);
}
})
it('SR000GGR3H_testIterator019', 0, function () {
let treemap = new TreeMap();
treemap.set(0,"a");
treemap.set(1,"b");
treemap.set(2,"c");
treemap.set(3,"d");
treemap.set(4,"g");
let arr = ["0,a","1,b","2,c","3,d","4,g"];
let iterArr = [];
for(let [key,value] of treemap) {
iterArr.push(key + "," + value);
}
for(let i=0;i<arr.length;i++){
expect(arr[i]).assertEqual(iterArr[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 {TreeSet} from '@ohos.treeset'
describe('SR000GGR3I_TreeSetTest', function () {
it('SR000GGR3I_testConstructor001', 0, function () {
try{
let treeset = new TreeSet();
expect(treeset != undefined).assertEqual(true)
}catch(err){
expect(err).assertEqual("Error: Cannot create new TreeSet")
}
})
it('SR000GGR3I_testAdd002_1', 0, function () {
let treeset = new TreeSet()
treeset.add("");
let res = treeset.has("");
expect(res).assertEqual(true)
})
it('SR000GGR3I_testAdd002_2', 0, function () {
let treeset = new TreeSet()
treeset.add(8);
let res = treeset.has(8)
expect(res).assertEqual(true)
})
it('SR000GGR3I_testAdd002_3', 0, function () {
let treeset = new TreeSet()
let a=[1,2,3,4]
treeset.add(a);
let res = treeset.has(a)
expect(res).assertEqual(true)
})
it('SR000GGR3I_testAdd002_4', 0, function () {
let treeset = new TreeSet();
treeset.add("*");
let res = treeset.has("*")
expect(res).assertEqual(true)
})
it('SR000GGR3I_testAdd002_5', 0, function () {
let treeset = new TreeSet();
let a={name:'lala',age:'13岁'};
treeset.add(a);
let res = treeset.has(a)
expect(res).assertEqual(true)
})
it('SR000GGR3I_testAdd002_6', 0, function () {
let treeset = new TreeSet();
treeset.add(1.234);
let res = treeset.has(1.234)
expect(res).assertEqual(true)
})
it('SR000GGR3I_testAdd002_7', 0, function () {
let treeset = new TreeSet();
treeset.add(true);
let res = treeset.has(true)
expect(res).assertEqual(true)
})
it('SR000GGR3I_testAdd002_8', 0, function () {
let treeset = new TreeSet();
treeset.add("");
let res = treeset.has("")
expect(res).assertEqual(true)
})
it('SR000GGR3I_testAdd002_9', 0, function () {
let treeset = new TreeSet();
for(let i = 0; i < 10000; i++){
treeset.add(i);
}
expect(treeset.length).assertEqual(10000)
let res = treeset.has(8888)
expect(res).assertEqual(true)
})
it('SR000GGR3I_testLength003_1', 0, function () {
let treeset = new TreeSet()
treeset.add(0);
treeset.add(1);
treeset.add(2);
let res = treeset.length;
expect(res).assertEqual(3);
})
it('SR000GGR3I_testLength003_2', 0, function () {
let treeset = new TreeSet()
let res = treeset.length;
expect(res).assertEqual(0);
})
it('SR000GGR3I_testHas004', 0, function () {
let treeset = new TreeSet()
treeset.add(0);
treeset.add(1);
treeset.add(2);
let res = treeset.has(2);
expect(res).assertEqual(true);
let res1 = treeset.has(3);
expect(res1).assertEqual(false);
})
it('SR000GGR3I_testGetFirstValue005_1', 0, function () {
let treeset = new TreeSet()
treeset.add(0);
treeset.add(1);
treeset.add(2);
treeset.add(3);
treeset.add(4);
let res = treeset.getFirstValue();
expect(res).assertEqual(0);
})
it('SR000GGR3I_testGetFirstValue005_2', 0, function () {
let treeset = new TreeSet()
try{
let res = treeset.getFirstValue();
}catch(err){
expect(err).assertEqual("Error: don't find this key,this tree is null");
}
})
it('SR000GGR3I_testGetLastValue006_1', 0, function () {
let treeset = new TreeSet()
treeset.add(0);
treeset.add(1);
treeset.add(2);
let res = treeset.getLastValue();
expect(res).assertEqual(2);
})
it('SR000GGR3I_testGetLastValue006_2', 0, function () {
let treeset = new TreeSet()
try{
let res = treeset.getLastValue();
}catch(err){
expect(err).assertEqual("Error: don't find this key,this tree is null");
}
})
it('SR000GGR3I_testGetLowerValue007_1', 0, function () {
let treeset = new TreeSet()
treeset.add(0);
treeset.add(1);
treeset.add(2);
treeset.add(3);
treeset.add(4);
let res = treeset.getLowerValue(2);
expect(res).assertEqual(1);
})
it('SR000GGR3I_testGetLowerValue007_2', 0, function () {
let treeset = new TreeSet()
try{
let res = treeset.getLowerValue(2);
}catch(err){
expect(err).assertEqual("Error: don't find this key,this node is undefine");
}
})
it('SR000GGR3I_testGetHigherValue008_1', 0, function () {
let treeset = new TreeSet()
treeset.add(0);
treeset.add(1);
treeset.add(2);
treeset.add(3);
treeset.add(4);
let res = treeset.getHigherValue(3);
expect(res).assertEqual(4);
})
it('SR000GGR3I_testGetHigherValue008_2', 0, function () {
let treeset = new TreeSet()
try{
let res = treeset.getHigherValue(3);
}catch(err){
expect(err).assertEqual("Error: don't find this key,this node is undefine");
}
})
it('SR000GGR3I_testPopFirst009_1', 0, function () {
let treeset = new TreeSet()
treeset.add("a");
treeset.add("b");
treeset.add("c");
treeset.add("d");
treeset.add("e");
let res = treeset.popFirst();
expect(res).assertEqual("a");
})
it('SR000GGR3I_testPopFirst009_2', 0, function () {
let treeset = new TreeSet()
try{
let res = treeset.popFirst();
}catch(err){
expect(err).assertEqual("Error: don't find first node,this tree is empty");
}
})
it('SR000GGR3I_testPopLast010_1', 0, function () {
let treeset = new TreeSet()
treeset.add("a");
treeset.add("b");
treeset.add("c");
treeset.add("d");
treeset.add("e");
let res = treeset.popLast();
expect(res).assertEqual("e");
})
it('SR000GGR3I_testPopLast010_2', 0, function () {
let treeset = new TreeSet()
try{
let res = treeset.popLast();
}catch(err){
expect(err).assertEqual("Error: don't find last node,this tree is empty");
}
})
it('SR000GGR3I_testClear011_1', 0, function () {
let treeset = new TreeSet()
treeset.add(0);
treeset.add(1);
treeset.add(2);
treeset.clear();
let res = treeset.length;
expect(res).assertEqual(0)
})
it('SR000GGR3I_testClear011_2', 0, function () {
let treeset = new TreeSet()
treeset.add(0);
treeset.add(1);
treeset.add(2);
treeset.clear();
let res = treeset.length;
expect(res).assertEqual(0)
treeset.add(3);
try{
treeset.popFirst();
}catch(err){
expect(err).assertEqual("Error: don't find first node,this tree is empty");
}
})
it('SR000GGR3I_testIsEmpty012', 0, function () {
let treeset = new TreeSet()
treeset.add("a");
let res1 = treeset.isEmpty();
expect(res1).assertEqual(false)
treeset.add("b");
treeset.add("c");
treeset.clear();
let res2 = treeset.isEmpty();
expect(res2).assertEqual(true)
})
it('SR000GGR3I_testRemove013_1', 0, function () {
let str1 = "a";
let str2 = "b";
let treeset = new TreeSet()
treeset.add("a");
treeset.add("b");
treeset.add("c");
treeset.add("d");
treeset.add("g");
let res1 = treeset.remove("c");
expect(res1).assertEqual(true)
let res2 = treeset.has("c");
expect(res2).assertEqual(false)
})
it('SR000GGR3I_testRemove013_2', 0, function () {
let treeset = new TreeSet()
let res = treeset.remove("c");
expect(res).assertEqual(false)
})
it('SR000GGR3I_testValues014', 0, function () {
let treeset = new TreeSet()
treeset.add("a");
treeset.add("b");
treeset.add("c");
treeset.add("d");
treeset.add("g");
let res = treeset.values();
expect(res.next().value).assertEqual("a");
expect(res.next().value).assertEqual("b");
expect(res.next().value).assertEqual("c");
expect(res.next().value).assertEqual("d");
expect(res.next().value).assertEqual("g");
})
it('SR000GGR3I_testForEach015', 0, function () {
let treeset = new TreeSet()
treeset.add(0);
treeset.add(1);
treeset.add(2);
treeset.add(3);
treeset.add(4);
let arr1=[];
treeset.forEach((value,key)=>{
arr1.push(value);
})
let arr=[0,1,2,3,4];
for(let i=0;i<arr1.length;i++){
expect(arr[i]).assertEqual(arr1[i]);
}
})
it('SR000GGR3I_testEntries016', 0, function () {
let treeset = new TreeSet()
treeset.add("a");
treeset.add("b");
treeset.add("c");
treeset.add("d");
treeset.add("g");
let res = treeset.entries();
expect(JSON.stringify(res.next().value)).assertEqual("[\"a\",\"a\"]");
expect(JSON.stringify(res.next().value)).assertEqual("[\"b\",\"b\"]");
expect(JSON.stringify(res.next().value)).assertEqual("[\"c\",\"c\"]");
expect(JSON.stringify(res.next().value)).assertEqual("[\"d\",\"d\"]");
expect(JSON.stringify(res.next().value)).assertEqual("[\"g\",\"g\"]");
})
it('SR000GGR3I_testIterator017', 0, function () {
let treeset = new TreeSet()
treeset.add(0);
treeset.add(1);
treeset.add(2);
treeset.add(3);
treeset.add(4);
let arr =[];
for(let item of treeset){
arr.push(item)
}
let arr1 = [0,1,2,3,4]
for(let i=0;i<arr1.length;i++){
expect(arr[i]).assertEqual(arr1[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 {Vector} from '@ohos.vector'
describe('VectorTest', function () {
it('SR000GGR47_testConstructor001', 0, function () {
try{
let vector = new Vector();
}catch(err){
expect(err).assertEqual("Error: Cannot create new vector")
}
})
it('SR000GGR47_testAdd002', 0, function () {
let vector = new Vector();
vector.add("");
let res = vector.getFirstElement()
expect(res).assertEqual("")
})
it('SR000GGR47_testAdd003 ', 0, function () {
let vector = new Vector();
vector.add(4);
let res = vector.getFirstElement()
expect(res).assertEqual(4)
})
it('SR000GGR47_testAdd004 ', 0, function () {
let vector = new Vector();
let a={name:'lala',age:'13岁'}
vector.add(a);
let res = vector.getFirstElement()
expect(res).assertEqual(a)
})
it('SR000GGR47_testAdd005 ', 0, function () {
let vector = new Vector();
let a=[1,2,3,4]
vector.add(a);
let res = vector.getFirstElement()
expect(res).assertEqual(a)
})
it('SR000GGR47_testInsert006', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a')
vector.insert(8,2)
let res = vector.get(2)
expect(res).assertEqual(8)
})
it('SR000GGR47_testInsert007', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a')
try{
vector.insert(-1,2);
}catch(err){
expect(err).assertEqual("Vector: get out-of-bounds")
}
})
it('SR000GGR47_testInsert008', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a')
let capacity = vector.getCapacity();
try{
vector.insert(capacity, 2);
}catch(err){
expect(err).assertEqual("Vector: get out-of-bounds")
}
})
it('SR000GGR47_testInsert009', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a')
let capacity = vector.getCapacity();
try{
vector.insert(capacity + 1, 2);
}catch(err){
expect(err).assertEqual("Vector: get out-of-bounds")
}
})
it('SR000GGR47_testLength010', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a')
let res = vector.length;
expect(res).assertEqual(4)
})
it('SR000GGR47_testHas011', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a')
vector.insert(8,2)
let res = vector.has(8);
expect(res).assertEqual(true);
})
it('SR000GGR47_testHas012', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a')
vector.insert(8,2)
let res1 = vector.has("")
expect(res1).assertEqual(false);
})
it('SR000GGR47_testGet013', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a')
vector.insert(8,2)
let res1 = vector.get(1)
expect(res1).assertEqual("");
})
it('SR000GGR47_testGet014', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a')
vector.insert(8,2)
try{
let res = vector.get(10)
}catch(err){
expect(err).assertEqual("Error: Vector: get out-of-bounds")
}
})
it('SR000GGR47_testGetIndexOf015', 0, function () {
let vector = new Vector();
vector.add(1);
vector.add("");
vector.add(1);
vector.add('a')
vector.insert(1,2)
let res1 = vector.getIndexOf(1)
expect(res1).assertEqual(0);
})
it('SR000GGR47_testGetFirstElement016', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a')
vector.insert(8,2)
try {
let res = vector.getFirstElement();
} catch(err) {
expect(err).assertEqual("Error: Vector: get out-of-bounds");
}
})
it('SR000GGR47_testGetFirstElement017', 0, function () {
let vector = new Vector();
try {
let res = vector.getFirstElement();
} catch(err) {
expect(err).assertEqual("Error: Vector: get out-of-bounds");
}
})
it('SR000GGR47_testSet018', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a')
vector.insert(8,2)
vector.set(1,"");
let res = vector.get(1)
expect(res).assertEqual("");
})
it('SR000GGR47_testRemoveByIndex019', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a')
vector.removeByIndex(2);
let res=vector.has(1);
expect(res).assertEqual(false);
})
it('SR000GGR47_testRemove020', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a')
vector.remove("");
let res=vector.has("");
expect(res).assertEqual(false);
})
it('SR000GGR47_testRemove021', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a')
let res = vector.remove(2);
expect(res).assertEqual(false);
})
it('SR000GGR47_testGetLastElement022', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a');
let res1 = vector.length;
let res=vector.getLastElement()
expect(res).assertEqual("a");
})
it('SR000GGR47_testGetLastElement023', 0, function () {
let vector = new Vector();
let res1 = vector.length;
try {
let res=vector.getLastElement();
} catch(err) {
expect(err).assertEqual("Error: Vector: get out-of-bounds");
}
})
it('SR000GGR47_testGetLastIndexOf024', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a');
vector.add(1);
vector.add("b");
let res = vector.getLastIndexOf(1);
expect(res).assertEqual(4);
})
it('SR000GGR47_testGetLastIndexFrom025', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a');
vector.add(1);
vector.add("b");
vector.add("c");
vector.add(1);
let res = vector.getLastIndexFrom(1,5);
expect(res).assertEqual(4);
})
it('SR000GGR47_testGetIndexFrom026', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a');
vector.add(1);
vector.add("b");
vector.add("c");
vector.add(1);
let res = vector.getIndexFrom(1,5);
expect(res).assertEqual(7);
})
it('SR000GGR47_testRemoveByRange027', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a');
vector.add(1);
vector.add("b");
vector.add("c");
vector.add(1);
vector.removeByRange(1,3);
let arr=[];
vector.forEach((item,index)=>{
arr.push(item);
})
let a=["","a",1,"b","c",1];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR47_testRemoveByRange028', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a');
vector.add(1);
vector.add("b");
vector.add("c");
vector.add(1);
try{
vector.removeByRange(3,1);
}catch(err){
expect(err).assertEqual("Error: fromIndex cannot be less than or equal to toIndex")
}
})
it('SR000GGR47_testRemoveByRange029', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
let length = vector.length;
try{
vector.removeByRange(length+1,7);
}catch(err){
expect(err).assertEqual("Error: Vector: set out-of-bounds")
}
})
it('SR000GGR47_testRemoveByRange030', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
let length = vector.length;
try{
vector.removeByRange(1,7);
}catch(err){
expect(err).assertEqual("vector: deleteProperty out-of-bounds")
}
})
it('SR000GGR47_testRemoveByRange031', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a');
vector.add(1);
vector.add("b");
vector.add("c");
vector.add(1);
let capacity = vector.getCapacity();
try {
vector.removeByRange(0,capacity);
} catch(err) {
expect(err).assertEqual("Error: Vector: set out-of-bounds")
}
let arr=[];
vector.forEach((item,index)=>{
arr.push(item);
})
expect(arr.length).assertEqual(1)
})
it('SR000GGR47_testRemoveByRange032', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a');
vector.add(1);
vector.add("b");
vector.add("c");
vector.add(1);
let capacity = vector.getCapacity();
try{
vector.removeByRange(-1,capacity);
}catch(err){
expect(err).assertEqual("Error: Vector: set out-of-bounds")
}
})
it('SR000GGR47_testRemoveByRange033', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a');
vector.add(1);
vector.add("b");
vector.add("c");
vector.add(1);
let capacity = vector.getCapacity();
vector.removeByRange(0,capacity+1);
let length = vector.length;
expect(length).assertEqual(1)
})
it('SR000GGR47_testSetLength034', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
vector.add(1);
vector.add('a');
vector.add(1);
vector.add("b");
vector.add("c");
vector.add(1);
vector.setLength(5);
let res1 = vector.length
expect(res1).assertEqual(5)
})
it('SR000GGR47_testReplaceAllElements035', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
vector.replaceAllElements((item, index) => {
return (item = 2 * item);
});
let arr=[];
vector.forEach((item,index)=>{
arr.push(item);
})
let a=[8,6,2,4,28];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR47_testForEach036', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
let arr=[];
vector.forEach((item,index)=>{
arr.push(item);
})
let a=[4,3,1,2,14];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR47_testForEach037', 0, function () {
let vector = new Vector();
let arr=[];
vector.forEach((item,index)=>{
arr.push(item);
})
let a=[4,3,1,2,14];
expect(arr.length).assertEqual(0)
})
it('SR000GGR47_testConstructor038', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
let res = vector.subVector(2,4);
let arr=[];
res.forEach((item,index)=>{
arr.push(item);
})
let a=[1,2];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR47_testConstructor039', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
try{
let res = vector.subVector(4,2);
} catch(err) {
expect(err).assertEqual("Error: fromIndex cannot be less than or equal to toIndex")
}
})
it('SR000GGR47_testConstructor040', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
let length = vector.length;
try{
let res = vector.subVector(length+1,length+3);
} catch(err) {
expect(err).assertEqual("Error: fromIndex or toIndex is out-of-bounds")
}
})
it('SR000GGR47_testConstructor041', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
let length = vector.length;
try{
let res = vector.subVector(1,length+1);
} catch(err) {
expect(err).assertEqual("Vector: get out-of-bounds")
}
})
it('SR000GGR47_testClear042', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
vector.clear();
let res = vector.length;
expect(res).assertEqual(0)
})
it('SR000GGR47_testConvertToArray043', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
let arr= vector.convertToArray()
let a=[4,3,1,2,14];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR47_testCopyToArray044', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
let arr1=['a','b','c']
let res = vector.copyToArray(arr1);
let a=[4,3,1];
for(let i=0;i<a.length;i++){
expect(arr1[i]).assertEqual(a[i])
}
})
it('SR000GGR47_testToString045', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
let res = vector.toString();
expect(res).assertEqual('4,3,1,2,14')
})
it('SR000GGR47_testClone046', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
let res = vector.clone();
let arr =[]
res.forEach((item,index)=>{
arr.push(item);
})
let a=[4,3,1,2,14];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR47_testGetCapacity047', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
let res = vector.getCapacity();
expect(res).assertEqual(10)
})
it('SR000GGR47_testGetCapacity048', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
vector.add('a');
vector.add('b');
vector.add('c');
vector.add('d');
vector.add('v');
let a=[1,2,3,4];
vector.add(a);
let res = vector.getCapacity();
expect(res).assertEqual(20)
})
it('SR000GGR47_testIncreaseCapacityTo049', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
vector.increaseCapacityTo(30);
let res = vector.getCapacity();
expect(res).assertEqual(30);
})
it('SR000GGR47_testTrimToCurrentLength050', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
vector.trimToCurrentLength();
let res = vector.getCapacity();
expect(res).assertEqual(5)
})
it('SR000GGR47_testSetLength051', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
vector.setLength(7);
let res1 = vector.length;
expect(res1).assertEqual(7)
})
it('SR000GGR47_testIterator052', 0, function () {
let vector = new Vector();
vector.add(8);
vector.add("")
vector.add("")
vector.add(5);
let c=[1,2,3,4];
vector.add(c);
vector.add(6);
vector.add("")
vector.add("")
let arr =[]
for(let item of vector) {
arr.push(item);
}
let a = [8,"","",5,c,6,"",""]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR47_testIteratorAndRemove053', 0, function () {
let vector = new Vector();
vector.add(8);
vector.add("")
vector.add("")
vector.add(5);
let c=[1,2,3,4];
vector.add(c);
vector.add(6);
vector.add(8);
vector.add("")
vector.add("")
let arr =[]
for(let item of vector) {
if(item == 8) { //remove element 8
vector.remove(8);
}
}
for(let item of vector) {
arr.push(item);
}
let a = ["","",5,c,6,"",""]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR47_testIteratorAndRemove054', 0, function () {
let vector = new Vector();
vector.add(8);
vector.add("")
vector.add("")
vector.add(5);
let c=[1,2,3,4];
vector.add(c);
vector.add(6);
vector.add("")
vector.add("")
let arr =[]
for(let item of vector) {
if(item == 123) { //remove element 123
vector.remove(123);
} else {
arr.push(item);
}
}
let a = [8,"","",5,c,6,"",""]
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR47_testIterator055', 0, function () {
let vector = new Vector();
let arr =[]
for(let item of vector) {
arr.push(item);
}
expect(arr.length).assertEqual(0)
})
it('SR000GGR47_testSort056', 0, function () {
let vector = new Vector();
vector.add(4);
vector.add(3);
vector.add(1);
vector.add(2);
vector.add(14);
vector.sort((a,b) => a-b);
let arr=[];
vector.forEach((item,index)=>{
arr.push(item);
})
let a=[1,2,3,4,14];
for(let i=0;i<a.length;i++){
expect(arr[i]).assertEqual(a[i])
}
})
it('SR000GGR47_testisEmpty057', 0, function () {
let vector = new Vector();
vector.add("");
let res = vector.isEmpty()
expect(res).assertEqual(false)
})
it('SR000GGR47_testisEmpty058', 0, function () {
let vector = new Vector();
let res = vector.isEmpty()
expect(res).assertEqual(true)
})
it('SR000GGR47_testFor059', 0, function () {
let vector = new Vector();
vector.add("");
let length = vector.length;
try{
for(let i = 0; i < length; i++){
}
}catch(err){
expect(err).assertEqual("Error: Cannot create new vector")
}
})
it('SR000GGR47_testAdd060', 0, function () {
let vector = new Vector();
for (let i = 0; i < 100; i++) {
let res3 = vector.add(i);
}
let res = vector.getLastElement();
let res1 = vector.length;
expect(res).assertEqual(99);
expect(res1).assertEqual(100);
})
it('SR000GGR47_testAdd061 ', 0, function () {
let vector = new Vector();
vector.add('%');
let res = vector.getFirstElement()
expect(res).assertEqual('%')
})
it('SR000GGR47_testAdd062 ', 0, function () {
let vector = new Vector();
vector.add(1.89);
let res = vector.getFirstElement()
expect(res).assertEqual(1.89)
})
it('SR000GGR47_testAdd063 ', 0, function () {
let vector = new Vector();
vector.add('');
let res = vector.getFirstElement()
expect(res).assertEqual('')
})
it('SR000GGR47_testAdd064 ', 0, function () {
let vector = new Vector();
vector.add(true);
let res = vector.getFirstElement()
expect(res).assertEqual(true)
})
it('SR000GGR47_testGetIndexOf065', 0, function () {
let vector = new Vector();
vector.add(1);
vector.add(2);
vector.add(3);
let res = vector.getIndexOf(23)
expect(res).assertEqual(-1);
})
it('SR000GGR47_testSet066', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
try{
vector.set(12,"");
}catch(err){
expect(err).assertEqual("Error: Vector: set out-of-bounds")
}
})
it('SR000GGR47_testRemoveByIndex067', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
try{
vector.removeByIndex(12);
}catch(err){
expect(err).assertEqual("Error: Vector: get out-of-bounds")
}
})
it('SR000GGR47_testGetLastIndexOf068', 0, function () {
let vector = new Vector();
vector.add("");
vector.add("");
let res = vector.getLastIndexOf("");
expect(res).assertEqual(-1);
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册