软件测试作业三 尝试使用JUnit

写一个判断三角形种类的代码,对其进行测试。

判断三角形代码:

package 测试1;

public class sjx {
    public String f(int a,int b,int c)
    {
        if(a<=0||b<=0||c<=0||a+b<=c||a+c<=b||b+c<=a) return "不是三角形";
        if(a == b&&b == c) return "等边三角形";
        else if(a == b||b == c) return "等腰三角形";
        else return "一般三角形";
    }
}

测试代码:

package 测试1;

import org.junit.*;

public class sjxTest {
    sjx s;
    @Before
    public void SetUp()
    {
        s = new sjx();
    }

    @Test
    public void tests()
    {
        Assert.assertEquals("不能判断是否为三角形","不是三角形",s.f(1,1,2));
        Assert.assertEquals("不能判断是否为等边三角形","等边三角形",s.f(1,1,1));
        Assert.assertEquals("不能判断是否为等腰三角形","等腰三角形",s.f(2,2,3));
        Assert.assertEquals("不能判断是否为一般三角形","一般三角形",s.f(3,4,6));
    }

}

运行结果:

时间: 2024-08-26 09:10:07

软件测试作业三 尝试使用JUnit的相关文章

软件测试(三)——使用Junit测试三角形问题

一.Junit, hamcrest 和 eclemma 的安装    1. Junit和hamcrest的安装和使用 (1)下载junit.jar和hamcrest.jar; (2)通过右键项目---Properties---Java Build Path---Libraries---Add External JARS,选择对应的Junit和hamcrest的包,将其导入项目中,如下: 2.Eclemma的安装和使用 (1)选择Help---Eclipse Marketplace, 搜索Ecle

软件测试作业三-printPrimes()

作业内容: private static void printPrimes(int n) { int curPrime; int numPrimes; boolean isPrime; int MAXPRIMES=50; int [] primes = new int [MAXPRIMES]; primes [0] = 2; numPrimes = 1; curPrime = 2; while (numPrimes < n) { curPrime++; isPrime = true; for (

软件测试作业——三

作业见<软件测试基础>中文版49页第7题.英文版63页 a) b) 令MAXPRIMES = 4,t1不能检查出错误,t2发生数组越界,使得t2比t1更容易发现. c)t3=(n=1) d)节点覆盖:TR={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16} 边覆盖:TR={(1,2),(2,3),(2,12),(3,4),(4,5),(5,6),(6,8),(8,5),(6,7),(7,9), (5,9),(9,10),(10,11),(9,11),(12,13)

软件测试作业三

作业内容: Use the following method printPrimes() for questions a–f below. 代码如下: 1. /** ***************************************************** 2. * Finds and prints n prime integers 3. * Jeff Offutt, Spring 2003 4. *****************************************

Software Testing (软件测试作业三) HW3 prin

The source code: 源代码: /******************************************************* * Finds and prints n prime integers * Jeff Offutt, Spring 2003 ******************************************************/ public static void printPrimes (int n) { int curPrim

软件测试 作业三 《软件测试基础》2.3节第7题

Use the following method printPrimes() for questions a–d. 原书:<Introduction to Software Testing>BY Paul Ammann and Jeff Offutt 题目为书中2.3小节第7题. 题目代码如下: /** ***************************************************** * Finds and prints n prime integers * Jeff

软件测试作业——Junit使用

软件测试作业--Junit使用 [TOC] 题目要求 Install Junit(4.12),Hamcrest(1.3) with Eclipse Install Eclemma with Eclipse Write a javaprogram for the triangle problem and test the program with Junit. Description oftriangle problem:Functiontriangle takes three integers

機器學習基石(Machine Learning Foundations) 机器学习基石 作业三 Q18-20 C++实现

大家好,我是Mac Jiang,今天和大家分享Coursera-NTU-機器學習基石(Machine Learning Foundations)-作业三 Q18-20的C++实现.虽然有很多大神已经在很多博客中给出了Phython的实现,但是给出C++实现的文章明显较少,这里为大家提供一条C++实现的思路!我的代码虽然能够得到正确答案,但是其中可能有某些思想或者细节是错误的,如果各位博友发现,请及时留言纠正,谢谢!再次声明,博主提供实现代码的原因不是为了让各位通过测试,而是为学习有困难的同学提供

機器學習基石(Machine Learning Foundations) 机器学习基石 作业三 Q13-15 C++实现

大家好,我是Mac Jiang,今天和大家分享Coursera-NTU-機器學習基石(Machine Learning Foundations)-作业三 Q6-10的C++实现.虽然有很多大神已经在很多博客中给出了Phython的实现,但是给出C++实现的文章明显较少,这里为大家提供一条C++实现的思路!我的代码虽然能够得到正确答案,但是其中可能有某些思想或者细节是错误的,如果各位博友发现,请及时留言纠正,谢谢!再次声明,博主提供实现代码的原因不是为了让各位通过测试,而是为学习有困难的同学提供一