// $Id: CoordinateListTest.cpp 1842 2006-09-07 15:28:03Z strk $
// 
// Test Suite for geos::geom::CoordinateList class.

// TUT
#include <tut.h>
// GEOS
#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateList.h>
#include <geos/geom/CoordinateArraySequence.h>
// STL
#include <string>
#include <vector>

namespace tut
{
    //
    // Test Group
    //

    // Common data used by tests
    struct test_coordinatelist_data
    {

        test_coordinatelist_data() {}
    };

    typedef test_group<test_coordinatelist_data> group;
    typedef group::object object;

    group test_coordinatelist_group("geos::geom::CoordinateList");

    //
    // Test Cases
    //

    // Test insert and erase
    template<>
    template<>
    void object::test<1>()
    {
		using geos::geom::Coordinate;
		
		const Coordinate a(0, 0);
		const Coordinate b(10, 10);
		const Coordinate c(20, 20);
		const Coordinate d(5, 5);

		geos::geom::CoordinateList::iterator it, it2;

		std::auto_ptr< std::vector<Coordinate> > col( new std::vector<Coordinate>() );
		col->push_back(a);
		col->push_back(b);
		col->push_back(c);

		// coordinates are copied
		geos::geom::CoordinateList clist(*col);

		ensure_equals( clist.size(), 3u );

		it = clist.begin();
		clist.insert(++it, d);

		ensure_equals( clist.size(), 4u );

		it = clist.begin();
		ensure_equals(*it, a);
		++it;
		ensure_equals(*it, d);
		++it;
		ensure_equals(*it, b);
		++it;
		ensure_equals(*it, c);


		it = clist.begin();
		++it; ++it;
		clist.erase(it);
		ensure_equals( clist.size(), 3u );

		it = clist.begin();
		ensure_equals(*it, a);
		++it;
		ensure_equals(*it, d);
		++it;
		ensure_equals(*it, c);

		clist.insert(clist.end(), b);

		ensure_equals( clist.size(), 4u );

		it = clist.begin(); ++it;
		it2 = it; ++it2; ++it2;
		clist.erase(it, it2);

		ensure_equals( clist.size(), 2u );

		it = clist.begin();
		ensure_equals(*it, a);
		++it;
		ensure_equals(*it, b);

	}


} // namespace tut
