码迷,mamicode.com
首页 > 编程语言 > 详细

用Java进行简单的乘除计算

时间:2015-04-29 21:24:20      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

用Java进行简单的乘除计算

 

一、题目简介

一个两个数简单的乘除计算的Java代码并验证是否其正确性。

 

二、源码的github链接

https://github.com/Battleblocke/Math

代码如下:

1.

public class Math

{
  public static int divide(int x,int y)

  {
        return x/y;
  }

  public static int multiple(int x,int y) {
    return x*y;
  }
}

2.

import static org.junit.Assert.*;

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

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
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 MathTest

  {
  int faciend;
  int multiplicator;
  int result;

  public MathTest(int faciend, int multiplicator, int result) {
  this.faciend = faciend;
  this.multiplicator = multiplicator;
  this.result = result;
  }

@BeforeClass
public static void setUpBeforeClass() throws Exception

  {
  }

@AfterClass
public static void tearDownAfterClass() throws Exception {
  }

@Test(expected=ArithmeticException.class)
public void testDivide() {
assertEquals(3,Math.divide(9,3));
assertEquals(3,Math.divide(10,3));
Math.divide(10,0);//除数不能为0,会抛出异常

  }

//@Ignore("忽略乘法测试")
@Test
public void testMultiple() {
assertEquals(result,Math.multiple(faciend,multiplicator));
  }

@Parameters
public static Collection multipleValues() {
return Arrays.asList(new Object[][] {
{3, 2, 6 },
{4, 3, 12 },
{21, 5, 105 },
{11, 22, 242 },
{8, 9, 72 }});
}

}

三、所设计的模块测试用例、测试结果截图

 技术分享技术分享

 

四、问题及解决方案、心得体会

  本次实验学习了Github的基本使用方法以及项目的简单建立。

  学习中遇到了不少困难,也学习了不少有用的知识,受益匪浅。。

 

用Java进行简单的乘除计算

标签:

原文地址:http://www.cnblogs.com/battleblock/p/4461631.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!