版權(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 食堂食材采購(gòu)招標(biāo)
- 房產(chǎn)買(mǎi)賣合同糾紛的代理詞
- 少年責(zé)任心擔(dān)保書(shū)
- 二手住宅買(mǎi)賣協(xié)議模板
- 租賃合同修補(bǔ)協(xié)議
- 茶葉禮盒裝購(gòu)銷協(xié)議
- 招標(biāo)文件施工標(biāo)準(zhǔn)
- 退伍軍人的未來(lái)承諾
- 農(nóng)田整治工程招標(biāo)公告
- 設(shè)備保修服務(wù)合同范本
- 氣管插管術(shù)評(píng)分標(biāo)準(zhǔn)
- 文學(xué)概論智慧樹(shù)知到期末考試答案章節(jié)答案2024年甘肅政法大學(xué)
- 30題會(huì)務(wù)專員崗位常見(jiàn)面試問(wèn)題含HR問(wèn)題考察點(diǎn)及參考回答
- MOOC 中國(guó)天氣-南京信息工程大學(xué) 中國(guó)大學(xué)慕課答案
- 全國(guó)養(yǎng)老護(hù)理職業(yè)技能大賽養(yǎng)老護(hù)理員賽項(xiàng)考試題庫(kù)-上(單選題)
- 倉(cāng)管員年度述職報(bào)告總結(jié)
- 口腔科誤吞誤吸應(yīng)急處理
- 2024年福建廣電網(wǎng)絡(luò)集團(tuán)有限公司招聘筆試參考題庫(kù)附帶答案詳解
- 武大生物化學(xué)復(fù)習(xí)資料
- 國(guó)家開(kāi)放大學(xué)《數(shù)據(jù)結(jié)構(gòu)》課程實(shí)驗(yàn)報(bào)告(實(shí)驗(yàn)5-圖的存儲(chǔ)方式和應(yīng)用)參考答案
- 部編版語(yǔ)文五年級(jí)下冊(cè)第二單元走進(jìn)中國(guó)古典名著 大單元整體教學(xué)設(shè)計(jì)
評(píng)論
0/150
提交評(píng)論