黑盒测试——移民评估案例

public class migrate {

	
	public int migrate(int age,String ability,String language,int investment) {
		int sum = 0;
		
		if (age>=18 && age <= 39) {
			sum += 30;
		}else if (age >= 40 && age <= 59) {
			sum += 20;
		}else if (age >= 60 && age <= 99) {
			sum += 10;
		}
		
		if (ability.equals("高")) {
			sum += 50;
		}else if (ability.equals("低")) {
			sum += 30;
		}
		
		if (language.equals("优秀")) {
			sum += 30;
		}else if (language.equals("普通")) {
			sum += 20;
		}
		
		if (investment >= 0 && investment <= 99) {
			if (investment < 10) {
				sum += 0;
			}else {
				int plus = investment / 10;
				if (plus <= 6) {
					sum += plus*10;
				}else {
					sum += 60;
				}
			}
		}
		
		return sum;
	}

}
import static org.junit.Assert.*;

import org.junit.Test;

public class migrateTest {

	migrate m = new migrate();
	
	@Test
	public void test1() {
		assertEquals(100, m.migrate(27, "高", "普通", 0));
	}
	@Test
	public void test2() {
		assertEquals(140, m.migrate(27, "高", "优秀", 30));
	}
	@Test
	public void test3() {
		assertEquals(150, m.migrate(50, "高", "普通", 99));
	}
	@Test
	public void test4() {
		assertEquals(90, m.migrate(70, "低", "普通", 30));
	}
	@Test
	public void test5() {
		assertEquals(60, m.migrate(70, "低", "普通", 0));
	}
	@Test
	public void test6() {
		assertEquals(110, m.migrate(50, "低", "优秀", 30));
	}

}

你可能感兴趣的:(java,java,单元测试)