服务计算概论作业报告.docx

上传人:b****6 文档编号:4451414 上传时间:2022-12-01 格式:DOCX 页数:18 大小:131.96KB
下载 相关 举报
服务计算概论作业报告.docx_第1页
第1页 / 共18页
服务计算概论作业报告.docx_第2页
第2页 / 共18页
服务计算概论作业报告.docx_第3页
第3页 / 共18页
服务计算概论作业报告.docx_第4页
第4页 / 共18页
服务计算概论作业报告.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

服务计算概论作业报告.docx

《服务计算概论作业报告.docx》由会员分享,可在线阅读,更多相关《服务计算概论作业报告.docx(18页珍藏版)》请在冰豆网上搜索。

服务计算概论作业报告.docx

服务计算概论作业报告

 

慕测平台测试报告

(二)

学院:

计算机学院

姓名:

赵红娜

专业:

软件工程

学号:

3130608003

班级:

1301

完成日期:

2016-10-22

2016年10月22日

1.题目

针对以下4个项目编写测试用例进行测试。

代码如下:

题目

(1)

//BinaryHeapclass

//

//CONSTRUCTION:

withoptionalcapacity(thatdefaultsto100)

//

//******************PUBLICOPERATIONS*********************

//voidinsert(x)-->Insertx

//intdeleteMin()-->Returnandremovesmallestitem

//intfindMin()-->Returnsmallestitem

//booleanisEmpty()-->Returntrueifempty;elsefalse

//booleanisFull()-->Returntrueiffull;elsefalse

//voidmakeEmpty()-->Removeallitems

//******************ERRORS********************************

//ThrowsOverflowifcapacityexceeded

/**

*Implementsabinaryheap.

*Notethatall"matching"isbasedonthecompareTomethod.

*@authorMarkAllenWeiss

*/

publicclassBinaryHeap

{

//@invariantwellFormed();

/**

*Constructthebinaryheap.

*/

publicBinaryHeap()

{

this(DEFAULT_CAPACITY);

}

/**

*Constructthebinaryheap.

*@paramcapacitythecapacityofthebinaryheap.

*/

//@requirescapacity>0;

//@ensuresisEmpty();

publicBinaryHeap(intcapacity)

{

currentSize=0;

array=newint[capacity+1];

}

/**

*Insertintothepriorityqueue,maintainingheaporder.

*Duplicatesareallowed.

*@paramxtheitemtoinsert.

*@exceptionOverflowifcontainerisfull.

*/

publicvoidinsert(intx)throwsOverflow

{

if(isFull())

thrownewOverflow();

//Percolateup

inthole=++currentSize;

for(;hole>1&&x

array[hole]=array[hole/2];

array[hole]=x;

}

/**

*Findthesmallestiteminthepriorityqueue.

*@returnthesmallestitem,ornull,ifempty.

*/

publicintfindMin()

{

if(isEmpty())

return-1;

returnarray[1];

}

booleanwellFormed(){

if(array==null){//array!

=null

returnfalse;

}

if(currentSize<0||currentSize>=array.length){//currentSize>=0;currentSize

returnfalse;

}

for(inti=1;i

if(i*2<=currentSize&&array[i]>array[2*i]){

returnfalse;

}

if(i*2+1<=currentSize&&array[i]>array[2*i+1]){

returnfalse;

}

}

returntrue;

}

/**

*Removethesmallestitemfromthepriorityqueue.

*@returnthesmallestitem,ornull,ifempty.

*/

publicintdeleteMin()

{

if(isEmpty())

return-1;

intminItem=findMin();

array[1]=array[currentSize--];

percolateDown

(1);

returnminItem;

}

/**

*Establishheaporderpropertyfromanarbitrary

*arrangementofitems.Runsinlineartime.

*/

publicvoidbuildHeap()

{

for(inti=currentSize/2;i>0;i--)

percolateDown(i);

}

/**

*Testifthepriorityqueueislogicallyempty.

*@returntrueifempty,falseotherwise.

*/

publicbooleanisEmpty()

{

returncurrentSize==0;

}

/**

*Testifthepriorityqueueislogicallyfull.

*@returntrueiffull,falseotherwise.

*/

publicbooleanisFull()

{

returncurrentSize==array.length-1;

}

/**

*Makethepriorityqueuelogicallyempty.

*/

//@ensuresisEmpty();

publicvoidmakeEmpty()

{

currentSize=0;

}

privatestaticfinalintDEFAULT_CAPACITY=100;

privateintcurrentSize;//Numberofelementsinheap

privateint[]array;//Theheaparray

/**

*Internalmethodtopercolatedownintheheap.

*@paramholetheindexatwhichthepercolatebegins.

*/

privatevoidpercolateDown(inthole)

{

intchild;

inttmp=array[hole];

for(;hole*2<=currentSize;hole=child)

{

child=hole*2;

if(child!

=currentSize&&

array[child+1]

child++;

if(array[child]

array[hole]=array[child];

else

break;

}

array[hole]=tmp;

}

 

}

/**

*Exceptionclassforaccessinfullcontainers

*suchasstacks,queues,andpriorityqueues.

*@authorMarkAllenWeiss

*/

publicclassOverflowextendsException

{

}

题目

(2)

importjava.util.Comparator;

importjava.util.Random;

/**

*Aclassthatcontainsseveralsortingroutines,

*implementedasstaticmethods.

*Arraysarerearrangedwithsmallestitemfirst,

*usingcompareTo.

*@authorMarkAllenWeiss

*/

publicfinalclassSorting

{

/**

*Simpleinsertionsort.

*@paramaanarrayofComparableitems.

*/

publicvoidinsertionSort(int[]a)

{

intj;

for(intp=1;p

{

inttmp=a[p];

for(j=p;j>0&&tmp

a[j]=a[j-1];

a[j]=tmp;

}

}

publicbooleanisSorted(int[]a){

for(inti=0;i

if(a[i]>a[i+1]){

returnfalse;

}

}

returntrue;

}

publicstaticvoidquicksort(int[]a)

{

quicksort(a,0,a.length-1);

}

privatestaticfinalintCUTOFF=10;

publicstaticfinalvoidswapReferences(Object[]a,intindex1,intindex2)

{

Objecttmp=a[index1];

a[index1]=a[index2];

a[index2]=tmp;

}

publicstaticfinalvoidswap(int[]a,intindex1,intindex2){

inttmp=a[index1];

a[index1]=a[index2];

a[index2]=tmp;

}

privatestaticintmedian3(int[]a,intleft,intright)

{

intcenter=(left+right)/2;

if(a[center]

swap(a,left,center);

if(a[right]

swap(a,left,right);

if(a[right]

swap(a,center,right);

//Placepivotatpositionright-1

swap(a,center,right-1);

returna[right-1];

}

privatestaticvoidquicksort(int[]a,intleft,intright)

{

if(left+CUTOFF<=right)

{

intpivot=median3(a,left,right);

inti=left,j=right-1;

for(;;)

{

while(a[++i]

while(a[--j]>pivot){}

if(i

swap(a,i,j);

else

break;

}

swap(a,i,right-1);//Restorepivot

quicksort(a,left,i-1);//Sortsmallelements

quicksort(a,i+1,right);//Sortlargeelements

}

else//Doaninsertionsortonthesubarray

insertionSort(a,left,right);

}

privatestaticvoidinsertionSort(int[]a,intleft,intright)

{

for(intp=left+1;p<=right;p++)

{

inttmp=a[p];

intj;

for(j=p;j>left&&tmp

a[j]=a[j-1];

a[j]=tmp;

}

}

privatestaticfinalintNUM_ITEMS=1000;

privatestaticinttheSeed=1;

}

题目(3)

publicclassStatistics{

/**

*

*@paramnumbers

*@returnthelengthofthearray

*/

publicintcalLength(int[]numbers){

intlength=numbers.length;

returnlength;

}

/**

*

*@paramnumbers

*@returnthemeanvalueofthearray

*/

publicdoublecalMean(int[]numbers){

intlength=calLength(numbers);

doublesum;

sum=0.0;

for(inti=0;i

sum+=numbers[i];

}

doublemean=sum/(double)length;

returnmean;

}

/**

*

*@paramnumbers

*@returnthevarvalueofthearray

*/

publicdoublecalVar(int[]numbers){

intlength=calLength(numbers);

doublemean=calMean(numbers);

doublevarsum=0.0;

for(inti=0;i

varsum=varsum+((numbers[i]-mean)*(numbers[i]-mean));

}

doublevar=varsum/(length-1.0);

returnvar;

}

}

题目(4)

publicclassTriangle{

protectedlonglborderA=0;

protectedlonglborderB=0;

protectedlonglborderC=0;

//Constructor

publicTriangle(longlborderA,longlborderB,longlborderC){

this.lborderA=lborderA;

this.lborderB=lborderB;

this.lborderC=lborderC;

}

/**

*checkifitisatriangle

*

*@returntruefortriangleandfalsenot

*/

publicbooleanisTriangle(Triangletriangle){

booleanisTriangle=false;

//checkboundary

if((triangle.lborderA>0&&triangle.lborderA<=Long.MAX_VALUE)

&&(triangle.lborderB>0&&triangle.lborderB<=Long.MAX_VALUE)

&&(triangle.lborderC>0&&triangle.lborderC<=Long.MAX_VALUE)){

//checkifsubtractionoftwoborderlargerthanthethird

if(diffOfBorders(triangle.lborderA,triangle.lborderB)

&&diffOfBorders(triangle.lborderB,triangle.lborderC)

&&diffOfBorders(triangle.lborderC,triangle.lborderA)

isTriangle=true;

}

}

returnisTriangle;

}

/**

*Checkthetypeoftriangle

*

*Consistsof"Illegal","Regular","Scalene","Isosceles"

*/

publicStringgetType(Triangletriangle){

StringstrType="Illegal";

if(isTriangle(triangle)){

//IsRegular

if(triangle.lborderA==triangle.lborderB

&&triangle.lborderB==triangle.lborderC){

strType="Regular";

}

//Ifscalene

elseif((triangle.lborderA!

=triangle.lborderB)

&&(triangle.lborderB!

=triangle.lborderC)

&&(triangle.lborderA!

=triangle.lborderC)){

strType="Scalene";

}

//ifisosceles

else{

strType="Isosceles";

}

}

returnstrType;

}

/**

*calculatethediffbetweenborders

*

**/

publiclongdiffOfBorders(longa,longb){

return(a>b)?

(a-b):

(b-a);

}

/**

*getlengthofborders

*/

publiclong[]getBorders(){

long[]borders=newlong[3];

borders[0]=this.lborderA;

borders[1]=this.lborderB;

borders[2]=this.lborderC;

returnborders;

}

}

2.软件工具

Eclipse

3.测试代码

题目

(1)

importorg.junit.After;

importorg.junit.Before;

importorg.junit.Test;

importorg.junit.Assert;

publicclassBinaryHeapTest{

@Before

publicvoidsetUp()throwsException{

}

@After

publicvoidtearDown()throwsException{

}

@Test

publicvoidtest(){

BinaryHeapheap1=newBinaryHeap(1024);

for(inti=1024;i>0;i--){

try{

heap1.insert(i);

}catch(Overflowe){

Assert.fail(e.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 英语

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1