EE308_LAB 11
| The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZ?category=0 |
|---|---|
|
The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/603748107 |
| The Aim of This Assignment | Learn related knowledge about Junit Test for Java and Unittest for python. |
| MUID&FZUID | 19104332 & 831901214 |
| Name | Wang Ruoyu |
1. Introducion
Of the two programming languages, Java and Python, I'm more familiar with Java, so I ended up using Juint for my tests.
2. Solving process
(1) Junit assert
Code:
package com.Lab10;
import org.junit.Test;
import static org.junit.Assert.*;
public class AssertionsTest {
String obj1 = "junit";
String obj2 = "junit";
String obj3 = "test";
String obj4 = "test";
String obj5 = null;
int var1 = 1;
int var2 = 2;
int[] arithmetic1 = { 1, 2, 3 };
int[] arithmetic2 = { 1, 2, 3 };
@Test
public void test() {
// add assert test code between Begin and End, no other change allowed
/***********************Begin**************************/
assertTrue(var1 < var2);
assertTrue(obj1 == obj2);
assertTrue(obj3 == obj4);
assertNull(obj5);
assertArrayEquals(arithmetic1,arithmetic2);
/************************End***************************/
}
}
Run:

(2) Junit time test
Code:
package com.Lab10;
import org.junit.Test;
public class TestTimeOut {
// Fix timeout assert in Test function below. Test fail if running 1000ms longer
/***********************Begin**************************/
@Test(timeout = 1000)
public void test() {
int a=0;
while(a!=-1){
a+=1;
}
}
/************************End***************************/
}
Run:

(3)Junit parameterized test
Code:
package com.Lab10;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import java.util.Arrays;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
/**
* JUnit4 parameterized test
*/
@RunWith(Parameterized.class)
public class ParameterTest {
private int input11;
private int input22;
private int expected;
public ParameterTest(int input11, int input22, int expected){
this.input11 = input11;
this.input22 = input22;
this.expected = expected;
}
@Parameters
public static Collection prepareData(){
/**
*the type of the two-dimension array must be Object.
*data in the two-dimension array is ready of test sub() in Calculator
* every element in the two-dimension array should corresponds to position of parameters in construct method ParameterTest
*let the third element equals the first subtract the second element according to parameters’ postion
*fix missing codes under ‘Begin’ and above ‘End’,pass 4 groups of parameters to test sub method in Calculator is right or not
*tip:only two lines of codes
*/
/*********************************Begin********************************************/
return Arrays.asList(new Integer[][]{
{3,2,1},
{6,4,2},
{4,5,6},
{1,2,3},
});
/**********************************End********************************************/
}
@Test
public void testSub(){
Calculator cal = new Calculator();
assertEquals(cal.sub(input11, input22), expected);
}
}
package com.Lab10;
// Calculator.java Junit Parameterized Test
/**
* Mathematical Calculation subtract
*/
public class Calculator {
public int sub(int a, int b) {
return a - b;
}
}
Run:

(4)Junit Exception Test
Code:
package com.Lab10;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class JunitException {
/**
*add a line of annotation in Begin/End,check the age of Person Object is legal or not. *throw IllegalArgumentException exception
*/
/***********************************Begin***********************************/
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void lab10Test(){
thrown.expect(IllegalArgumentException.class);
checkage();
}
/************************************End************************************/
public void checkage() {
Person person = new Person();
person.setAge(-1);
}
}
Run:

(5)Junit Exception Test
Code:
package com.Lab10;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
/*
add two lines of annotations. Implement Suite Test of CalculateTest and CarTest
Suite Test codes must next to Class SuiteTest, no shift allowed!
*/
//**************************************************************
@RunWith(Suite.class)
@SuiteClasses({CalculateTest.class, CarTest.class})
public class SuiteTest {
}
Run:

3. Conclusion
Mastering unit testing can greatly reduce the time we spend debugging and improve the overall quality of our code. (And look professional!)
相关推荐
EE-308 LAB4 final version.7z
这是本次实验的压缩包
EE308-Lab11-Software Testing
unittest for Python
EE308-Lab8-AlphaSprint Collection
EE308 Lab8 Alpha Sprint Collection1. Format Description2. 宁可累死自己,也要卷死同学 -Sprint Collection 1. Format Description The Link Your Class https://bbs.csdn.net/forums/MUEE308FZ The Link of Requirement of This Assignment https://bbs.csdn.net/topics/603251
【信息科学与工程学】【物理/化学科学和工程技术】知识体系073——电学基础04
。
【多无人机协同目标运输任务】多无人机协同目标运输任务中的路径规划与动态控制研究(Matlab代码实现)
内容概要:本文聚焦于多无人机协同执行目标运输任务中的关键问题,系统研究了复杂环境下多无人机系统的路径规划与动态控制策略,并提供了基于Matlab的完整仿真代码实现。研究内容包括多智能体协同机制设计、高效路径规划算法(如改进RRT*、A*等)的应用、动态响应控制策略(如反步控制、滑模控制等)的集成,以及任务过程中无人机间的协调控制逻辑。通过高保真度仿真验证了所提方法在不同场景下的有效性、鲁棒性与实用性,代码配备详尽注释,便于理解与二次开发。; 适合人群:具备一定控制理论基础和Matlab编程能力,从事无人机控制、多智能体系统、智能交通或机器人协同等方向的科研人员及研究生(工作1-3年或研一以上水平);; 使用场景及目标:①用于多无人机协同运输任务的算法设计与仿真验证;②支撑科研论文复现、课题开发及工程原型构建;③深入理解路径规划与动态控制在多机协同中的耦合关系与实现方式;; 阅读建议:建议结合Matlab代码逐模块调试运行,配合控制理论教材深化对控制律设计的理解;建议先掌握单无人机基本控制原理,再逐步过渡到多机协同逻辑的学习,以提升整体系统认知与实践效率。


