zoukankan      html  css  js  c++  java
  • 数组测试 --Junit

    1、添加依赖

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support:appcompat-v7:25.1.1'
        compile 'com.android.support.constraint:constraint-layout:1.0.1'
        testCompile 'junit:junit:4.12'
    }

    2.java代码

    package com.example.testforgit;

    /**
     * Created by ** on 2017/3/13.
     */

    public class Work {
        public static int forsum(int[] array){
            if(array.length==0 || array==null){
                return 0;
            }
            int Sum1 = 0;//存储当前连续n项的和
            int max =0;//存储连续子元素和的最大值
            for(int i=0;i<array.length;i++){
                if(Sum1<=0){
                    Sum1=array[i];
                }else{
                    Sum1+=array[i];
                }
                if(Sum1>max){
                    max=Sum1;
                }
            }
            return max;
        }
    }

    3.测试部分

    package com.example.testforgit;

    import org.junit.Before;
    import org.junit.Test;

    import static org.junit.Assert.*;

    /**
     * Created by 金林 on 2017/3/13.
     */
    public class WorkTest {
        private Work mwork;
        @Before
        public void setUp() throws Exception {
                mwork = new Work();
        }

        @Test
        public void forsum() throws Exception {
            int[] array={-1,2,3,-4};
            int result = 5;
            result=mwork.forsum(array);
            System.out.print(result);

        }


    }

  • 相关阅读:
    设计模式-抽象工厂模式
    装修预算-资料收集
    SQL中存储过程和函数的区别
    View
    数据表优化
    Entity Framework 基础
    html5标准
    JS整数验证
    vue 页面切换从右侧切入效果
    vue动态设置Iview的多个Input组件自动获取焦点
  • 原文地址:https://www.cnblogs.com/jinlindb/p/6567015.html
Copyright © 2011-2022 走看看