首页 练字文章 test

test

2023-11-20 16:56  浏览数:366  来源:小键人10618375    

package f1;
public class F {
private String result;
public String MathF(int x,int y) {
double j;
if(x>60&&y<35) {
j=10*x-y;
}else if(x==25&&y>50){
j=(x-y)*((10^5)%7);
}else {
j=y*(Math.log(x+10));
}
result=""+j;
System.out.println(result);
return result;
}
}
package f1;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;
public class FTest {
private F f1=new F();
@Test
public void test1() {
assertThat("690.0",startsWith(f1.MathF(70, 10)));
}
@Test
public void test2() {
assertThat("-35.0",startsWith(f1.MathF(25, 60)));
}
@Test
public void test3() {
assertThat("68.02394763324311",startsWith(f1.MathF(20, 20)));
}
}
package f2;
public class F {
private String result;
public String MathF(String c,String u) {
if(c.equals("M")) {
result="Monday";
}else if(c.equals("T")) {
if(u.equals("u")) {
result="Tuesday";
}else if(u.equals("h")) {
result="Thursday";
}
}else if(c.equals("W")) {
result="Wednesday";
}else if(c.equals("F")) {
result="Friday";
}else if(c.equals("S")) {
if(u.equals("a")) {
result="Saturday";
}else if(u.equals("u")) {
result="Sunday";
}
}
return result;
}
}
package f2;
import static org.junit.Assert.*;
import org.junit.Test;
public class FTest {
private F f1=new F();
@Test
public void test1() {
assertEquals("Monday",f1.MathF("M", "o"));
}
@Test
public void test2() {
assertEquals("Tuesday",f1.MathF("T", "u"));
}
@Test
public void test3() {
assertEquals("Wednesday",f1.MathF("W", "e"));
}
@Test
public void test4() {
assertEquals("Thursday",f1.MathF("T", "h"));
}
@Test
public void test5() {
assertEquals("Friday",f1.MathF("F", "r"));
}
@Test
public void test6() {
assertEquals("Saturday",f1.MathF("S", "a"));
}
@Test
public void test7() {
assertEquals("Sunday",f1.MathF("S", "u"));
}
}
package f3;
public class F {
private String result;
private String uregx="^[a-zA-Z]{5}@(163|126).(com.cn|com)$";
private String pregx="^[0-9]{6,}$";
public String MathF(String username,String password) {
if(username.matches(uregx)) {
if(password.matches(pregx)) {
result="信息正确";
}else {
result="密码不符合要求";
}
}else {
result="用户名不符合要求";
}
return result;
}
}
package f3;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;
public class FTest {
private F f1=new F();
@Test
public void test1() {
assertThat("信息正确",equalTo(f1.MathF("ertyu@163.com", "1234567")));
}@Test
public void test3() {
assertThat("密码不符合要求",equalTo(f1.MathF("ertyu@163.com", "123")));
}
@Test
public void test2() {
assertThat("用户名不符合要求",equalTo(f1.MathF("er||||???.com", "1234567")));
}
}
package f4;
public class F {
private String result;
public String MathF(String username,String password) {
if(username==""&&password=="") {
result="用户名或密码不能为空";
}else if(username.equals("admin")&&password=="123") {
result="登录成功";
}else if(!(username.equals("admin"))&&password.equals("123")) {
result="请输入正确的用户名";
}else if(username.equals("admin")&&!(password=="123")) {
result="请输入正确的密码";
}else if(!(username.equals("admin"))&&!(password=="123")) {
result="请输入正确的用户名和密码";
}
return result;
}
}
package f4;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
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;
@RunWith(Parameterized.class)
public class FTest {
private F f1=new F();
private String username;
private String password;
private String expect;
public FTest(String username,String password,String expect) {
this.username=username;
this.password=password;
this.expect=expect;
}
@Parameters
public static Collection<?> data(){
return Arrays.asList(new Object[][] {
{"","","用户名或密码不能为空"},
{"admin","123","登录成功"},
{"am","123","请输入正确的用户名"},
{"admin","1","请输入正确的密码"},
{"ad","1","请输入正确的用户名和密码"},
});
}
@Test
public void test1() {
assertEquals(expect,f1.MathF(username, password));
}
}



声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)