package Test_W01H06a_Cartesianas;

import W01H06a_Cartesianas.Point;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

/**
 *
 * @author Manel Guerrero
 */
public class PointJUnitTest {

    Point[] v = new Point[8];
    static final double DELTA = 0.0001;

    public PointJUnitTest() {
    }

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
        //
        for (int i = 0; i < v.length; i++) {
            v[i] = new Point(Integer.signum((int)Math.round(Math.cos(i * Math.PI / 4))),
                             Integer.signum((int)Math.round(Math.sin(i * Math.PI / 4))));
        }
        //
        for (int i = 0; i < v.length; i++) {
            System.out.print(Integer.signum((int)Math.round(Math.cos(i * Math.PI / 4))) + " , ");
            System.out.println(Integer.signum((int)Math.round(Math.sin(i * Math.PI / 4))));
        }
        /* EQUIVAL A:
        v[0] = new Point(1, 0);
        v[1] = new Point(1, 1);
        v[2] = new Point(0, 1);
        v[3] = new Point(-1, 1);
        v[4] = new Point(-1, 0);
        v[5] = new Point(-1, -1);
        v[6] = new Point(0, -1);
        v[7] = new Point(1, -1);
        */
    }

    @After
    public void tearDown() {
        v = null;
    }

    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    @Test
    public void conversionToPolarCheck() {
        for (int i = 0; i < v.length; i++) {
            System.out.print("p" + i + ": ");
            System.out.println(v[i]);
            System.out.print("p" + i + ": ");
            System.out.println(v[i].toStringPolar());
            System.out.println();
            System.out.println("");
            assertEquals(45 * i, v[i].getAngulo(), DELTA);
            if (i % 2 == 0) {
                assertEquals(1, v[i].getR(), DELTA);
            } else {
                assertEquals(Math.sqrt(2), v[i].getR(), DELTA);
            }
        }
    }
}
