假設有個程式如下
public class Main {
private double _primaryForce=0.2, _secondaryForce=0.1, _mass=2;
int _delay=2;
public static void main(String[] args) {
Main a= new Main();
System.out.println(a.getDistanceTravelled_v1(0));
}
public Main() {
super();
}
public Main(double _primaryForce, double _secondaryForce, double _mass,
int _delay) {
super();
this._primaryForce = _primaryForce;
this._secondaryForce = _secondaryForce;
this._mass = _mass;
this._delay = _delay;
}
double getDistanceTravelled_v1(int time) {
double result = 0;
double acc = _primaryForce / _mass;
int primaryTime = Math.min(time, _delay);
result = 0.5 * acc * primaryTime * primaryTime;
int secondaryTime = time - _delay;
if (secondaryTime >; 0) {
double primaryVel = acc * _delay;
result += primaryVel * secondaryTime + 0.5 * acc * secondaryTime
* secondaryTime;
}
return result;
}
}
我首先要作的事情是,建構測試環境,我使用eclipse以及JUnit來作為測試以及開發工具。
JUnit作的事情是單元測試(Unit Testing),這概念中的最小單元是指函式或方法。當我們使用JUnit測試時,我們會不斷嘗試用使函式崩壞的參數作測試,這絕對不是犯賤,相信我。
單元測試相關閱讀
單元測試相關閱讀
沒有留言:
張貼留言