package tp1.ex2_2;

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

import java.time.Duration;

import org.junit.jupiter.api.Test;


/**
 * Suite de tests pour vérifier la méthode sqrt dans la classe Sqrt
 */
public class SqrtTest {
	@Test
	public void testSortie(){
		assertTrue(Sqrt.sqrt(42) >= 0);
	}

	@Test
	public void testprecision(){
		assertEquals(Math.sqrt(16), Sqrt.sqrt(16), Sqrt.EPSILON);
	}

	@Test
	public void testValidInput(){
		double t1 = Sqrt.sqrt(0.4);
		assertTrue(t1 > 0 && t1 < 1);

		double t2 = Sqrt.sqrt(21);
		assertTrue(t2 > 1);
	}

	@Test
	public void testBorne(){
		assertEquals(0, Sqrt.sqrt(0));
		assertEquals(1, Sqrt.sqrt(1));
	}

	@Test
	public void testBig(){
		double val = assertTimeoutPreemptively(Duration.ofSeconds(1), () -> Sqrt.sqrt(1e16));
		assertEquals(Math.sqrt(1e16), val, Sqrt.EPSILON);
	}

	@Test
	public void testInvalid(){
		assertThrows(IllegalArgumentException.class, () -> Sqrt.sqrt(-42));
	}
}
