標籤:
單元測試:
原始碼:
1 import java.util.Scanner; 2 public class List { 3 4 public static void main(String[] args) { 5 // TODO Auto-generated method stub 6 System.out.println("輸入長度"); 7 Scanner t = new Scanner(System.in); 8 int l; 9 l = t.nextInt();10 while(l<=0)11 {12 System.out.println("長度未大於0 請重新輸入");13 l = t.nextInt();14 }15 16 Max m = new Max(l);17 m.Input();18 m.Largest(m.list, m.length);19 m.Output();20 }21 22 }23 24 class Max25 {26 int list[];27 int length;28 int max;29 int i;30 public Max(int s)31 {32 length = s;33 }34 int Largest(int list[],int length)35 {36 max = list[0];37 for( i=0;i<length;i++)38 {39 if(list[i]>max)40 {41 max = list[i];42 }43 }44 return max;45 }46 void Input()47 {48 Scanner k = new Scanner(System.in);49 list = new int [length];50 System.out.println("請輸入數組");51 for( i=0;i<length;i++)52 { 53 list[i]=k.nextInt();54 }55 }56 void Output()57 {58 System.out.println(max);59 }60 61 62 }
測試:
1、當數組長度為負數時:
2、當數組長度為0時
3、當輸入值都為正數時:
4、當輸入數都為負數時:
5、當輸入數正數負數都有時:
6、當輸入有相同數時:
軟體工程-課上單元測試