??????????????????3
???????????? ???????[ 2013/8/6 13:56:54 ] ????????
?????ж??????ε?java????
package demo2;
public class Triangle {
private double a??b??c;
public Triangle(double a??double b??double c){
this.a =a;
this.b =b;
this.c =c;
}
/*
* return value description:
* 1.?????????
* 2.??????????
* 3.??????????
* -1.??????????
*/
public int type(){
if(isTriangle()){
if(a==b&&b==c){
return 1;
}else if(a==b||b==c||c==a){
return 2;
}else
return 3;
}
else
return -1;
}
//auxiliary method which is used to predicate weather three number consist of a triangle or not
private boolean isTriangle(){
if(Math.abs(a-b)<c&&Math.abs(a-c)<b&&Math.abs(b-c)<a
&&(a+b>c)&& (a+c >b)&& (b+c >a) )
return true;
return false;
}
}
?????????????????:
package demo2;
import static org.junit.Assert.*;
import org.junit.Test;
public class TriangleTest {
@Test
public void testType(){
Triangle triangle = new Triangle(12??12??4);
assertEquals(2??triangle.type());
}
}
?????????????????????
package demo2;
import static org.junit.Assert.*;
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(value = Parameterized.class)
public class ParameterTestTriangle {
private double expected;
private double valueOne;
private double valueTwo;
private double valueThree;
@Parameters
//Double is a class type??double is a basic type.
public static Collection<Object []> getTestParameters(){
return Arrays.asList(new Object [][]{
{2??12.3??13.5??13.5}??
{2??10??10??4}??
{2??34??5??34}??
{1??6.0??6.0??6.0}??
{1??23??23??23}??
{-1??1.0??4.0??9.0}??
{-1??10??3??15}??
{3??3.0??4.0??5.0}??
{3??12??24??33}??
});
}
public ParameterTestTriangle(double expected?? double valueOne??
double valueTwo??double valueThree){
this.expected= expected;
this.valueOne= valueOne;
this.valueTwo= valueTwo;
this.valueThree= valueThree;
}
@Test
public void testType(){
Triangle triangle = new Triangle(valueOne??valueTwo??valueThree);
assertSame("?????????????????!"??(int)expected??triangle.type());
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11