import org.junit.Assert;
import org.junit.Test;

/**
 * Created by IntelliJ IDEA.
 * User: gloyaute
 * Date: 10 06 2011
 * Time: 21:11:35
 * To change this template use File | Settings | File Templates.
 */

public class TestPolyLine {

    @Test
    public void testNegativeConstructor() {
        try {
            PolyLine polyLine = new PolyLine(-10);
        } catch(NegativeArraySizeException e) {
            Assert.assertTrue(true);
        }
    }

    @Test
    public void testZeroConstructor() {
        try {
            PolyLine polyLine = new PolyLine(0);
        } catch(NegativeArraySizeException e) {
            Assert.fail();
        }
    }

    @Test
    public void testPointCapacity() {
        try {
            PolyLine polyLine = new PolyLine(10);
            Assert.assertEquals(10, polyLine.pointCapacity());
        } catch(NegativeArraySizeException e) {
            Assert.fail();
        }
    }

    @Test
    public void testAdd() {
        try {
            PolyLine polyLine = new PolyLine(10);

            Assert.assertEquals(0, polyLine.pointCount());
            for (int i = 0; i < 10; ++i) {
                polyLine.add(new Point(1, 2));
            }
            Assert.assertEquals(10, polyLine.pointCount());
        } catch(NegativeArraySizeException e) {
            Assert.fail();
        }
    }

    @Test
    public void testAddFail() {
        try {
            PolyLine polyLine = new PolyLine(10);

            Assert.assertEquals(0, polyLine.pointCount());
            for (int i = 0; i < 10; ++i) {
                polyLine.add(new Point(1, 2));
            }
            Assert.assertEquals(10, polyLine.pointCount());

            try {
                polyLine.add(new Point(1, 2));
            } catch(ArrayStoreException e) {
                Assert.assertTrue(true);
            }

        } catch(NegativeArraySizeException e) {
            Assert.fail();
        }
    }

    @Test
    public void testPointCount() {
        try {
            PolyLine polyLine = new PolyLine(10);
            Assert.assertEquals(0, polyLine.pointCount());
            polyLine.add(new Point(1, 2));
            Assert.assertEquals(1, polyLine.pointCount());
        } catch(NegativeArraySizeException e) {
            Assert.fail();
        }
    }

    @Test
    public void testContains() {
        try {
            PolyLine polyLine = new PolyLine(10);

            Assert.assertEquals(0, polyLine.pointCount());
            for (int i = 0; i < 10; ++i) {
                polyLine.add(new Point(i, 2 * i));
            }
            Assert.assertEquals(10, polyLine.pointCount());

            Assert.assertTrue(polyLine.contains(new Point(8, 16)));
            Assert.assertFalse(polyLine.contains(new Point(9, 9)));
        } catch(NegativeArraySizeException e) {
            Assert.fail();
        }
    }
}
