zoukankan      html  css  js  c++  java
  • 程序测试学习之5.2作业

    public class test {
        private int a;
        private int b;
        int c;
        public int  add(int a,int b)
        {
        
            System.out.println(""+a);
            System.out.println(""+b);
            c = a+b;
            System.out.println("a+b="+(a+b)+"
    ");
            return c;
            
        }
        public int  jian(int a,int b)
        {
            
            System.out.println(""+a);
            System.out.println(""+b);
            c=a-b;
            System.out.println("a-b="+(a-b)+"
    ");
            return c;
            
            
        }
        public int Cheng(int a,int b)
        {   
            System.out.println(""+a);
            System.out.println(""+b);
            c=a*b;
            System.out.println("a*b="+(a*b)+"
    ");
            return c;
        }
        public double  Chu(int a,int b)
        {
            double c;
            c=(double) (Math.round((a/b)*100/100.0));
            System.out.println(""+a);
            System.out.println(""+b);
            if(b!=0)
                System.out.println("c=a/b="+(c)+"
    ");
            else
                throw new ArithmeticException();
                System.out.println("分母不能为0!");
                  
                return c;
        }
    
        /**
         * @param args
         */
        public static void main(String[] args) {
             Test Jia=new Test();
             Jia.jia(1, 1);
             Test Jian=new Test();
             Jian.jian(2,1);
             Test cheng=new Test();
             cheng.Cheng(2,3);
             Test chu=new Test();
             chu.Chu(3,0);
             
        }
    这个是上一次作业的基础
    这次加入test类进行测试:

    test.java 的代码清单:

    import static org.junit.Assert.*;
    
    import org.junit.Test;
    
    
    public class FZTest {
    
    int z;
    @Test
    public void testJia() {
    FZ fz = new FZ();
    z = fz.jia(1, 1);
    assertEquals(2,z);
    }
    @Test(expected=ArithmeticException.class) //抛出异常,当分母为0时
    public void testchu() {
    double b;
    FZ fz = new FZ();
    b = fz.Chu(2, 1);
    
    }
    @Test
    public void testjian() {
    
    FZ fz = new FZ();
    z = fz.jian(2, 3);
    assertEquals(6,z);
    
    }
    @Test
    public void testCheng() {
    
    FZ fz = new FZ();
    z = fz.Cheng(3, 0);
    assertEquals(0,z);
    }
    }
  • 相关阅读:
    CSS清除浮动的方法
    JS获取元素属性、样式getComputedStyle()和currentStyle方法兼容性问题
    数据类型真假的问题
    数据类型——方法总结(可能有不对的)
    attr()与setAttribute()的区别
    wampserver 2.5多站点配置
    php常用函数(持续中)
    php中环境变量
    编码转换
    php中rsa加密及解密和签名及验签
  • 原文地址:https://www.cnblogs.com/Oliver-zzc/p/4488629.html
Copyright © 2011-2022 走看看