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);

        }


    }

  • 相关阅读:
    密码朋克的社会实验(一):开灯看暗网
    ThinkPHP5框架缺陷导致远程命令执行(POC整合帖)
    SQL基本注入演示
    从SQL注入到内网漫游
    业务逻辑漏洞探索之敏感信息泄露
    Web安全之XSS Platform搭建及使用实践
    iOS URL Schemes与漏洞的碰撞组合
    phpcms2008远程代码执行漏洞
    使用RSA加密在Python中逆向shell
    源码级调试的XNU内核
  • 原文地址:https://www.cnblogs.com/jinlindb/p/6567015.html
Copyright © 2011-2022 走看看