Lab 1: Write a java program for the triangle problem and test the program with Junit.

Tasks:

  1. Install Junit(4.12), Hamcrest(1.3) with Eclipse

将两个jar包添加到工程中

  2. Install Eclemma with Eclipse

  3. Write a java program for the triangle problem and test the program with Junit.

[Description of triangle problem]Function triangle takes three integers a,b,c which are length of triangle sides; calculates whether the triangle is equilateral, isosceles, or scalene.

  运行截图如下:

  代码如下:

package TestTriangle;

public class triangles {

    public static String triangleshape(int a,int b, int c){

        if(a == b && a == c && b == c){
            return "equilateral";
        }
        else if(a == b || a == c || b == c){
            return "isosceles";
        }
        else{
            return "scalene";
        }

        }

}
package TestTriangle;

import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.Collection;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class testTriangles {

    private int a;
    private int b;
    private int c;
    private String expected;
    private String result = null;

    public testTriangles(int a,int b, int c, String expected){
        this.a = a;
        this.b = b;
        this.c = c;
        this.expected= expected;

        }

    @Parameters
    public static Collection<Object[]> getData(){
    return Arrays.asList(new Object[][]{
    {1,1,1,"equilateral"},
    {2,3,4,"scalene"},
    {3,5,5,"isosceles"},
    {6,6,8,"isosceles"}
    });
    }

    @Test
    public void test() {
    assertEquals(this.expected,triangles.triangleshape(a,b,c));
    }

}
时间: 2024-12-26 19:15:47

Lab 1: Write a java program for the triangle problem and test the program with Junit.的相关文章

java virtual machine launcher Error:Could not create the Java Virtual Machine. Error:A Fatal exception has occurred,Program will exit.

Error:Could not create the Java Virtual Machine. Error:A Fatal exception has occurred,Program will exit. 出现以上错误信息提示,如下图所示: 然后点击确定弹出以下错误信息 解决办法: 1.判断机子是否安装了Java环境.具体方法网上搜吧,这里还是给小白一个传送门:(设置) 注意设置自己的环境变量:如JAVA_HOME,CLASSPATH,PATH 2.有些程序会有内存设置,有些程序内存设置过大

Kafka中错误:Unrecognized VM option ‘UseCompressedOops’ Error: Clould not create the Java Vritual Machine. Error: A fatal exception has occurres . Program will exit.

错误的描述: 在kafka安装目录下,执行 $ bin/zookeeper-server-start.sh config/zookeeper.properties & Unrecognized VM option ‘UseCompressedOops’ Error: Clould not create the Java Vritual Machine. Error: A fatal exception has occurres . Program will exit. 解决方法: 找到bin/k

JAVA HDU 1048 The Hardest Problem Ever

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1048 1 package hdu; 2 3 import java.io.BufferedInputStream; 4 import java.util.Scanner; 5 6 public class hdu_1048 { 7 8 public static void main(String[] args) { 9 Scanner in = new Scanner(new BufferedInp

安装wampserver出现“The Program can&#39;t start because MSVCR110.dll is missing from your computer. Try reinstalling the program to fix this problem”

问题描述: 今天安装wampserver的时候出现"The Program can't start because MSVCR110.dll is missing from your computer. Try reinstalling the program to fix this problem"弹窗报错,以至于无法启动wampserver 安装条件:Win7 系统, 64 位, 安装软件: WAMPSERVER 64 BITS (X64) 3.0.6 原因分析: MSVCR110

Java反射学习总结终(使用反射和注解模拟JUnit单元测试框架)

本文是Java反射学习总结系列的最后一篇了,这里贴出之前文章的链接,有兴趣的可以打开看看. http://blog.csdn.net/a396901990/article/category/2302221 本文介绍了如何利用反射和注解去简单的模拟JUnit4单元测试框架,之所以选择JUnit4是因为4.0以后最大的改进就是使用了注解.需要注意的是这里并不是完全的模拟,只是简单实现了一下Runner类和JUnit注解相关的工作流程.所以本文的主要目的是介绍反射和注解的使用.废话不多说,直接进入正文

Atitit. &#160;Exception in thread &quot;main&quot; java.lang.Error: Unresolved compilation problem:

Atitit.  Exception in thread "main" java.lang.Error: Unresolved compilation problem: 1.1. 产看是否产生class文件,以及class体积大小1 1.2. 观察ide源文件,左边有个红叉叉.1 1.3. Resin等服务器锁定了原class文件,导致新生成的class无法替换..1 1.1. 产看是否产生class文件,以及class体积大小 也生成class文件了.但是包这个错..不过大小只有1k

菜鸟学Java(二十一)——如何更好的进行单元测试——JUnit

测试在软件声明周期中的重要性,不用我多说想必大家也都非常清楚.软件测试有很多分类,从测试的方法上可分为:黑盒测试.白盒测试.静态测试.动态测试等:从软件开发的过程分为:单元测试.集成测试.确认测试.验收.回归等. 在众多的分类中,与开发人员关系最紧密的莫过于单元测试了.像其他种类的测试基本上都是由专门的测试人员来完成,只有单元测试是完全由开发人员来完成的.那么今天我们就来说说什么是单元测试,为什么要进行单元测试,以及如更好的何进行单元测试. 什么是单元测试? 单元测试(unit testing)

启动eclipse时候提示错误Error:Could not create the Java Virtual Machine. Error:A Fatal exception has occurred,Program will exit.

我的是neon3版本 解决办法是: 首先把这两个选项勾选,才能看到eclipse.ini完整的文件名.然后用记事本等工具打开编辑. 新版的里面原本是这样: -startup plugins/org.eclipse.equinox.launcher_1.3.201.v20161025-1711.jar --launcher.library C:/Users/scc/.p2/pool/plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.

Software Testing Report,Triangle Problem, Lab 1, May 5th . 2016

首先要在eclipse里安装junit, hamcrest 和 eclemma 插件,可以在http://junit.org/junit4/ 上找到插件的下载,国内网估计下不了需要FQ,我就用的myeclipse,里面直接自带.http://www.myeclipsecn.com/ 这是myeclipse的官网链接. 然后就是开始编程序和测试程序具体的Java在github上,链接:https://github.com/DongArvin/Triangle-Test1 最后的测试结果是绿了.但没