写了一个程序,要从System.in读数据,怎么写JUnit啊,哪位大侠指点一下?
有两个CASE,从console输入,
2 5
1 7 2 10 9
6 11
62 63 54 66 65 61 57 56 50 53 48
0 0
然后可以得到两行结果
Case 1: 2
Case 2: 4
- Java code
import java.util.*;import java.math.*;public class P1001pku { public static void Main() { Scanner cin = new Scanner(System.in); BigDecimal x; StringBuffer output; int n; x = cin.nextBigDecimal(); n = cin.nextInt(); while (true) { x = x.pow(n).stripTrailingZeros(); output = new StringBuffer(x.toPlainString()); if (output.charAt(0) == '0') System.out.println(output.substring(1)); else System.out.println(output); try { x = cin.nextBigDecimal(); n = cin.nextInt(); } catch (NoSuchElementException e) { break; } } }}
------解决方案--------------------
LZ,一般单元测试都是测试一个类或者一个方法.
如果写到main()涵数中,不需要单元测试,直接就可以测试了.
建议LZ,直接把main()里的东西拎出来,放到一个方法里;然后在main()里调用此方法.
另外,我想问LZ,while (true)是什么意思??? 程序里可以这样写吗?