版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
.慕測(cè)平臺(tái)測(cè)試報(bào)告(二)姓名:趙紅娜專業(yè):軟件工程學(xué)號(hào):313060800310-222016年10月22.日針對(duì)以下4個(gè)項(xiàng)目編寫(xiě)測(cè)試用例進(jìn)行測(cè)試。代碼如下:題目(1)//BinaryHeapclass////CONSTRUCTION:withoptionalcapacity(thatdefaultsto100)////******************PUBLICOPERATIONS*********************voidinsertx)-->InsertxeMinReturnandallitems//******************ERRORS********************************//ThrowsOverflowifcapacityexceeded/***Implementsabinaryheap.*Notethatall"matching"isbasedonremovesmallestitemthecompareTomethod.//intfindMin()-->Returnsmallest*@authorMarkAllenWeiss//booleanisEmpty()-->ReturnpublicclassBinaryHeaptrueifempty;elsefalse{//booleanisFull()-->Return//@invariantwellFormed();trueiffull;elsefalse/**voidmakeEmpty-->Remove*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();//Percolateupinthole=++currentSize;for(;hole>1&&x<array[hole/2];hole/=2)array[hole]=array[hole/array[hole]=x;}/***Findthesmallestiteminthepriorityqueue.*@returnthesmallestitem,ornull,ifempty.publicintfindMin(){if(isEmpty())return-1;returnarray[1];}booleanwellFormed(){if(array==null){//array!=nullreturnfalse;}if(currentSize<0||currentSize>=array.length){//currentSize>=0;currentSize<array.length;returnfalse;}for(inti=1;i<currentSize;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;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;//Numberofelementsinheapprivateint[]array;//Theheapray/***Internalmethodtopercolatedownintheheap.*@paramholetheindexatwhichthepercolatebegins.privatevoidpercolateDown(int{intchild;for(;hole*2<=currentSize;hole=child){child=hole*2;if(child!=currentSize&&array[child+1]<array[child])child+;if(array[child]<tmp)array[hole]=array[child];elsebreak;}array[hole]=tmp;}}inttmp=array[hole];./***Exceptionclassforaccessinfullcontainers*suchasstacks,queues,andpriorityqueues. *@authorMarkAllenWeiss publicclassOverflowextendsException {}題目(2)importjava.util.Comparator;importjava.util.Random;/***Aclassthatcontainsseveralsortinges*implementedasstaticmethods.*Arraysarerearrangedwithsmallestitemfirst,*usingcompareTo.*@authorMarkAllenWeisspublicfinalclassSorting{/***Simpleinsertionsort.*@paramaanarrayofComparableitems.publicvoidinsertionSort(int[]a){for(intp=1;p<a.length;{inttmp=a[p];for(j=p;j>0&&tmp<a[j-1];j--)a[j]=a[j-1];a[j]=tmp;}}publicbooleanisSorted(int[]a){for(inti=0;i<a.length-1;i++){if(a[i]>a[i+1]){returnfalse}}turntrue}publicstaticvoidquicksort(int[]{quicksort(a,0,a.length-1);}privatestaticfinalintCUTOFF=10;publicstaticfinalvoid.swapReferences(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]<a[left])swap(a,left,center);if(a[right]<a[left])swap(a,left,right);if(a[right]<a[center]).swap(a,center,right);swap(a,i,j);//Placepivotatpositionright-1swap(a,center,right-1);returna[right-1];}eak}swap(a,i,right-1);//privatestaticvoidquicksort(int[]a,intleft,intright){if(left+CUTOFF<=right){intpivot=median3(a,left,inti=left,j=right-1;for(;;){while(a[++i]<pivot)}while(a[--j]>pivot)}jquicksortalefti-1);//Sortsmallelementsquicksort(a,i+1,right);//Sortlargeelements}else//DoaninsertionsortonthesubarrayinsertionSort(a,left,}privatestaticvoidinsertionSort(int[]a,intleft,intright){for(intp=left+1;p<=right;{inttmp=a[p];for(j=p;j>left&&tmpaj];j--)a[j]=a[j-1];a[j]=tmp;題目(3)publicclassStatistics{/****@paramnumbers*@returnthelengthofthearraypublicintcalLength(int[]numbers){intlength=numbers.length;returnlength;}/**.}}privatestaticfinalintNUM_ITEMSprivatestaticinttheSeed=1;}**@paramnumbers*@returnthemeanvalueoftheraypublicdoublecalMean(int[]numbers){intlength=calLength(numbers);doublesum;sum=0.0;for(inti=0;i<length;i++){sum+=numbers[i];}doublemean=sum/(double)returnmean;}/****@paramnumbers*@returnthevarvalueofthe.doublemean=calMean(numbers);doublevarsum=0.0;for(inti=0;i<length;i++){varsum=varsum+((numbers[i]-mean)*(numbers[i]-an}doublevar=varsum/(lengthraypublicdoublecalVar(int[]numbers){intlength=calLength(numbers);題目(4)publicclassTriangle{protectedlonglborderA=0;protectedlonglborderB=0;protectedlonglborderC=0;returnvar;}}//ConstructorpublicTriangle(longlborderA,longlborderB,longlborderC){this.lborderA=lborderA;.this.lborderB=lborderB;this.lborderC=lborderC;}/***checkifitisatriangle**@returntruefortriangleandfalsenotpublicbooleanisTriangle(Triangletriangle){booleanisTriangle=false;//checkboundaryif((triangle.lborderA>0&&triangle.lborderA<=Long.MAX_VALU(triangle.lborderB>0&&triangle.lborderB<=(triangle.lborderC>0&&triangle.lborderC<=Long.MAX_VALU){//checkifsubtractionoftwoborderlargerthanthethirdif(diffOfBorders(triangle.lborderA,triangle.lborderB)<triangle.lborderCdiffOfBorders(triangle.lborderB,triangle.lborderC)<triangle.lborderAdiffOfBorders(triangle.lborderC,triangle.lborderA)<triangle.lborderB){isTriangle=true;}}returnisTriangle;}Long.MAX_VALU/***Checkthetypeoftriangle**Consistsof"Illegal","Regular","Scalene","Isosceles"publicStringgetType(Triangletriangle){StringstrType="Illegal";if(isTriangle(triangle)){//IsRegularif(triangle.lborderA==triangle.lborderBtriangle.lborderB==triangle.lborderC).(triangle.lborderA!=triangle.lborderC)){strTypeScalene;} //ifisosceles else{strType="Isosceles";}}returnstrType;}/***calculatethediffbetween{strType="Regular";*}**/ //Ifscalene publiclongdiffOfBorders(longa,elseiflongb){((triangle.lborderA!=triangle.lborderB)return(a>b)?(a-b):(b-a);}(triangle.lborderB!=triangle.lborderC).borders[1]=this.lborderB;/**borders[2]=this.lborderC;*getlengthofbordersreturnborders;}publiclong[]getBorders(){}long[]borders=newlong[3];borders[0]=this.lborderA;題目(1)importorg.junit.After;importorg.junit.Before;importorgjunitTestimportorg.junit.Assert;publicvoidsetUp()Exception{}publicvoidtearDown()throwsthrowsException{publicclassBinaryHeapTest{}.publicvoidtest(){BinaryHeapheap1=newBinaryHeap(1024);for(inti=1024;i>0;i--){try{heap1.insert(i);}catch(Overflowe){Assert.fail(e.getMessage());}}heap1.makeEmpty();heap1.findMin();heap1.deleteMin();}}題目(2)if(heap1.wellFormed()){heap1.buildHeap();}heap1.deleteMin();importorg.junit.Before;importorg.junit.After;importorgjunitTestpublicclassSortingTest{privateintnum;privateint[]num1=newint[50];privateint[]num2=newint[50];privateObject[]ref=newObject[]{3,4,5,6,9};privateSortingsorting;publicvoidsetUp()throws.Exception{}sorting=newSorting();for(inti=0;i<50;i++){num=(int)(Math.random()*50);num1[i]=num;}for(inti=0;i<50;i++){num=(int)(Math.random()*50);num2[i]=num;}publicvoidtest(){sorting.quicksort(num1);sorting.isSorted(num1);sorting.insertionSort(num2);sorting.isSorted(num2);sorting.swapReferences(ref,1,}}}}publicvoidtearDown()throwsException{題目(3)importorg.junit.After;importorg.junit.Before;importorgjunitTestpublicclassStatisticsT
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 糖尿病模型討論與分析
- 物業(yè)客服部員工培訓(xùn)
- 露天礦山安全培訓(xùn)課件經(jīng)典
- 互聯(lián)網(wǎng)平臺(tái)會(huì)計(jì)勞動(dòng)合同
- 城市綜合體外保溫施工合同
- 生物科技辦公樓施工承包合同
- 山東影劇院建設(shè)合同
- 墻紙施工合同幼兒園歡樂(lè)世界
- 地下商場(chǎng)建設(shè)鉆探施工合同
- 教育信息化項(xiàng)目招投標(biāo)攻略
- (正式版)SH∕T 3541-2024 石油化工泵組施工及驗(yàn)收規(guī)范
- 【中考真題】2024年江西省初中學(xué)業(yè)水平考試歷史真題試卷(含答案)
- 內(nèi)科知識(shí)練習(xí)題庫(kù)(附答案)
- 【易錯(cuò)題】蘇教版數(shù)學(xué)六年級(jí)上冊(cè)第5單元《分?jǐn)?shù)四則混合運(yùn)算》易錯(cuò)題強(qiáng)化訓(xùn)練卷(含答案)
- 云南省高中學(xué)業(yè)水平考試數(shù)學(xué)考題分類匯編以及知識(shí)點(diǎn)穿插
- 頭暈眩暈診斷與治療
- 物業(yè)反恐應(yīng)急演練方案(2篇)
- 揚(yáng)州邗江區(qū)2023-2024六年級(jí)英語(yǔ)上冊(cè)期中試卷及答案
- 2024年遼寧石化職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性測(cè)試題庫(kù)含答案
- 2024年燕舞集團(tuán)限公司公開(kāi)招聘公開(kāi)引進(jìn)高層次人才和急需緊缺人才筆試參考題庫(kù)(共500題)答案詳解版
- 四年級(jí)上冊(cè)語(yǔ)文 第六單元《一只窩囊的大老虎》教學(xué)課件 第1課時(shí)
評(píng)論
0/150
提交評(píng)論