zoukankan      html  css  js  c++  java
  • 单元测试——数组

    1.array

     1 package com.example.john.testforgit1;
     2 
     3 /**
     4  * Created by john on 2017/3/13.
     5  */
     6 
     7 public class array {
     8 
     9     public  int findMaxArray(int[] array){
    10         if (array == null || array.length == 0) {
    11             return Integer.MIN_VALUE;
    12         }
    13         int maxSum = Integer.MIN_VALUE;
    14         int currentSum = 0;
    15         for (int i = 0; i < array.length; i++) {
    16             if (currentSum < 0) {
    17                 currentSum = array[i];
    18             }else {
    19                 currentSum += array[i];
    20             }
    21             maxSum = Math.max(maxSum, currentSum);
    22         }
    23         return maxSum;
    24     }
    25 
    26 }
    
    

    2.arrayTest

     1 package com.example.john.testforgit1;
     2 
     3 import org.junit.Before;
     4 import org.junit.Test;
     5 
     6 import static org.junit.Assert.*;
     7 
     8 /**
     9  * Created by john on 2017/3/13.
    10  */
    11 public class arrayTest {
    12     private array marray;int[] array = {-1,2,3,-4};
    13     @Before
    14     public void setUp() throws Exception {
    15         marray=new array();
    16     }
    17 
    18     @Test
    19     public void findMaxArray() throws Exception {
    20         assertEquals(5,marray.findMaxArray(array),0);
    21     }
    22 
    23 }
    
    

    3.测试结果

     。

  • 相关阅读:
    易用性问题回复
    阅读心得2:《余额宝技术架构及演进 》
    假期周进度报告8
    假期周进步报告7
    假期周进度报告6
    假期周进度报告5
    假期周进度报告4
    假期周进度报告3
    JAVA中SSH框架
    一张图说明CDN网络的原理
  • 原文地址:https://www.cnblogs.com/ly97/p/6559076.html
Copyright © 2011-2022 走看看