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

        }


    }

  • 相关阅读:
    一个新的Activity跳转到带有Framgment的Activity页面
    安卓图片下载及存储
    安卓4.0以上 UDP 发送端
    安卓 service 后台运行,activity 启动和停止service
    安卓 BaseAdapter ListView和Button
    安卓点击两次返回键退出程序
    安卓 surfaceview 添加点击事件
    Mybatis
    Cookie
    AJAX原生代码
  • 原文地址:https://www.cnblogs.com/jinlindb/p/6567015.html
Copyright © 2011-2022 走看看