package com.sunzee;

import android.util.Log;

import com.sunzee.model.HoleInformation;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
public class ExampleUnitTest {
    private static final String TAG = "Test";
    public static char[] chars = {0, 0, 0, 0, 0, 0};
    //存储两个数据：是否上过厕所，一开始上厕所的时间是什么时候
    private static List<HoleInformation> sHoleInformationList = new CopyOnWriteArrayList<>();
    private static LinkedList<Integer> sCleaningLocationList = new LinkedList<>();//存储要清洗的位置。
    private static int sum = 0;

    @Test
    public void test() {
        for (int i = 0; i < 6; i++) {
            sHoleInformationList.add(i, new HoleInformation(2, 0));//初始化
        }

        while (true) {
            sum++;
            System.out.println(sum);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (sum == 15) {
                sum = 0;
                chars[0] = 1;
            } else {
                chars[0] = 0;
            }
            if (chars[0] == 1) {
                HoleInformation holeInformation = sHoleInformationList.get(0);
                int state = holeInformation.getState();
                if (state != 1) {
                    if (state == 0) {
                        if (System.currentTimeMillis() - holeInformation.getTimeDuration() > 20000) {
                            //开始清洗厕所。
                            sCleaningLocationList.add(0);
                            System.out.println("出来厕所。");
                        } else {
                            System.out.println("又上厕所了。");
                        }
                    }
                } else {
                    //说明是第一次，还没上厕所。
                }
            } else {
                HoleInformation holeInformation = sHoleInformationList.get(0);
                if (holeInformation.getState() != 0) {
                    holeInformation.setState(0);//上厕所
                    holeInformation.setTimeDuration(System.currentTimeMillis());//存储他上厕所的时间
                }
                System.out.println("在上厕所。");
            }
        }
    }

    @Test
    public void mmm(){
        String asdf = "1111111";
        String[] split = asdf.split("");
        System.out.println(split[0]);
        List<String> lis = Arrays.asList(asdf.split(""));
        System.out.println(lis.get(0));
        ArrayList<String> result = new ArrayList(lis);
        System.out.println(result.get(0));
    }


}