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);
        }
    }
  • 相关阅读:
    Python3学习笔记27-ConfigParser模块
    Python3学习笔记26-unittest模块
    HTML学习笔记09-列表
    HTML学习笔记08-表格
    [hdu1402]A * B Problem Plus(FFT模板题)
    [bzoj2179]FFT快速傅立叶
    [bzoj3884]上帝与集合的正确用法
    [ural1132]Square Root(cipolla算法)
    MD5算法的c++实现
    DES算法的c++实现
  • 原文地址:https://www.cnblogs.com/c337134154/p/5291548.html
Copyright © 2011-2022 走看看