package nxm.sys.test.junit.libg;

import java.util.List;

import org.junit.Before;
import org.junit.Test;

import nxm.sys.lib.DataFile;
import nxm.sys.lib.Midas;
import nxm.sys.lib.Table;
import nxm.sys.libg.LayerT5;
import nxm.sys.libg.Point3D;
import nxm.sys.test.junit.NMTestCase;

/**
 * Test class for LayerT5 This test will execute macros, the user may see them pop up.
 * @author Kevin Esterheld
 * @since NeXtMidas 3.9.0
 */
public class LayerT5Test extends NMTestCase {
  private LayerT5 lt5;

  public LayerT5Test (String methodName) {
    this(methodName, null);
  }

  public LayerT5Test (String methodName, Midas midas) {
    super(methodName, midas);
  }

  @Before
  public void setUp() {
    lt5 = new LayerT5();
    DataFile df = new DataFile(getMidas(), urlDat+"ellipse5000.prm");
    df.open();

    lt5.setFile(df,null,null);
    lt5.process();
    lt5.clear();
    Table pnt = new Table("{POS=(45.0,0,0),ELPS=(30000.0, 7000.0, 0),NAME=JEREMY}");
    lt5.setPoint(0, pnt);
    pnt = new Table("{POS=(60.0,15.0,0),ELPS=(30000.0, 7000.0, 60),NAME=JAY}");
    lt5.setPoint(1, pnt);
    pnt = new Table("{POS=(105,15.0,0),ELPS=(30000.0, 7000.0, 105.0),NAME=JEFF}");
    lt5.setPoint(2, pnt);
    df.close();
  }

  @Test
  public void testClear () {
    lt5.clear();
    assertEquals("The count of points should be 0", 0, lt5.getPointsSize());
    assertEquals("the size of pointsNulled should be 0", 0, lt5.getPointsNulledSize());
    assertNull("after clearing, the first point should be null", lt5.getPoint(0));
  }

  @Test
  public void testDeletePoint () {
    assertNotNull(lt5.getPoint(1));
    lt5.deletePoint(1);
    assertNull(lt5.getPoint(1));
    assertEquals("The size of points nulled should be 1", 1, lt5.getPointsNulledSize());
    assertEquals("The next index should be 1", 1, lt5.peekAtNextNulledIndex());
  }

  @Test
  public void testDeletePoints () {
    lt5.deletePoints(0, 1);
    for (int i = 0; i < 2; i++) {
      assertNull(lt5.getPoint(i));
    }
    assertEquals("the size of pointsNulled should be 2", 2, lt5.getPointsNulledSize());
    assertNotNull("We should still have a point at index 2", lt5.getPoint(2));
  }

  @Test
  public void testGetPointsAsList () {
    lt5.deletePoint(1);
    List<Point3D> layT5Pts = lt5.getPointsAsList();
    for (Point3D point : layT5Pts ) {
      assertNotNull("Nulled point should not be included when getting points as a List",point);
    }
  }
}