复利-单元测试

 对我们和复利计算程序,写单元测试。 

   有哪些场景?

   期待的返回值

   写测试程序。

   运行测试。

其实我对这个单元测试的概念还是不熟悉,特别不知道要怎么测试代码,还得花时间去找熟练下

主要代码

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);
	}
}

 

 总结:由于不知道要怎么单元测试代码,百度后仍然还是迷迷糊糊的,或许还需要时间来熟练理解单元测试!

 

posted @ 2016-03-29 22:11  26林发  阅读(141)  评论(0编辑  收藏  举报