四则运算——计应193第四组梁静怡
1、计划
实现加减乘除运算
2、需求分析
3、生成设计文档
创建一个java类,包含四个运算方法,创建加减乘除测试类进行单元测试。
4、设计复审
需用Junit4进行单元测试
5、代码规范
类名和方法名要做到见名知意
6、具体设计
需要建一个Math类里面有add、 substract、multiply、divide等,在单元测试里面分别对应进行测试,运行结果和预想的一样
7、具体编码
package cn.edu.hnzj.lesson2;
public class Math {
public int add(int a,int b)//加法
{
return a+b;
}
public int substract(int a,int b)//减法
{
return a-b;
}
public int multiply(int a,int b)//乘法
{
return a*b;
}
public double divide(double a,double b)//除法
{
return a/b;
}
}
package cn.edu.hnzj.lesson2;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
public class MathText {
private static Math mm=new Math();
@Test
public void testAdd() {
int result= mm.add(1,3);
assertEquals(4,result);
}
@Test
public void testSubstract() {
int result= mm.substract(56,48);
assertEquals(8,result);
}
@Test
public void testMultiply() {
int result= mm.multiply(5,5);
assertEquals(25,result);
}
@Test
public void testDivide() {
int result= (int) mm.divide(125.0,25.0);
assertEquals(5,result);
}
}
8、代码复审
小组人员代码复审
9、测试报告
在单元测试中,如果assertequals()方法第一个参数与运算结果不同,则报错。
10、事后总结
在写程序的过程中也是一次的改错的过程
11、提出过程改进计划
学会优化代码,不要写的非常繁杂
|
PSP阶段 |
够了额(梁静怡)所花时间 |
工程师所花时间 |
|
计划 |
10 |
6 |
|
10 |
6 |
|
开发 |
84 |
88 |
|
10 |
10 |
|
5 |
6 |
|
5 |
6 |
|
3 |
3 |
|
13 |
12 |
|
30 |
21 |
|
6 |
9 |
|
12 |
21 |
|
报告 |
8 |
6 |
|
3 |
2 |
|
2 |
1 |
|
3 |
3 |
|
总共花费的时间(分钟) |
102 |
100 |
浙公网安备 33010602011771号