package com.hc.webapp;

import org.junit.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Random;

import static org.junit.Assert.*;

/**
 * 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);
    }

    @Test
    public void random() {
        for (int i = 0; i < 100; i++) {
            System.out.println(new Random().nextInt(2));
        }
    }

    @Test
    public void test() {
        String url = "http://27.31.208.36:33200/EPG/";
        try {
            URL u = new URL(url);
            System.out.println(u.getAuthority());
            System.out.println(u.getProtocol());
        } catch (MalformedURLException e) {
            String value[] = url.split("/");
            for (int i = 0; i < value.length; i++) {
                System.out.println(value[i]);
            }
        }
    }

    @Test
    public void append() {
        System.out.println( autoGenericCode("123", 8));
    }

    private String autoGenericCode(String code, int length) {
        return "ps_haochuan" + String.format("%0" + length + "d", Integer.parseInt(code));
    }
}