其他分享
首页 > 其他分享> > 2018-2019-2 20175207 实验三《敏捷开发与XP实践》实验报告

2018-2019-2 20175207 实验三《敏捷开发与XP实践》实验报告

作者:互联网

代码规范

Git中添加添加仓库成员及测试代码

要求:在码云上把自己的学习搭档加入自己的项目中,确认搭档的项目加入自己后,下载搭档实验二的Complex代码,加入不少于三个JUnit单元测试用例,测试成功后git add .; git commit -m "自己学号 添加内容";git push;提交搭档项目git log的截图,包含上面git commit的信息,并加上自己的学号水印信息。

public class Complex {
    int RealPart;
    int ImagePart;
    public Complex(){}
    public Complex(int R,int I){
        RealPart = R;
        ImagePart = I;
    }
    public int getRealPart(){
        return RealPart;
    }
    public int getImagePart(){
        return ImagePart;
    }
    public String toString(){
        String s = new String();
        if(ImagePart>0)
            s = getRealPart()+"+"+getImagePart()+"i";
        if(ImagePart==0)
            s = getRealPart()+"";
        if(ImagePart<0)
            s = getRealPart()+""+getImagePart()+"i";
        if(RealPart==0)
            s = getImagePart()+"i";
        if(ImagePart==0&&RealPart==0)
            s = "0";
        return s;
    }
    public Complex ComplexAdd(Complex a){
        Complex d = new Complex();
        d.RealPart = RealPart + a.RealPart;
        d.ImagePart = ImagePart + a.ImagePart;
        return d;
    }
    public Complex ComplexSub(Complex a){
        Complex d = new Complex();
        d.RealPart = RealPart - a.RealPart;
        d.ImagePart = ImagePart - a.ImagePart;
        return d;
    }
    public Complex ComplexMulti(Complex a){
        Complex d = new Complex();
        d.RealPart = RealPart*a.RealPart - ImagePart*a.ImagePart;
        d.ImagePart = RealPart*a.ImagePart + ImagePart*a.RealPart;
        return d;
    }
    public Complex ComplexDiv(Complex a) {
        Complex d = new Complex();
        d.RealPart = (RealPart * a.RealPart + ImagePart * a.ImagePart) / (a.RealPart * a.RealPart + a.ImagePart * a.ImagePart);
        d.ImagePart = (ImagePart * a.RealPart - RealPart * a.ImagePart) / (a.RealPart * a.RealPart + a.ImagePart * a.ImagePart);
        return d;
    }
}
import junit.framework.TestCase;

public class ComplexTest extends TestCase {

    Complex a = new Complex(7, 9);
    Complex b = new Complex(-2, -3);
    public void testEquals() {
        assertEquals(true, a.equals(a));
        assertEquals(false, b.equals(a));
    }
    public void testToString() {
        assertEquals("7+9i", a.toString());
        assertEquals("-2-3i", b.toString());
    }
    public void testComplexAdd() {
        assertEquals("5+6i",a.ComplexAdd(b).toString());
        assertEquals("-4-6i",b.ComplexAdd(b).toString());
    }
    public void testComplexSub() {
        assertEquals("9+12i",a.ComplexSub(b).toString());
        assertEquals("0",b.ComplexSub(b).toString());
    }
    public void testComplexMulti() {
        assertEquals("-32+126i",a.ComplexMulti(a).toString());
        assertEquals("13-39i",a.ComplexMulti(b).toString());
    }
    public void testComplexDiv() {
        assertEquals("1",a.ComplexDiv(a).toString());
    }
}


- 推送结果

Git中添加添加仓库成员及测试代码

重构练习

要求:完成重构内容的练习,下载搭档的代码,至少进行三项重构,提交重构后代码的截图,加上自己的学号水印。提交搭档的码云项目链接。

码云链接

标签:搭档,buffer,assertEquals,Move,toString,2018,20175207,2019,public
来源: https://www.cnblogs.com/ln-0407/p/10789634.html