軟體工程-課上單元測試

來源:互聯網
上載者:User

標籤:

單元測試:

原始碼:

 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、當輸入有相同數時:

軟體工程-課上單元測試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.