码迷,mamicode.com
首页 > 其他好文 > 详细

第四次作业

时间:2016-03-31 21:45:09      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

(a)

技术分享

(b) when MAXPRIMES = 4, array will out of bound

(c) n = 1

(d) node coverage:

  TR = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}

  Test Paths: [1,2,3,4,5,6,7,8,5,9,10,11,12,2,13,14,15,16]

  edge coverage:

  TR = {(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(6,8),(7,8),(8,5),(5,9),(9,10),(10,11),(11,12),(10,12),(12,2),(2,13),(13,14),(14,15),(15,14),(14,16)}

  prime path coverage:

  TR = {[1,2,13,14,16],[1,2,13,14,15],[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,8],[1,2,3,4,5,9,10,11,12],[1,2,3,4,5,9,10,12]}

全路径覆盖的例子:

判断三角形是等边,等腰,还是普通三角形。

判断三角形代码:

public class triangle {
	private static int result = -1;
	public void triangle(int a,int b,int c)
	{
		if(a<=0 || b<=0 || c<=0)
		{
			result = -1;
		}
		else
		{
			if(((a+b)>c) && ((a+c)>b && (b+c)>a))
			{
				if((a == b) &&(a == c))
			    {
				  result = 3;
			    }
				if((a==b && a!=c)||(a==c && a!=b)||(b==c && a!=b))
				{
					result = 2;
					
				}
				if(a!=b && a!=c && b!=c)
				{
					result = 1;
				}
			}
			
			else
			{
				result = -1;
			}
		}
		
	}
	
	
	public int getResult(){
		return result;
	}
	
		public void clear(){
		result = -1;
	}

}

  

测试代码:

import static org.junit.Assert.*;
import org.junit.Test;
public class test {
	
	private static triangle cal = new triangle();
	@Test
	public void testTriangle(){
		
	cal.triangle(3, 4, 5);
	assertEquals(1, cal.getResult());
	cal.triangle(3, 3, 5);
	assertEquals(2, cal.getResult());
	cal.triangle(6, 6, 6);
	assertEquals(3, cal.getResult());
	cal.triangle(10, 4, 4);
	assertEquals(-1, cal.getResult());
	cal.triangle(-1, 3, 4);
	assertEquals(-1, cal.getResult());
	}
	

}

  

这是代码的结构:

技术分享

测试结果的截图:

技术分享

第四次作业

标签:

原文地址:http://www.cnblogs.com/WentaiLi/p/5342803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!