package objectstructures;

import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;

public class CoffeeCupTest {
  CoffeeCup cup;
  CoffeeCup halfWayFilledCup;

  @BeforeEach
  public void setup() {
    this.cup = new CoffeeCup();
    this.halfWayFilledCup = new CoffeeCup(2, 1);
  }

	@Test
	@DisplayName("Test constructor validation")
  public void testConstructorValidation() {
    assertThrows(IllegalArgumentException.class, () -> new CoffeeCup(-1, -2));
    assertThrows(IllegalArgumentException.class, () -> new CoffeeCup(1, -1));
    assertThrows(IllegalArgumentException.class, () -> new CoffeeCup(2, 3));
    var localCup = new CoffeeCup(3, 2);
  }

	@Test
	@DisplayName("Test getCapacity")
  public void testGetCapacity() {
    assertEquals(0, cup.getCapacity());
    assertEquals(2, halfWayFilledCup.getCapacity());
  }

	@Test
	@DisplayName("Test getCurrentVolume")
  public void testGetCurrentVolume() {
    assertEquals(0, cup.getCurrentVolume());
    assertEquals(1, halfWayFilledCup.getCurrentVolume());
  }

	@Test
	@DisplayName("Test increaseCupSize")
  public void testIncreaseCupSize() {
    assertEquals(0, cup.getCapacity());
    cup.increaseCupSize(3);
    assertEquals(3, cup.getCapacity());
    cup.increaseCupSize(1.5);
    assertEquals(4.5, cup.getCapacity());
    cup.increaseCupSize(-1);
    assertEquals(4.5, cup.getCapacity());
  }

	@Test
	@DisplayName("Test drinkCoffee")
  public void testDrinkCoffee() {
    assertEquals(1, halfWayFilledCup.getCurrentVolume());
    halfWayFilledCup.drinkCoffee(0.5);
    assertEquals(0.5, halfWayFilledCup.getCurrentVolume());
    halfWayFilledCup.drinkCoffee(0.5);
    assertEquals(0, halfWayFilledCup.getCurrentVolume());
    assertThrows(IllegalArgumentException.class, () -> cup.drinkCoffee(0.5));
  }

	@Test
	@DisplayName("Test fillCoffee")
  public void testFillCoffee() {
    assertEquals(1, halfWayFilledCup.getCurrentVolume());
    halfWayFilledCup.fillCoffee(0.5);
    assertEquals(1.5, halfWayFilledCup.getCurrentVolume());
    halfWayFilledCup.fillCoffee(0.5);
    assertEquals(2, halfWayFilledCup.getCurrentVolume());
    assertThrows(IllegalArgumentException.class, () -> cup.fillCoffee(0.5));
  }
}
