IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 游戏开发 -> 慕测平台ISTC 2022 Practice -> 正文阅读

[游戏开发]慕测平台ISTC 2022 Practice

文章摘要

本文主要是分享一下慕测平台ISTC 2022 Practice的答案。

(本人刚刚入门软件测试,主要是参加这个比赛,答案可能不对,仅供参考)

结果展示:

在这里插入图片描述
相对来说,MoreTriangle更简单一些;Calculator涉及到一些控制台输出检测(我只覆盖,没有断言),异常抛出等,而且好像有的代码根本执行不到,比如:

  1. 黄色的FALSEf分支以及红色的返回语句

在这里插入图片描述

  1. 红色部分也是执行不到
    在这里插入图片描述

Calculator测试代码

package net.mooctest;

import static org.junit.Assert.*;

import org.junit.Test;




public class CalculatorTest {
	
	Calculator c= new Calculator();
	
	@Test
	public void testCommand() {
		CommandNotFoundException e =new CommandNotFoundException("c");
		assertEquals("c", e.getCommand());
		
		ExpressionParserException exception= new ExpressionParserException("eee");
		assertEquals("eee", exception.getFaultyExpression());
		
		FunctionNotFoundException ffException =new FunctionNotFoundException("ff");
		assertEquals("ff", ffException.getFunc());
		
		MissingOperandException mm = new MissingOperandException("an", "+");
		assertEquals("+", mm.getOperator());
		
		UnmatchedBracketsException unmatchedBracketsException= new UnmatchedBracketsException("ab", 1);
		assertEquals(1, unmatchedBracketsException.getIndexOfBracket());
		
		VariableNotFoundException vv1 =new VariableNotFoundException("vva");
		assertEquals("vva", vv1.getVar());
		
		VariableNotFoundException vv2 =new VariableNotFoundException("v","vva");
		assertEquals("vva", vv1.getVar());
		
	}
	


	@Test(expected=NullExpressionException.class)
	public void testEvaluate00() throws Throwable {
		Calculator.expParser=new ExpressionParser(2);
		Calculator.evaluate("");

	}
	
	@Test
	public void testEvaluate01() throws Throwable {
		Calculator.expParser=new ExpressionParser(2);
		
//		String ass="(\\s+)?(\\w+)(\\s+)(=)(.*)";
//		
//		System.out.println("正则匹配:");
//		System.out.println(" 3 = 3".matches(ass));
		
		Calculator.evaluate("8");
		Calculator.evaluate(" 8 = 8");
		Calculator.parseCommand("list vars");

	}
	
	@Test(expected=ExpressionParserException.class)
	public void testEvaluate02() throws Throwable {
		Calculator.expParser=new ExpressionParser(2);
		Calculator.evaluate("1+2=3");
//		Calculator.evaluate("1+2/0");
	}
	
	@Test
	public void testEvaluate03() throws Throwable {
		Calculator.expParser=new ExpressionParser(2);
        //Calculator.expParser.numberOfVars=2;
		String exp="8 = 8";
//		String  vn=exp.substring(0, exp.indexOf("=")).trim();
//		String vv="" + Double.parseDouble(exp.substring(exp.indexOf("=") + 1));
//		System.out.println("vn="+vn+"  vv= "+vv);
		Calculator.evaluate(exp);
		Calculator.expParser.addVariable("8", "10");
		Calculator.expParser.addVariable("9", "10");
		
	}
	

	@Test
	public void testParseCommand00() throws Throwable {
		 Calculator.parseCommand("exit");
		 Calculator.parseCommand("help");
		 Calculator.parseCommand("help vars");
		 Calculator.parseCommand("help cmds");
		 Calculator.parseCommand("help funcs");
		 Calculator.parseCommand("list");
		 Calculator.parseCommand("list cmds");
		 //Calculator.parseCommand("list vars");
		 Calculator.parseCommand("list funcs");
	}
	
	@Test(expected=CommandNotFoundException.class)
	public void testParseCommand01() throws Throwable {
		 Calculator.parseCommand("nono");
		 //assertTrue("nono"==Calculator.parseCommand("nono").getCommand());
	}
	
	@Test
	public void testMathParserFactorial() {
		Calculator.expParser = new ExpressionParser(10);
		assertEquals(1, Calculator.expParser.factorial(1),0);
		assertEquals(2, Calculator.expParser.factorial(2),0);
		
		assertEquals(16, Calculator.expParser.solveBinaryOperation(4, "^", 2),0);
		assertEquals(0, Calculator.expParser.solveBinaryOperation(4, "%", 2),0);
		assertEquals(2, Calculator.expParser.solveBinaryOperation(4, "/", 2),0);
		assertEquals(8, Calculator.expParser.solveBinaryOperation(4, "*", 2),0);
		assertEquals(6, Calculator.expParser.solveBinaryOperation(4, "+", 2),0);
		assertEquals(2, Calculator.expParser.solveBinaryOperation(4, "-", 2),0);
		assertEquals(0, Calculator.expParser.solveBinaryOperation(4, "--", 2),0);
		
		
	}
	
	@Test
	public void testMathParserSolveUnaryFunction00() throws Throwable {
//		System.out.println("s");
//		System.out.println(Calculator.expParser.solveUnaryFunction("sin", 30));
		assertEquals(Math.sin(30), Calculator.expParser.solveUnaryFunction("sin", 30),0);
		assertEquals(Math.cos(30), Calculator.expParser.solveUnaryFunction("cos", 30),0);
		assertEquals(Math.tan(30), Calculator.expParser.solveUnaryFunction("tan", 30),0);
		
		assertEquals(1.0/Math.sin(30), Calculator.expParser.solveUnaryFunction("csc", 30),0);
		assertEquals(1.0/Math.cos(30), Calculator.expParser.solveUnaryFunction("sec", 30),0);
		assertEquals(1.0/Math.tan(30), Calculator.expParser.solveUnaryFunction("ctn", 30),0);
		
		assertEquals(Math.toRadians(30), Calculator.expParser.solveUnaryFunction("rad", 30),0);
		assertEquals(Math.toDegrees(30), Calculator.expParser.solveUnaryFunction("deg", 30),0);
		assertEquals(Calculator.expParser.factorial(30), Calculator.expParser.solveUnaryFunction("fct", 30),0);
		
		assertEquals(Math.abs(30), Calculator.expParser.solveUnaryFunction("abs", 30),0);
		assertEquals(Math.exp(30), Calculator.expParser.solveUnaryFunction("exp", 30),0);
		assertEquals(Math.log(30), Calculator.expParser.solveUnaryFunction("log", 30),0);
	}
	
	@Test(expected=FunctionNotFoundException.class)
	public void testMathParserSolveUnaryFunction01() throws Throwable {
		assertEquals(Math.sin(30), Calculator.expParser.solveUnaryFunction("ssin", 30),0);

	}
	
	@Test
	public void testExpParseVariables00() throws Throwable {
		Calculator.expParser=new ExpressionParser(10);
		Calculator.expParser.numberOfVars=1;
		Calculator.expParser.parseVariables("1+3");
		Calculator.expParser.parseVariables("<1+3");
		Calculator.expParser.parseVariables(">1+3<");
		
	}
	
	@Test(expected=VariableNotFoundException.class)
	public void testExpParseVariables01() throws Throwable {
		Calculator.expParser=new ExpressionParser(10);
		Calculator.expParser.numberOfVars=1;
		Calculator.expParser.parseVariables("<11>");
		
	}
	
	
	@Test
	public void testExpParseParenthesis() throws Throwable{
		Calculator.expParser=new ExpressionParser(10);
		Calculator.expParser.parseParenthesis("(1+2)*3=9");
		Calculator.expParser.parseParenthesis("-(1+2)*3=9");
	}
	
	@Test(expected=ExpressionParserException.class)
	public void testExpParseFunctions00() throws Throwable{
		Calculator.expParser=new ExpressionParser(10);
		Calculator.expParser.parseFunctions("[1+2]*3=9");
	}
	
	@Test(expected=FunctionNotFoundException.class)
	public void testExpParseFunctions01() throws Throwable{
		Calculator.expParser=new ExpressionParser(10);
		Calculator.expParser.parseFunctions("4+5+[1+2]*3=9");
	}
	
	@Test
	public void testExpParseFunctions02() throws Throwable{
		Calculator.expParser=new ExpressionParser(10);
		Calculator.expParser.parseFunctions("sin[30]");
		Calculator.expParser.parseFunctions("-sin[30]");
	}
	
	@Test(expected=MissingOperandException.class)
	public void testExpParseFunctions03() throws Throwable{
		Calculator.expParser=new ExpressionParser(10);
		Calculator.expParser.parseFunctions("a+b[]");
		
	}
	
	@Test(expected=ExpressionParserException.class)
	public void testExpParseFunctions04() throws Throwable{
		Calculator.expParser=new ExpressionParser(10);
		Calculator.expParser.parseFunctions("sin[1+2=3]");
		
	}
	
	@Test
	public void testExpParseOperators00() throws Throwable{
		Calculator.expParser=new ExpressionParser(10);
		Calculator.expParser.parseOperators("(1 - 2 + 3)");
	}
	
	@Test(expected=MissingOperandException.class)
	public void testExpParseOperators01() throws Throwable{
		Calculator.expParser=new ExpressionParser(10);
		Calculator.expParser.parseOperators("1 +");
	}
	
	@Test(expected=MissingOperandException.class)
	public void testExpParseOperators03() throws Throwable{
		Calculator.expParser=new ExpressionParser(10);
		Calculator.expParser.parseOperators("+ 1");
	}
	
	@Test
	public void testExpParseOperators02() throws Throwable{
		String exp=" a+a ";
		String numberRegex = "(([+-]?)\\d+(\\.\\d+)?([eE](-?)\\d+)?)";
		while (exp.matches("(.*)" + numberRegex + "\\s+-\\s+" + numberRegex + "(.*)")) {
			exp = exp.replaceAll(numberRegex + "\\s+-\\s+" + numberRegex, " $1 + -($6) ");
			exp = Calculator.expParser.parseParenthesis(exp);
		}
		System.out.println("ggggghhh:"+exp);
		String[] stack = exp.split("\\s+");
		System.out.println("sss_stcak:"+stack[1]+"__"+stack.length);
	}
	
	@Test(timeout=1000)
	public void testExpindexOfMatchingBracket00() throws Throwable{
		Calculator.expParser=new ExpressionParser(10);
		System.out.println("VVV"+Calculator.expParser.indexOfMatchingBracket("(())(",2,'(',')'));
		Calculator.expParser.indexOfMatchingBracket("(())(",1,'(',')');

	}
	
	
	@Test(expected=UnmatchedBracketsException.class)
	public void testExpindexOfMatchingBracket01() throws Throwable{
		Calculator.expParser=new ExpressionParser(10);
		Calculator.expParser.indexOfMatchingBracket("(-4)",4,'a','b');

	}
}

MoreTriangle测试代码

package net.mooctest;

import static org.junit.Assert.*;

import org.junit.Test;

public class MoreTriangleTest {
	
	MoreTriangle t1=new MoreTriangle();
	
	MoreTriangle t2=new MoreTriangle(1,1,4,5,7,1);
	MoreTriangle t3=new MoreTriangle("t3",1,1,4,5,7,1);
	MoreTriangle t4=new MoreTriangle(7,1,1,1,4,5);
	MoreTriangle t5=new MoreTriangle(4,5,7,1,1,1);
	
	MoreTriangle t6=new MoreTriangle(1,1,1,4,5,1);
	MoreTriangle t7=new MoreTriangle(5,1,1,1,1,4);
	MoreTriangle t8=new MoreTriangle(1,4,5,1,1,1);
	

	
	
	Vector v1=new Vector();
	Vector v2=new Vector(2,7);
	
	Node n1=new Node(3,4);
	Node n2=new Node("nn2",4,5);
	
	Edge e1= new Edge();
	Edge e2= new Edge(n1,n2);
	

	@Test
	public void testGetCentroidX() {
		assertEquals(4, t2.getCentroidX(),0);
	}

	@Test
	public void testGetCentroidY() {
		assertEquals(7/3.0, t2.getCentroidY(),0);
	}

	@Test
	public void testPerimeter() {
		assertEquals(16, t2.perimeter(),0);
	}

	@Test
	public void testArea() {
		assertEquals(12, t2.area(),0);
	}

	@Test
	public void testPointInsideTriangle() {
		assertTrue(t2.pointInsideTriangle(4, 2));
		assertTrue(t4.pointInsideTriangle(4, 2));
		assertTrue(t5.pointInsideTriangle(4, 2));
		
		assertFalse(t2.pointInsideTriangle(1, 1));
		assertFalse(t2.pointInsideTriangle(4, 5));
		assertTrue(t2.pointInsideTriangle(5, 2));
		assertTrue(t5.pointInsideTriangle(5, 2));
		//assertFalse(t2.pointInsideTriangle(7, 1));
		assertFalse(t2.pointInsideTriangle(1, 10));
		assertFalse(t2.pointInsideTriangle(8, 2));
		
		assertFalse(t6.pointInsideTriangle(1, 2));
		assertFalse(t7.pointInsideTriangle(1, 2));
		assertFalse(t8.pointInsideTriangle(1, 2));

	}

	@Test
	public void testToString() {
		String s3="";
		//System.out.println(t3.toString());
		assertFalse(s3==t3.toString());
				
	}

	@Test
	public void testAdd() {
//		System.out.println(t4.node1.add(t4.node2));
//		System.out.println(t4.node1.add(t4.node2).length());
		assertTrue(Math.sqrt(68)==t4.node1.add(t4.node2).length());
		
	}
	
	@Test
	public void testVectortoString() {
		
		assertFalse("Vector(" + 2 + ", " + 7 + ")"== v2.toString());
	}
	



}

如果朋友您正好在做这两个题,希望交流交流,网上找不到答案,官方也没有给答案,他们的群也进不去,而且那个慕测平台还有bug…

  游戏开发 最新文章
6、英飞凌-AURIX-TC3XX: PWM实验之使用 GT
泛型自动装箱
CubeMax添加Rtthread操作系统 组件STM32F10
python多线程编程:如何优雅地关闭线程
数据类型隐式转换导致的阻塞
WebAPi实现多文件上传,并附带参数
from origin ‘null‘ has been blocked by
UE4 蓝图调用C++函数(附带项目工程)
Unity学习笔记(一)结构体的简单理解与应用
【Memory As a Programming Concept in C a
上一篇文章      下一篇文章      查看所有文章
加:2022-05-01 16:02:57  更:2022-05-01 16:05:46 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/23 10:27:28-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码