package ca.recrown.islandsurvivalcraft.world;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Random;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;

@TestInstance(Lifecycle.PER_CLASS)
public class IslandWorldMapTest {
    public final int SEED = 102385923;
    public Random random = new Random(SEED);
    public IslandWorldMap mapper = new IslandWorldMap(random);
    public final double[][] answers = new double[2048][2048];

    @BeforeAll
    public void setUp() {
        for (int x = 0; x < answers.length; x++) {
            for (int y = 0; y < answers[x].length; y++) {
                answers[x][y] = mapper.getWorldValue(x, y);
            }
        }
    }

    @BeforeEach
    public void individualSetUp() {
        random = new Random(SEED);
        mapper = new IslandWorldMap(random);
    }

    @Test
    public void testBlockValueConsistency() {
        for (int x = 0; x < answers.length; x++) {
            for (int y = 0; y < answers[x].length; y++) {
                assertEquals(answers[x][y], mapper.getWorldValue(x, y), String.format("Occurred at (%d, %d)", x, y));
            }
        }
    }

    @Test
    public void testBlockValueConsistencyRandom() {
        for (int amount = 0; amount < 1024; amount++) {
            int x = random.nextInt(answers.length);
            int y = random.nextInt(answers[x].length);
            assertEquals(answers[x][y], mapper.getWorldValue(x, y), String.format("Occurred at (%d, %d)", x, y));
        }
    }
    
    @Test
    public void test2048ValuesValidity() {
        for (int i = 0; i < 1024; i++) {
            int x = random.nextInt();
            int y = random.nextInt();
            assertTrue((mapper.getWorldValue(x, y) <= 1));
            assertTrue((mapper.getWorldValue(x, y) >= -1));

        }
    }
}