2017-08-09 2 views
0

junitテストシステムではスキルが新しく、@Parametersの修正を手伝ってくれる人の助けを借りたいと思います。配列には3つの値があると仮定しますが、何を入れるべきかわかりません。私は、オブジェクトテスト条件で、parallelToテストの作業を行うだけで、簡単に助けが必要です。私は他の提案にも開放しています。私のパラレルテスト作業をパラメータ化しました

private int parallel; 
private Line p; 
private boolean x; 

:あなたが必要な事前のおかげで

LineTestParallelTo.java

package line; 

import static org.junit.Assert.*; 

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 LineTestParallelTo { 


private int parallel; 
private Line p; 
private boolean x; 

public void LineTestParallel(int parallel, Line p) 
{ 
    this.parallel = parallel; 
    this.p = p; 
    this.x = x; 
} 

@Parameters 
public static Collection<Object[]> testConditions() { 

    Line one = new Line(1,1,2,2); 
    Line two = new Line(1,1,3,3); 
    Line three = new Line(1,1,3,2); 

    Object x[][][] = { 
      {}, 
      {}, 
      {} 
    }; 
    return Arrays.asList(x); 
} 

@Test 
public void test() { 
    assertEquals(parallel, x.parallelTo(l) , p.parallelTo(p), 0.0001); 
} 

} 

Line.java

package line; 

public class Line { 
//Always create a constructor 
//private double x0, y0, x1, y1; 

// construct a line object 
    public Line(double x0, double y0, double x1, double y1) { 
    this.x0 = x0; 
    this.y0 = y0; 
    this.x1 = x1; 
    this.y1 = y1; 
    } 



    // calculate the slope of the line 
    public double getSlope() { 
    // avoid dividing by zero 
    if(x1 == x0) { 
     throw new ArithmeticException(); 
    } 

    return (y1 - y0)/(x1 - x0); 
    } 

    // calculate the distance of the line 
    public double getDistance() { 
    return Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)); 
    } 

    // return whether a line is parallel to another 
    public boolean parallelTo(Line l) { 
    // if the difference between the slopes is very small, consider them parallel 
    if(Math.abs(getSlope() - l.getSlope()) < .0001) { 
     return true; 
    } else { 
     return false; 
    } 
    } 

    // private member data 
    private double x0, y0, x1, y1; 


} 

答えて

0

の値は、フィールドとして定義された3つのパラメータの値です例として:

私はこれまで得た方法に興味のある人のための
return Arrays.asList(new Object[][][]{ 
      {1, one, false}, 
      {2, two, true}, 
      {3, three, true} 
    }); 

:オブジェクトでJunit Parameters Documentation

+0

私が書くことかわからない[] [] [] {} xは –

関連する問題