20165111 实行二 Java面向工具顺序设计

明胜亚洲科技  公布工夫:2018-04-16 03:37:02

本文要害词:java面向工具编程标题

java面向工具编程标题_java面向工具经典标题_java面向工具编程pdf

java面向工具编程标题

20165111 实行二 Java面向工具顺序设计

MyUtil.java

public class MyUtil {
    public static String percentage2fivegrade(int grade){
        if(grade<0 || grade>100)
            return "错误";
        else if(grade<60)
            return "不合格";
        else if(grade<70)
            return "合格";
        else if (grade<80)
            return "中等";
        else if (grade<90)
            return "精良";
        else
            return "良好";
    }
}

MyUtilTest.java

import org.junit.Test;
import junit.framework.TestCase;

public class MyUtilTest extends TestCase {
    @Test
    public void testNormal(){//用于测试正常状况
        assertEquals("不合格", MyUtil.percentage2fivegrade(55));
        assertEquals("合格", MyUtil.percentage2fivegrade(65));
        assertEquals("中等", MyUtil.percentage2fivegrade(75));
        assertEquals("精良", MyUtil.percentage2fivegrade(85));
        assertEquals("良好", MyUtil.percentage2fivegrade(95));
    }
    @Test
    public void testException(){//用于测试非常状况
        assertEquals("错误",MyUtil.percentage2fivegrade(-1));
        assertEquals("错误",MyUtil.percentage2fivegrade(101));
    }
    @Test
    public void testBoundary(){//用于测试界限状况
        assertEquals("不合格",MyUtil.percentage2fivegrade(0));
        assertEquals("不合格",MyUtil.percentage2fivegrade(59));
        assertEquals("合格",MyUtil.percentage2fivegrade(60));
        assertEquals("合格",MyUtil.percentage2fivegrade(69));
        assertEquals("中等",MyUtil.percentage2fivegrade(70));
        assertEquals("中等",MyUtil.percentage2fivegrade(79));
        assertEquals("精良",MyUtil.percentage2fivegrade(80));
        assertEquals("精良",MyUtil.percentage2fivegrade(89));
        assertEquals("良好",MyUtil.percentage2fivegrade(90));
        assertEquals("良好",MyUtil.percentage2fivegrade(100));
    }
}

本文来自互联网,由呆板人主动采编,文章内容不代表本站观念,请读者自行区分信息真伪,若有发明不适内容,请实时联络站优点理。

相干阅读