`

测试_20120818

    博客分类:
  • java
阅读更多
Calculater.java

package com.xjh.study;

public class Calculater {
	
	public double add(double a, double b) {
		return a + b;
	}
	
	public double sub(double a, double b) {
		return a - b;
	}
	
	public double mul(double a, double b) {
		return a * b;
	}
	
	public double div(double a, double b) {
		return a / b;
	}

}



TestCalculater.java

package com.xjh.study;

import junit.framework.TestCase;

public class TestCalculater extends TestCase {

	Calculater calculater;

	public void setUp() {
		calculater = new Calculater();
	}

	public void testAdd() {
		double result = calculater.add(100, 200);
		this.assertEquals(300, result, 0);
	}
	
	public void testSub() {
		double result = calculater.sub(200, 100);
		this.assertEquals(100, result, 0);
	}
	
	public void testMul() {
		double result = calculater.mul(10, 20);
		this.assertEquals(200, result, 0);
	}
	
	public void testDiv() {
		double result = calculater.div(100, 10);
		this.assertEquals(10, result, 0);
		result = calculater.div(100, 0);
		this.assertEquals(Double.POSITIVE_INFINITY, result, 0);
	}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics