package com.tcl.ah.tvcontrol;

import android.util.Log;

import org.apache.commons.codecc.binary.Base64;
import org.junit.Test;

import static org.junit.Assert.*;

import java.util.Random;

/**
 * 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 {
    @Test
    public void addition_isCorrect() {
        assertEquals(4, 2 + 2);
    }

    private static final int START_LEFT = 11;
    private static final int START_RIGHT = 13;
    private static final int END_LEFT = 8;
    private static final int END_RIGHT = 4;

    @Test
    public void StringCustomVaryForDecrypt() {
        String valueBase = "2RlIjoidm9DM=sdW1lIiwidmFsdWUiOjUwfToxNjAzOTc1NTk4LjeyJjbcyM";
//        String valueBase = "eyJjb2RlIjoidm9sdW1lIiwidmFsdWUiOjUwfToxNjAzOTc1NTk4LjcyMDM=";
//        String valueBase = "bbbbb456*********aaaaa123";
        if (valueBase.length() < 15) return;
        int strLong = valueBase.length();
        StringBuilder stb = new StringBuilder(valueBase);
        String startStr = valueBase.substring(START_LEFT - 1, START_RIGHT);
        String endStr = valueBase.substring(strLong - END_LEFT, strLong - END_RIGHT + 1);

        stb.replace(START_LEFT - 1, START_RIGHT, "");
        int startLength = START_RIGHT - START_LEFT;
        System.out.println("this is :" + stb.toString());
        stb.replace(strLong - END_LEFT - startLength - 1, strLong - END_RIGHT - startLength, "");
        System.out.println("this is :" + stb.toString());
        String str = stb.toString();
        String resStr = endStr + str + startStr;

        System.out.println("this is :" + "startStr:" + startStr + "endStr" + endStr + "str:" + str+  "\n" +"resStr:" + resStr);

    }

    @Test
    public void getIndexString() {
//        String value = "eyJjb2RlIjm9DM=sdW1lIiwidmFsdWUiOjUwfToxNjAzOTc1NTk4LjcyMoid";
        String value = "eyJjb2RlIjoidm9sdW1lIiwidmFsdWUiOjUwfToxNjAzOTc1NTk4LjcyMDM=";
//        String str = new String(value);
        String str = new String(Base64.decodeBase64(value.getBytes()));
        System.out.println("this is TEST Decrypt:" + str);
        String res = "";
        try {
            if (str.contains(":"))
                res = str.substring(0, str.lastIndexOf(":"));
        } catch (Exception e) {

        }
        System.out.println("this is TEST Decrypt:" + res);
    }

    @Test
    public void testRandom(){
        double pos = new Random().nextInt(100);
        System.out.println(pos);
    }
}