對我們和複利計算程式,寫單元測試。
有哪些場景?
期待的傳回值
寫測試程式。
運作測試。
其實我對這個單元測試的概念還是不熟悉,特别不知道要怎麼測試代碼,還得花時間去找熟練下
主要代碼
package test;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;
/**
* @author
*
*/
public class Fuli
{
public Fuli(){
}
public static void caculate(double principal, double rate, int n){
double amount;
NumberFormat currencyformatter=NumberFormat.getCurrencyInstance();
String output="年"+"/t"+"複利存款"+"/n";
int year =1;
while(year<=n)
{
amount=principal*Math.pow(1+rate,year);
output+=String.valueOf(year)+"\t"+currencyformatter.format(amount)+"\n";
year=year+1;
}
System.out.println(output);
}
}
總結:由于不知道要怎麼單元測試代碼,百度後仍然還是迷迷糊糊的,或許還需要時間來熟練了解單元測試!