1、2016-2017-1 慕测平台测试报告1慕测平台测试报告(二)2016 年 10 月 22学 院: 计算机学院 姓 名: 赵红娜专 业: 软件工程 学 号: 3130608003班 级: 1301 完成日期: 2016-10-222016-2017-1 慕测平台测试报告2日1.题目针对以下 4 个项目编写测试用例进行测试。代码如下:题目(1)/ BinaryHeap class/ CONSTRUCTION: with optional capacity (that defaults to 100)/ *PUBLIC OPERATIONS*/ void insert( x ) Insert x
2、/ int deleteMin( ) Return and remove smallest item/ int findMin( ) Return smallest item/ boolean isEmpty( ) Return true if empty; else false/ boolean isFull( ) Return true if full; else false/ void makeEmpty( ) Remove all items/ *ERRORS*/ Throws Overflow if capacity exceeded/* Implements a binary he
3、ap.* Note that all “matching“ is based on the compareTo method.* author Mark Allen Weiss*/public class BinaryHeap/ invariant wellFormed();/* Construct the binary heap.*/public BinaryHeap( )this( DEFAULT_CAPACITY );/* Construct the binary heap.* param capacity the capacity of the binary heap.*/ requi
4、res capacity 0;/ ensures isEmpty();public BinaryHeap( int capacity )currentSize = 0;array = new int capacity + 1 ;/* Insert into the priority queue, maintaining heap order.* Duplicates are allowed.* param x the item to insert.* exception Overflow if container is full.*/public void insert( int x ) th
5、rows Overflowif( isFull( ) )throw new Overflow( );/ Percolate upint hole = +currentSize;for( ; hole 1 currentSizearray2*i) return false;if(i*2 + 1array2*i+1) return false;return true;/* Remove the smallest item from the priority queue.* return the smallest item, or null, if empty.*/public int delete
6、Min( )if( isEmpty( ) )return -1;int minItem = findMin( );array 1 = array currentSize- ;percolateDown( 1 );return minItem;/* Establish heap order property from an arbitrary* arrangement of items. Runs in linear time.*/public void buildHeap( )for( int i = currentSize / 2; i 0; i- )percolateDown( i );/
7、* Test if the priority queue is logically empty.* return true if empty, false otherwise.*/public boolean isEmpty( )return currentSize = 0;/* Test if the priority queue is logically full.* return true if full, false otherwise.*/public boolean isFull( )return currentSize = array.length - 1;2016-2017-1
8、 慕测平台测试报告4/* Make the priority queue logically empty.*/ ensures isEmpty();public void makeEmpty( )currentSize = 0;private static final int DEFAULT_CAPACITY = 100;private int currentSize; / Number of elements in heapprivate int array; / The heap array/* Internal method to percolate down in the heap.*
9、 param hole the index at which the percolate begins.*/private void percolateDown( int hole )int child;int tmp = array hole ;for( ; hole * 2 0 return true;public static void quicksort( int a )quicksort( a, 0, a.length - 1 );private static final int CUTOFF = 10;public static final void swapReferences(
10、 Object a, int index1, int index2 )Object tmp = a index1 ;a index1 = a index2 ;a index2 = tmp;public static final void swap(int a,int index1,int index2) int tmp = a index1 ;a index1 = a index2 ;a index2 = tmp;private static int median3( int a, int left, int right )int center = ( left + right ) / 2;i
11、f( a center pivot ) if( i left /* get length of borders*/public long getBorders() long borders = new long3;borders0 = this.lborderA;borders1 = this.lborderB;borders2 = this.lborderC;return borders;2.软件工具Eclipse3.测试代码题目(1)import org.junit.After;import org.junit.Before;import org.junit.Test;import org
12、.junit.Assert;public class BinaryHeapTest Beforepublic void setUp() throws Exception Afterpublic void tearDown() throws Exception Testpublic void test() BinaryHeap heap1 = new BinaryHeap(1024);for (int i = 1024; i 0; i-) try heap1.insert(i); catch (Overflow e) Assert.fail(e.getMessage();if (heap1.we
13、llFormed() 2016-2017-1 慕测平台测试报告9heap1.buildHeap();heap1.deleteMin();heap1.makeEmpty();heap1.findMin();heap1.deleteMin();题目(2)import org.junit.Before;import org.junit.After;import org.junit.Test;public class SortingTest private int num;private int num1 = new int50;private int num2 = new int50;private
14、 Object ref = new Object 3, 4, 5, 6, 9 ;private Sorting sorting;Beforepublic void setUp() throws Exception sorting = new Sorting();for (int i = 0; i 50; i+) num = (int) (Math.random() * 50);num1i = num;for (int i = 0; i 50; i+) num = (int) (Math.random() * 50);num2i = num;Afterpublic void tearDown()
15、 throws Exception Testpublic void test() sorting.quicksort(num1);sorting.isSorted(num1);sorting.insertionSort(num2);2016-2017-1 慕测平台测试报告10sorting.isSorted(num2);sorting.swapReferences(ref, 1, 5);题目(3)import org.junit.After;import org.junit.Before;import org.junit.Test;public class StatisticsTest pri
16、vate Statistics st ;Beforepublic void setUp() throws Exception st=new Statistics();Afterpublic void tearDown() throws Exception Testpublic void testCalVar() int nums=new int200,300,400,500,600;st.calVar(nums);题目(4)import org.junit.After;import org.junit.Before;import org.junit.Test;public class Tria
17、ngleTest private Triangle triangle1,triangle2,triangle3,triangle4;Beforepublic void setUp() throws Exception triangle1 = new Triangle(4, 4, 4);triangle2 = new Triangle(2,2,3);triangle3 = new Triangle(4,5,6);triangle4 = new Triangle(2,5,9);2016-2017-1 慕测平台测试报告11Afterpublic void tearDown() throws Exce
18、ption Testpublic void test() triangle1.getBorders();if(triangle1.isTriangle(triangle1)triangle1.getType(triangle1);triangle2.getBorders();if(triangle2.isTriangle(triangle2)triangle2.getType(triangle2);triangle3.getBorders();if(triangle3.isTriangle(triangle3)triangle3.getType(triangle3);triangle4.getBorders();if(triangle4.isTriangle(triangle4)triangle4.getType(triangle4);4.运行结果5.分数95.5556.收获和体会通过这次试验,让我对软件测试的基本概念,工具,方法都有了清晰的认识,掌握了基本的软件测试流程,提高了代码的编写能力,开扩了眼界,为以后的学习和工作打下了坚实的基础。