package TerrariaClone.GameData;

import TerrariaClone.BlockToolsProvider;
import TerrariaClone.HorrificBlockNameProvider;
import TerrariaClone.HorrificBlockToolsProvider;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.*;

public class JsonBlockToolsProviderTest {

    @Test
    public void constantlyBootstrapBlockTools()
    {
        String[] blocknames = new HorrificBlockNameProvider().getBlockNames();

        JsonBlockToolsProvider provider = new JsonBlockToolsProvider();
        HorrificBlockToolsProvider horrible_provider = new HorrificBlockToolsProvider();
        provider.createBlockToolsData(horrible_provider.getBlockToolsData());

    }

    @Test
    public void getBlockTools() throws Exception {

        String[] blocknames = new HorrificBlockNameProvider().getBlockNames();

        BlockToolsProvider provider = new JsonBlockToolsProvider();
        BlockToolsProvider horrible_provider = new HorrificBlockToolsProvider();

        HashMap<Integer, Short[]> newData= provider.getBlockTools(blocknames);
        HashMap<Integer, Short[]> originalData= provider.getBlockTools(blocknames);
        assertMapWithArrayEqual(newData, originalData);

    }

    public static void assertMapWithArrayEqual(Map<Integer,Short[]> lhs, Map<Integer, Short[]> rhs)
    {
        assertArrayEquals("Map keys should be the same", lhs.keySet().toArray(), rhs.keySet().toArray());
        for(Integer key : lhs.keySet())
        {
            assertArrayEquals("Inner arrays should be the same", lhs.get(key), rhs.get(key));
        }
    }

}