EE308 LAB11

Luv丶 Luv丶 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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 AssignmentSoftware Testing-Junit Test
MUID&FZUID19105045& 831901126
Name

Junye Wu

 

Preparation

Learn related knowledge about Junit Test for Java and Unittest for python. You can finish the following assignment or test Your Project.

 

Task

  1. 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.
  2. Follow the requests and tips, complete the test task .

 

Requirements

  1. You should be familiar with Junit Test or Unittest and the usage of these tools.Such as ‘assert, suite, timeout’, check problems for detail.
  2. Fix the missing codes according to requirement for every problem.

 

Junit assert

import static org.junit.Assert.*;
import org.junit.Test;

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**************************/                      
    assertEquals(obj1,obj2);
    assertNull(obj5);                                                                                                      
    /************************End***************************/
    }
}

junit time test

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() {
        while(true){
            break;
        }
    }
/************************End***************************/ }

 junit parameterized test

import static org.junit.Assert.assertEquals; // static import
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import step1.Calculator;
/**
* 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********************************************/     /**********************************End********************************************/
}
@Test
public void testSub(){
    Calculator cal = new Calculator();
    assertEquals(cal.sub(input11, input22), expected);
    }
}
// Calculator.java Junit Parameterized Test
/**
* Mathematical Calculation  subtract
*/
public class Calculator {
    public int sub(int a, int b) {
        return a - b;
    }
}

 junit exception test

import static org.junit.Assert.*;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import step2.Person;



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***********************************/

/************************************End************************************/
public void checkage() {
    Person person = new Person();
    person.setAge(-1);
    }
}
//Person.java
public class Person {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
    if (age < 0 ) {
        throw new IllegalArgumentException("age is invalid");
    }
    this.age = age;
    }
}

 junit suite test

import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import step3.Calculate;
import step3.CalculateTest;
import step3.Car;
import step3.CarTest;

/*
add two lines of annotations. Implement Suite Test of CalculateTest and CarTest Suite Test codes must next to Class SuiteTest, no shift allowed!
*/                                                                                                                                         //************************************************************** 
public class SuiteTest {
}
//Calculate.java
public class Calculate {
    public int add(int a, int b) {
        return a + b;
    }
}

//CalculateTest.java
public class CalculateTest {
    Calculate calculate;
    @Before
    public void setUp() throws Exception {
        calculate = new Calculate();
    }
@Test
    public void testAdd() {
        int result = calculate.add(12, 12);
        assertEquals(24, result);
    }
}

//CarTest.java
public class CarTest {
    Car car;
@Before
    public void setUp() throws Exception {
        car = new Car();
}
@Test
    public void testGetWheels() {
        int result = car.getWheels();
        assertEquals(4, result);
    }
}

//Car.java
public class Car {
    public int getWheels() {
        return 4;
    }
}

 

...全文

相关推荐

EE-308 LAB4 final version.7z

这是本次实验的压缩包

晨起剪桃花

EE308-Lab11-Software Testing

unittest for Python

调参侠鱼尾

【自然语言处理】基于CRISPE与BROKE框架的提示词工程应用:大语言模型内容生成中的写作方法优化研究

内容概要:本文探讨提示词工程在人工智能内容生成中的关键作用,以CRISPE与BROKE两个提示词框架为例,分析其在角色设定、背景约束、验收标准和迭代机制上的异同,并通过撰写“AI与就业”科普短文的实际案例,展示提示词从模糊任务到可执行指令的构建过程。研究指出,提示词工程的核心不在于模板记忆,而在于提升意图的清晰度、约束的精确性、输出的可评测性以及对模型能力边界的认知。文章强调,有效的提示需明确角色、背景、任务、风格与验收标准,并通过多轮实验与迭代优化结果,避免生成内容陷入形式化与模板化。; 适合人群:具备一定AI基础知识、正在学习或使用大语言模型进行内容创作的学生、研究人员及内容创作者,尤其是关注写作质量与个性化表达的用户。; 使用场景及目标:①掌握如何将模糊写作意图转化为结构化提示词;②提升AI生成内容的信息密度、可读性与实用性;③在科研写作、科普传播等场景中保留个人思考痕迹,避免机械化表达;④学会通过可检查的验收标准持续优化输出。; 阅读建议:此资源不仅介绍提示词框架的操作方法,更强调思维训练。建议读者结合自身写作任务,动手实践CRISPE与BROKE的组合应用,重点关注约束设计与结果评测环节,并反思“为何提示无效”,从而真正实现从“会问”到“会写”的跃迁。

beiningya

技术转移机构自建平台与使用第三方SaaS系统相比,哪种投入产出比更好?.docx

科易网(厦门科易网科技有限公司)创立于2007年,是技术转移与科技创新数智化服务平台,拥有国家科技成果转化服务示范基地、国家技术转移示范机构等资质。平台以“AI+科技成果转化”为核心,整合成果、专利、专家、政策等多维数据,构建知识图谱与科创智能体,面向企业、政府、高校院所提供成果转化、技术需求对接、产业服务等数智化解决方案。截至目前,已服务全国企业超43万家,推动落地项目11800余项,总金额逾80亿元。

BIZKEEN

2026年中国重点行业企业研发投入强度与创新产出比的数据分布现状是怎样的?.docx

2026年中国重点行业企业研发投入强度与创新产出比的数据分布现状是怎样的?

BIZKEEN
评论
收藏 已收藏
分享
返回顶部