import junit.framework.TestCase; /** * @author zhengxm * 递归测试 * TODO To change the template for this generated type comment go to * Window – Preferences – Java – Code Style – Code Templates */ public class TestRecurse extends TestCase { public int getResult(int X,int y){ if(y==0) return 1; if(!(y%2==0)){ return getResult(X*X,y/2)*X; } if(y%2==0){ return getResult(X*X,y/2); } return 0; } public void testRecursive(){ int m = 0; int X = 6; int y = 0; m = getResult(X,y); assertTrue(m==1); } } |