這是我的代碼,而我至今嘗試過的測試我試圖寫一個臨時轉換JUnit測試,但還沒有得到一個工作尚未
public class TempConvert {
private double cel;
private double fah;
private double kel;
public TempConvert(double celsius) {
this.cel = celsius;
this.fah = (celsius * 1.8) + 32;
this.kel = celsius + 273.15;
}
protected double getCel() {
return cel;
}
public double getfah() {
return fah;
}
public double getkel(){
return kel;
}
public void setCal(double celsius){
this.cel = celsius;
this.fah = (celsius * 1.8) + 32;
this.kel = celsius + 273.15;
}
public void setFah(double fahrenheit){
fah = fahrenheit;
cel = (fah * 1.8) + 32;
kel = cel + 273;
}
public void setKel(double kelvin){
kel = kelvin;
cel = kel -273;
fah = (cel * 1.8) + 32;enter code here
}
public String toString(){
//DecimalFormat formater = new DecimalFormat("0.##");
return "the temp in c is" + cel + "the tempt in f is " + fah + `"the temp in kel is " + kel;`enter code here`
}
這是我與那些測試頁我試圖回答
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@Test
public void testSetCal() {
TempConvert cal1 = new TempConvert(10);
assertEquals(10,40,283.15,cal1.getCel());
}
private void assertEquals(int i, int j, double d, double cel) {
// TODO Auto-generated method stub
}
與這個測試我曾嘗試使用斷言真正的方法,但我不知道這是否是使用正確的,或者如果這是正確的格式?
@Test
public void testSetFah() {
TempConvert fah1 = new TempConvert(40);
assertTrue("range acceptable",fah1.getCel() , fah1.getkel());
}
private void assertTrue(String string, double cel, double getkel) {
// TODO Auto-generated method stub
}
with this test I have tried the assertEquals method but again not working . I have tried several variations of these two methods and have not gotten any succcess. I am now in fear that my original code is changed and will have to go back and review it as have tried several auto fixes
@Test
public void testSetKel() {
TempConvert kel1 = new TempConvert(283.15);
assertEquals(283.15,10,40,kel1.setKel1());//the 3 numbers are the respective values in kelvin and faharenight and celesius
}
@Test
public void testToString() {`enter code here`
fail("Not yet implemented"); // TODO
}
的任何部分。任何幫助將受到歡迎
在開始搞亂測試之前,轉換的代碼是或者可以的。我可以修復任何它是@test我被困住的東西 – user3373898