EE308 LAB11
| The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZ |
| The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/603781458 |
| The Aim of This Assignment | Course Summary |
| MU STU ID and FZU STU ID | 19105681 831901211 |
Preparation
Learn related knowledge about Junit Test for Java and Unittest for python. You can finish the following assignment or test Your Project.
Task
- Here are Junit Test task and Unittest task for choose. If you are good at Java , we suggest you choose the first one, if you are good at Python, then, the latter one.
- Follow the requests and tips, complete the test task .
Requirements
- You should be familiar with Junit Test or Unittest and the usage of these tools.Such as ‘assert, suite, timeout’, check problems for detail.
- Fix the missing codes according to requirement for every problem.
Tips:
- We list ‘related knowledge’ for some problems, read it very carefully
Unittest based on python
1.unittest assert test
-
import unittest, random
# Test Class
class MyClass(object):
@classmethod
def sum(self, a, b):
return a + b
@classmethod
def div(self, a, b):
return a / b
@classmethod
def retrun_None(self):
return None
# Unit Test Class
class MyTest(unittest.TestCase):
# assertEqual()
def test_assertEqual(self):
# test if a+b equals sum or not
try:
a, b = 1, 2
sum = 3
self.assertEqual(a + b, sum, 'assert failed!,%s + %s != %s' % (a, b, sum))
except AssertionError as e:
print(e)
# assertNotEqual()
def test_assertNotEqual(self):
# fix missing three lines of codes below ‘try’, test if b-a equals res or not
try:
a, b = 1, 3
res = 3
self.assertNotEqual(b - a, res, 'assert failed!,%s + %s != %s' % (a, b, res))
except AssertionError as e:
print(e)
# assertTrue()
def test_assertTrue(self):
try:
self.assertTrue(1 == 1, "False expression")
except AssertionError as e:
print(e)
# assertFalse()
def test_assertFalse(self):
# fix missing codes below ‘try’, only a line of codes needed
try:
self.assertFalse(1 != 1, "False expression")
except AssertionError as e:
print(e)
# assertIs()
def test_assertIs(self):
# test a and b are totally same
try:
a = 12
b = a
self.assertIs(a, b, "%s and %s are not same" % (a, b))
except AssertionError as e:
print(e)
# assertIsInstance()
def test_assertIsInstance(self):
# fix missing codes below ‘y=object’ to test type(x) != y, only a line of codes needed
try:
x = MyClass
y = object
self.assertIsNot(x, y, "%s and %s are not same" % (x, y))
except AssertionError as e:
print(e)
if __name__ == '__main__':
# run unittest
unittest.main() -
✔result of this test:
-
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import Help.Calculate;
import Help.CalculateTest;
import Help.Car;
import Help.CarTest;
/*
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)
@Suite.SuiteClasses({ CalculateTest.class, CarTest.class})
public class SuiteTest {
} -
Summary
Through this experiment, I gain a deeper understanding of the code structure used to implement the back end. It is a good chance to improve the writing ability and understanding of the code, and ultimately my testing is successful.
相关推荐
EE-308 LAB4 final version.7z
这是本次实验的压缩包
EE308-Lab11-Software Testing
unittest for Python
完全复现虚拟同步发电机VSG自适应惯量阻尼控制仿真、根轨迹、调节系数对比(Simulink仿真、Matlab代码实现)
内容概要:本文围绕虚拟同步发电机(VSG)的自适应惯量阻尼控制策略展开,通过Simulink仿真与Matlab代码实现,全面复现并深入分析了VSG在不同控制参数下的动态响应特性。研究重点包括构建VSG的数学模型,设计自适应惯量与阻尼控制算法,利用根轨迹法分析系统稳定性,并对比不同调节系数对系统频率响应、阻尼效果及暂态性能的影响。仿真结果验证了所提自适应控制策略在提升系统频率稳定性和抑制功率波动方面的有效性,尤其在应对负载突变等扰动时展现出优异的鲁棒性。该资源为电力系统仿真、新能源并网控制等领域的研究提供了完整的可复现案例。; 适合人群:具备一定电力系统基础知识和Matlab/Simulink操作能力,从事新能源发电、微电网控制、电力电子与电力系统自动化等相关领域的科研人员、研究生及工程技术人员。; 使用场景及目标:①学习和掌握虚拟同步发电机(VSG)的基本原理及其在现代电网中的应用;②理解并实践自适应惯量与阻尼控制策略的设计与仿真方法;③掌握利用根轨迹法进行电力系统稳定性分析的技能;④为相关课题的论文写作、项目研究或课程设计提供可复现的仿真模型和技术参考。; 阅读建议:此资源以完全复现为目标,不仅提供了详细的仿真模型和代码,还包含了深入的理论分析。学习者应在理解VSG基本原理的基础上,结合文档内容逐步搭建和调试Simulink模型,重点关注参数调节对系统性能的影响,通过动手实践加深对理论知识的理解。
超扭滑模(STSMC)-快速终端滑模(FTSMC)高阶滑模、磁链无感观测电机控制Matlab仿真(Simulink仿真实现)
内容概要:本文系统研究了永磁同步电机(PMSM)无位置传感器控制中三种滑模速度环控制策略——传统滑模控制(SMC)、超扭滑模控制(STSMC)与快速终端滑模控制(FTSMC)——在离散化仿真环境下的性能差异,并结合高阶滑模磁链观测器实现无感运行。理论分析表明,STSMC通过双增益机制将不连续控制作用嵌入积分项,有效抑制抖振并保持系统鲁棒性;FTSMC则利用非线性终端吸引子实现有限时间收敛,且控制律连续、无切换项。文章详细阐述了各控制器的理论推导、参数整定方法及离散化实现过程,构建的Simulink仿真模型支持从有感向无感的一键切换与控制器灵活配置,所有算法均经过开发板测试验证。仿真结果表明,STSMC在动态响应与抖振抑制的综合性能上最优,FTSMC稳态精度更高,而传统SMC存在明显抖振问题。该研究为工程应用中控制器的选型、优化与实际部署提供了坚实的理论依据与仿真支持。; 适合人群:具备一定现代控制理论基础和Matlab/Simulink仿真能力,从事电机驱动、电力电子、自动化控制及相关领域的研究生、工程师及科研人员。; 使用场景及目标:①深入理解滑模控制在PMSM无感控制中的应用机制与技术演进路径;②掌握STSMC与FTSMC的核心设计原理、参数整定准则及其离散化实现关键技术;③通过对比仿真分析不同滑模策略在动态响应、稳态精度与抖振特性方面的性能差异,为实际系统中控制器的选型、参数优化与工程化落地提供指导。; 阅读建议:建议结合所提供的Simulink仿真模型进行实践操作,重点关注控制器与观测器的模块化搭建、参数调节过程及仿真结果的对比分析,同时可尝试将算法移植至DSP或微控制器等嵌入式平台,以深化对实时控制性能与工程约束条件的理解。
【顶级EI复现】计及连锁故障传播路径的电力系统 N-k 多阶段双层优化及故障场景筛选模型(Matlab代码实现)
【顶级EI复现】计及连锁故障传播路径的电力系统 N-k 多阶段双层优化及故障场景筛选模型(Matlab代码实现)内容概要:本文提出了一种计及连锁故障传播路径的电力系统 N-k 多阶段双层优化及故障场景筛选模型,旨在提升大规模电力系统在极端或恶意攻击下的安全评估效率。该模型上层以最小化系统负荷损失为目标,优化选择最恶劣的 N-k 故障场景;下层则模拟连锁故障的动态传播过程,通过潮流转移、保护动作与设备相继过载等机制刻画故障演化路径。通过双层交互迭代,筛选出最具威胁的故障组合,并结合多阶段动态模拟实现关键故障场景的有效识别。该方法不仅提高了传统静态 N-k 分析的准确性,还增强了对复杂连锁故障演变行为的建模能力,适用于大型电网的风险评估与预防控制。; 适合人群:具备电力系统分析背景、从事电网安全稳定、风险评估或优化调度研究的研究生、科研人员及工程技术人员。; 使用场景及目标:① 用于识别可能导致严重停电事故的关键故障组合;② 支持电网脆弱环节辨识、防御策略制定与应急预案优化;③ 提升对连锁故障传播机理的理解与仿真能力。; 阅读建议:建议读者结合Matlab代码实现部分深入理解算法流程,重点关注双层优化架构的设计、连锁故障传播规则的建模方式以及场景筛选的收敛性判断方法,以便在实际系统中进行复现与改进。


