软件测试赛特殊样题

 题目1:

根据输入执行下列不同的三角函数的计算并显示计算结果。编写程序,并设计最少的测试数据进行判定覆盖测试。其中变量x,k为整数。输入数据打印出“输入x值:”、“输入k值:”。执行算式一输出文字“算式一值:”和y的值,执行 输出文字“算式二值:”和y的值;执行输出文字“算式三值:”和y的值。若不在有效范围之内,应提示:“输入不符合要求。

被测试代码:

public class TM15 {
	public String tm15(int x ,int k) {
		if (x > 0 && x <= 30) {
			return "算式一值:" + Math.sin(Math.pow(x, k));
		}else if (x > 30 && x <= 60) {
			return "算式二值:" + Math.cos(Math.pow(x, 1/k));
		}else if (x > 60) {
			return "算式三值:" + Math.tan(x/k);
		}else {
			return "输入不符合要求";
		}
	}
}

测试代码:

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.startsWith;

import org.junit.Test;

public class TM15Test {
	private TM15 tm15 = new TM15();
	
	@Test
	public void test01() {
		assertThat(tm15.tm15(1, 1),startsWith("算式一值:0.84"));
	}
	@Test
	public void test02() {
		assertThat(tm15.tm15(40, 1),startsWith("算式二值:-0.66"));
	}
	@Test
	public void test03() {
		assertThat(tm15.tm15(70, 1),startsWith("算式三值:1.22"));
	}
	@Test
	public void test04() {
		assertThat(tm15.tm15(-1, -1),startsWith("输入不符合要求"));
	}

}

 题目2:

下列流程图中变量a、b、c、d均为非负整数,编写程序实现相应分析处理,并设计最少的测试数据进行判定条件覆盖测试,要求a、b、c、d取最小可能值。

被测试代码:

public class TM16 {
	public double tm16(int a,int b,int c,int d) {
		double Y;
		if (a >12 && b <12) {
			if (c >4 || d <20) {
				Y = 3 *a + 10*b +5*d -c ;
			}else {
				Y = 10 * d -(a +b)*c/5;
			}
		}else {
			Y = Math.pow(a, b) + Math.pow(c, d);
		}
		return Y;
	}
}

测试代码:

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;

import org.junit.Test;

public class TM16Test {
	private TM16 tm16 = new TM16();
	
	@Test
	public void test01() {
		assertThat(tm16.tm16(1, 14, 1, 1), equalTo(2.0));
	}
	@Test
	public void test02() {
		assertThat(tm16.tm16(13, 1, 5, 1), equalTo(49.0));
	}
	@Test
	public void test03() {
		assertThat(tm16.tm16(13, 1, 1, 21), equalTo(208.0));
	}

}

  题目3:

根据下列流程图编写程序实现相应分析处理,并设计测试数据进行判定覆盖测试。其中变量 a、b 均须为整型。

被测试代码:

public class TM17 {
	public double tm17(int a,int b,int k) {
		double x;
		if (a >5 && b >10) {
			x = k*Math.pow(a, 2)*b;
		}else if (b == 0&& a >0) {
			x = Math.sqrt(a + k);
		}else {
			x = Math.pow((a + b + k), 5);
		}
		return x;
	}
}

测试代码:

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;

import org.junit.Test;

public class TM17Test {
	private TM17 tm17 = new TM17();
	
	@Test
	public void test01() {
		assertThat(tm17.tm17(6, 11, 1), equalTo(396.0));
	}
	
	@Test
	public void test02() {
		assertThat(tm17.tm17(3, 0, 1), equalTo(2.0));
	}
	
	@Test
	public void test03() {
		assertThat(tm17.tm17(6, 1, 1), equalTo(32768.0));
	}

}

  题目4:

根据流程图编写程序实现相应分析处理,并设计测试数据进行语句覆盖测试。要求变量 a、b 均为非 0 的整数,且为正整数时取值尽可能小,为负整数时取值尽可能大。

被测试代码:

public class TM18 {
	public double tm18(int a,int b,int k) {
		double c;
		if (a >0 && b > 0) {
			c = Math.sin(a + b *k);
		}else if (a < 0 && b <0) {
			c = Math.pow(a*b, k);
		}else {
			c = Math.pow(a-b, 2);
		}
		return c;
	}
}

测试代码:

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;

import org.junit.Test;

public class TM18Test {
	private TM18 tm18 = new TM18();
	
	@Test
	public void test01() {
		assertThat(tm18.tm18(1, 1, -1), equalTo(0.0));
	}
	
	@Test
	public void test02() {
		assertThat(tm18.tm18(-1, -1, 1), equalTo(1.0));
	}
	
	@Test
	public void test03() {
		assertThat(tm18.tm18(-1, 1, 1), equalTo(4.0));
	}
}

  题目5:

根据下列流程图编写程序实现相应分析处理,并设计测试数据进行判 定覆盖测试。输入数据打印出“输入 a 值:”、“输入 b 值:”。x 执行结果输 出文字“x 的值:”和 x 的值,y 执行结果输出文字“y 的值:”和 y 的值;z 执行 结果输出文字“z 的值:”和 z 的值。其中变量 a、b 均须为整型。

被测试代码:

public class TM19 {
	public double tm19(int a ,int b) {
		double x;
		if (a >5 && b >10) {
			x = Math.pow(a, 2)*b;
		}else if (b ==0 && a >0) {
			x = Math.sqrt(a);
		}else {
			x = Math.pow(a+b, 5);
		}
		return x;
	}
}

测试代码:

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;

import org.junit.Test;

public class TM19Test {
	private TM19 tm19 = new TM19();

	@Test
	public void test01() {
		assertThat(tm19.tm19(6, 20), equalTo(720.0));
	}
	@Test
	public void test02() {
		assertThat(tm19.tm19(9, 0), equalTo(3.0));
	}
	@Test
	public void test03() {
		assertThat(tm19.tm19(6, 1), equalTo(16807.0));
	}

}

  题目6:

根据流程图编写程序实现相应分析处理,并设计测试数据

进行语句覆盖测试。要求变量 a、b 均为非 0 的整数,且为正整数时

取值尽可能小,为负整数时取值尽可能大。

被测试代码:

public class TM20 {
	public double tm20(int a,int b,int k) {
		double c;
		if (a >0 && b >0) {
			c = Math.sin(a+b*k);
		}else if(a <0 && b<0){
			c = Math.pow(a * b, k);
		}else {
			c = Math.pow(a-b, 2);
		}
		return c;
	}
}

测试代码:

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;

import org.junit.Test;

public class TM20Test {
	private TM20 tm20 = new TM20();
	
	@Test
	public void test01() {
		assertThat(tm20.tm20(1, 1, -1), equalTo(0.0));
	}
	@Test
	public void test02() {
		assertThat(tm20.tm20(-1, -1, 1), equalTo(1.0));
	}
	@Test
	public void test03() {
		assertThat(tm20.tm20(1, -1, -1), equalTo(4.0));
	}

}
  • 10
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值