zoukankan      html  css  js  c++  java
  • 软件测试上机作业_junit使用

    先推荐两个不错的博客链接,如何使用junit

    http://blog.csdn.net/andycpp/article/details/1327147

    如果碰到一些困难,那么就看这个解决方法


    http://blog.csdn.net/andycpp/article/details/1327147

    测试三条边是否是可以组成三角形,三角形类型

    public class Main {
        private static int result; // 静态变量,用于存储运行结果
        public static int ERRTRIANGLE = 0;
        public static int ValidTRIANGLE = 1;
        public static int Equilateral = 1;
        public static int Isosceles = 2;
        public static int Scalene = 3;
    
        public void clear() {     // 将结果清零
            result = 0;
        }
        public int getResult() {
            return result;
        }
        public void validTrangle(int a,int b,int c){
            
            if(b + c - a > 0 && b > 0 && a > 0 && c > 0)result = ValidTRIANGLE;
            else if(b + a - c > 0 && b > 0 && a > 0 && c > 0)result = ValidTRIANGLE;
            else if(c + a - b > 0 && b > 0 && a > 0 && c > 0)result = ValidTRIANGLE;
            else result = ERRTRIANGLE;
        }
        public void triangleType(int a,int b,int c){
            if(a == b && b == c)result = Equilateral;
            else if(a == b || b == c || a == c)result = Isosceles;
            else result = Scalene;
        }
    }
    import static org.junit.Assert.*;
    
    import org.junit.Before;
    import org.junit.Test;
    
    
    import static org.junit.Assert.*;
    import org.junit.Before;
    import org.junit.Ignore;
    import org.junit.Test;
    
    public class MainTest {
    
        private static Main calculator = new Main();
        
        @Before
        public void setUp() throws Exception {
            calculator.clear();
        }
    
        @Test
        public void testTriangleType() {
            calculator.clear();
            
            calculator.triangleType(10, 10, 10);
            assertTrue(calculator.getResult() == calculator.Equilateral);
            calculator.triangleType(10, 11, 10);
            assertTrue(calculator.getResult() == calculator.Isosceles);
            calculator.triangleType(10, 11, 12);
            assertTrue(calculator.getResult() == calculator.Scalene);  
        }
        
        
        @Test
        public void testValidTrangle() {
            calculator.clear();
            
            calculator.validTrangle(1, 11, 0);
            assertTrue(calculator.getResult() == calculator.ERRTRIANGLE);
            
            calculator.validTrangle(10, 11, 12);
            assertTrue(calculator.getResult() == calculator.ValidTRIANGLE);
        }
    }
  • 相关阅读:
    对象的引用
    查询各个商品分类中各有多少商品的SQL语句
    将TP引擎改为smarty引擎
    图片预加载
    js中接口的声明与实现
    判断对象是否是某个类的实例
    判断变量是否为json对象
    Python 爬取淘宝商品数据挖掘分析实战
    Python 爬取淘宝商品数据挖掘分析实战
    扫盲丨关于区块链你需要了解的所有概念
  • 原文地址:https://www.cnblogs.com/c337134154/p/5291548.html
Copyright © 2011-2022 走看看