# 单元测试#

201421123098 胡丹丹 201421123118 张中结

1.整数四则运算测试

2.分数四则运算测试

3.求最大公约数测试

## 三、测试用例##

1.整数四则运算测试

  @Test
Calculate cal = new Calculate();
String expected="32778";
assertEquals(expected, result);
}
@Test
public void testSub() {
Calculate cal = new Calculate();
String result = cal.sub(6,3);
String expected="3";
assertEquals(expected, result);

}
@Test
public void testMul() {
Calculate cal = new Calculate();
String result = cal.mul(6,3);
String expected="18";
assertEquals(expected, result);
}
@Test
public void testDiv() {
Calculate cal = new Calculate();
String result = cal.div(5,2);
String expected="5/2";
assertEquals(expected, result);
}


2.真分数四则运算测试

 @Test
//fail("Not yet implemented");
Calculate cal = new Calculate();
String expected="7/5";
assertEquals(expected, result);
}
@Test
public void testScoreSub() {
Calculate cal = new Calculate();
String result = cal.ScoreSub(4,5,1,5);
String expected="3/5";
assertEquals(expected, result);
}
@Test
public void testScoreMul() {
Calculate cal = new Calculate();
String result = cal.ScoreMul(4,5,1,5);
String expected="4/25";
assertEquals(expected, result);
}
@Test
public void testScoreDiv() {
Calculate cal = new Calculate();
String result = cal.ScoreDiv(4,5,1,2);
String expected="8/5";
assertEquals(expected, result);
}
}


3.求最大公约数测试

@Test
public void testReduce(){
Calculate cal = new Calculate();
int result = cal.reduce(40,20);
int expected=20;
assertEquals(expected, result);
}


4.运行结果

5.覆盖率

6.测试中遇到的问题

public String ScoreAdd(int x,int y,int q,int w){
strz = "+";
int temp1 = x * w + q * y;
int temp2 = y * w;
int temp3 = reduce(temp1, temp2);
temp1 = temp1 / temp3;
temp2 = temp2 / temp3;
sumScore = String.valueOf(temp1) + '/' + String.valueOf(temp2);
sumStr = (String.valueOf(temp4) + '/' + String.valueOf(temp5)) + strz
+ (String.valueOf(temp7) + '/' + String.valueOf(temp8));
t = 1;
return sumStr;
}


7.结对照片

## PSP展示##

PSP2.1 Personal Software Process Stages Time (%) Senior Student(/hour) Time (%)(/hour)
· Planning 计划 2 2.5
· Estimate 估计这个任务需要多少时间 0.5 0.5
· Analysis 需求分析 (包括学习新技术) 1 1
· Coding Standard 代码规范 0.5 0.5
· Design 具体设计 1.5 2
· Coding 具体编码 20 24
· Test 测试（自我测试，修改代码，提交修改） 1 1
Reporting 报告 1 1

## 小结##

PS:问在隔了一周之后再看之前的代码，是否更能体会到下面这些东西?

(1) 良好的设计
(2) 编码规范
(3) 必要的注释

posted @ 2017-03-29 00:27  丹hjk  阅读(173)  评论(4编辑  收藏  举报