package it.polimi.ingsw.gc14.Model.Orders;

import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;

import static org.junit.jupiter.api.Assertions.*;

class Order2Test {

    @Test
    void effectZero() {
        Player p = new Player("p1");
        Order2 order = new Order2(new ArrayList<>());

        int initialFood = p.getFoodValue();

        order.effect(p, 0);

        assertEquals(initialFood + 1, p.getFoodValue());
    }

    @Test
    void effectOneWithFood() {
        Player p = new Player("p1");
        Order2 order = new Order2(new ArrayList<>());

        p.addFood(1);
        int initialPrestige = p.getPrestigeValue();

        order.effect(p, 1);

        assertEquals(0, p.getFoodValue());
        assertEquals(initialPrestige, p.getPrestigeValue());
    }

    @Test
    void effectOneWithoutFood() {
        Player p = new Player("p1");
        Order2 order = new Order2(new ArrayList<>());

        p.addPrestige(3);

        order.effect(p, 1);

        assertEquals(0, p.getFoodValue());
        assertEquals(1, p.getPrestigeValue());
    }

    @Test
    void effectWrongIndexHigh() {
        Player p = new Player("p1");
        Order2 order = new Order2(new ArrayList<>());

        assertThrows(IndexOutOfBoundsException.class, () -> order.effect(p, 2));
    }

    @Test
    void effectWrongIndexLow() {
        Player p = new Player("p1");
        Order2 order = new Order2(new ArrayList<>());

        assertThrows(IndexOutOfBoundsException.class, () -> order.effect(p, -1));
    }
}