public void TestAdd()
        {
            var coordinates = new HugeCoordinateCollectionIndex(10);
            coordinates.Add(0, new CoordinateArrayCollection<GeoCoordinate>(
                new GeoCoordinate[] {
                    new GeoCoordinate(0, 1),
                    new GeoCoordinate(2, 3) }));
            Assert.Catch<InvalidOperationException>(() =>
            {
                coordinates.Add(0, null);
            });

            ICoordinateCollection actual;
            Assert.IsTrue(coordinates.TryGet(0, out actual));
            Assert.AreEqual(2, actual.Count);
            Assert.AreEqual(0, actual.ElementAt(0).Latitude);
            Assert.AreEqual(1, actual.ElementAt(0).Longitude);
            Assert.AreEqual(2, actual.ElementAt(1).Latitude);
            Assert.AreEqual(3, actual.ElementAt(1).Longitude);

            coordinates = new HugeCoordinateCollectionIndex(10);
            coordinates.Add(0, new CoordinateArrayCollection<GeoCoordinate>(
                new GeoCoordinate[] {
                    new GeoCoordinate(0, 1),
                    new GeoCoordinate(2, 3) }));
            Assert.Catch<InvalidOperationException>(() =>
            {
                coordinates.Add(0, null);
            });
            coordinates.Add(1, new CoordinateArrayCollection<GeoCoordinate>(
                new GeoCoordinate[] {
                    new GeoCoordinate(4, 5),
                    new GeoCoordinate(6, 7),
                    new GeoCoordinate(8, 9) }));
            Assert.Catch<InvalidOperationException>(() =>
            {
                coordinates.Add(1, null);
            });

            Assert.IsTrue(coordinates.TryGet(0, out actual));
            Assert.AreEqual(2, actual.Count);
            Assert.AreEqual(0, actual.ElementAt(0).Latitude);
            Assert.AreEqual(1, actual.ElementAt(0).Longitude);
            Assert.AreEqual(2, actual.ElementAt(1).Latitude);
            Assert.AreEqual(3, actual.ElementAt(1).Longitude);

            Assert.IsTrue(coordinates.TryGet(1, out actual));
            Assert.AreEqual(3, actual.Count);
            Assert.AreEqual(4, actual.ElementAt(0).Latitude);
            Assert.AreEqual(5, actual.ElementAt(0).Longitude);
            Assert.AreEqual(6, actual.ElementAt(1).Latitude);
            Assert.AreEqual(7, actual.ElementAt(1).Longitude);
            Assert.AreEqual(8, actual.ElementAt(2).Latitude);
            Assert.AreEqual(9, actual.ElementAt(2).Longitude);
        }
        public void TestRemove()
        {
            var coordinates = new HugeCoordinateCollectionIndex(10);
            coordinates.Add(0, new CoordinateArrayCollection<GeoCoordinate>(
                new GeoCoordinate[] { }));

            coordinates.Remove(0);

            ICoordinateCollection actual;
            Assert.IsFalse(coordinates.TryGet(0, out actual));
            Assert.Catch<KeyNotFoundException>(() =>
            {
                actual = coordinates[0];
            });

            coordinates = new HugeCoordinateCollectionIndex(10);
            coordinates.Add(0, null);

            coordinates.Remove(0);

            Assert.IsFalse(coordinates.TryGet(0, out actual));
            Assert.Catch<KeyNotFoundException>(() =>
            {
                actual = coordinates[0];
            });
        }
        public void TestDeserialize()
        {
            // build a coordinate collection.
            var coordinates = new HugeCoordinateCollectionIndex(100);
            coordinates.Add(0, new CoordinateArrayCollection<GeoCoordinate>(
                new GeoCoordinate[] {
                    new GeoCoordinate(0, 1),
                    new GeoCoordinate(2, 3) }));
            coordinates.Add(1, new CoordinateArrayCollection<GeoCoordinate>(
                new GeoCoordinate[] {
                    new GeoCoordinate(4, 5),
                    new GeoCoordinate(6, 7) }));

            // serialize/deserialize and test size.
            using (var stream = new MemoryStream())
            {
                coordinates.Serialize(stream);

                stream.Seek(0, SeekOrigin.Begin);

                coordinates = HugeCoordinateCollectionIndex.Deserialize(stream, false);

                ICoordinateCollection actual;
                Assert.IsTrue(coordinates.TryGet(0, out actual));
                Assert.AreEqual(2, actual.Count);
                Assert.AreEqual(0, actual.ElementAt(0).Latitude);
                Assert.AreEqual(1, actual.ElementAt(0).Longitude);
                Assert.AreEqual(2, actual.ElementAt(1).Latitude);
                Assert.AreEqual(3, actual.ElementAt(1).Longitude);

                Assert.IsTrue(coordinates.TryGet(1, out actual));
                Assert.AreEqual(2, actual.Count);
                Assert.AreEqual(4, actual.ElementAt(0).Latitude);
                Assert.AreEqual(5, actual.ElementAt(0).Longitude);
                Assert.AreEqual(6, actual.ElementAt(1).Latitude);
                Assert.AreEqual(7, actual.ElementAt(1).Longitude);
            }

            // build a coordinate collection.
            coordinates = new HugeCoordinateCollectionIndex(100);

            // serialize/deserialize and test size.
            using (var stream = new MemoryStream())
            {
                coordinates.Serialize(stream);

                stream.Seek(0, SeekOrigin.Begin);

                coordinates = HugeCoordinateCollectionIndex.Deserialize(stream, false);
                Assert.AreEqual(0, coordinates.LengthIndex);
                Assert.AreEqual(0, coordinates.LengthCoordinates);
            }

            // build a coordinate collection.
            coordinates = new HugeCoordinateCollectionIndex(100);
            coordinates.Add(0, null);

            // serialize/deserialize and test size.
            using (var stream = new MemoryStream())
            {
                coordinates.Serialize(stream);

                stream.Seek(0, SeekOrigin.Begin);

                coordinates = HugeCoordinateCollectionIndex.Deserialize(stream, false);
                Assert.AreEqual(1, coordinates.LengthIndex);
                Assert.AreEqual(0, coordinates.LengthCoordinates);
            }
        }
        public void TestNullVersusEmpty()
        {
            var coordinates = new HugeCoordinateCollectionIndex(10);
            coordinates.Add(0, new CoordinateArrayCollection<GeoCoordinate>(
                new GeoCoordinate[] { }));
            coordinates.Add(1, null);

            ICoordinateCollection actual;
            Assert.IsTrue(coordinates.TryGet(0, out actual));
            Assert.AreEqual(0, actual.Count);

            Assert.IsTrue(coordinates.TryGet(1, out actual));
            Assert.AreEqual(null, actual);

            Assert.IsFalse(coordinates.TryGet(2, out actual));
        }
        public void TestCompress()
        {
            // build a coordinate collection.
            var coordinates = new HugeCoordinateCollectionIndex(100);
            coordinates.Add(0, new CoordinateArrayCollection<GeoCoordinate>(
                new GeoCoordinate[] {
                    new GeoCoordinate(0, 0),
                    new GeoCoordinate(1, 1) }));
            coordinates.Add(1, new CoordinateArrayCollection<GeoCoordinate>(
                new GeoCoordinate[] {
                    new GeoCoordinate(2, 2),
                    new GeoCoordinate(3, 3) }));

            // compress.
            coordinates.Compress();

            // check if everything is still there.
            Assert.AreEqual(8, coordinates.LengthCoordinates);
            Assert.AreEqual(2, coordinates.LengthIndex);
            Assert.IsTrue(coordinates[0].ElementAt(0).Latitude == 0);
            Assert.IsTrue(coordinates[0].ElementAt(0).Longitude == 0);
            Assert.IsTrue(coordinates[0].ElementAt(1).Latitude == 1);
            Assert.IsTrue(coordinates[0].ElementAt(1).Longitude == 1);
            Assert.IsTrue(coordinates[1].ElementAt(0).Latitude == 2);
            Assert.IsTrue(coordinates[1].ElementAt(0).Longitude == 2);
            Assert.IsTrue(coordinates[1].ElementAt(1).Latitude == 3);
            Assert.IsTrue(coordinates[1].ElementAt(1).Longitude == 3);

            // build a coordinate collection and remove some data.
            coordinates = new HugeCoordinateCollectionIndex(100);
            coordinates.Add(0, new CoordinateArrayCollection<GeoCoordinate>(
                new GeoCoordinate[] {
                    new GeoCoordinate(0, 0),
                    new GeoCoordinate(1, 1) }));
            coordinates.Add(1, new CoordinateArrayCollection<GeoCoordinate>(
                new GeoCoordinate[] {
                    new GeoCoordinate(2, 2),
                    new GeoCoordinate(3, 3) }));
            coordinates.Remove(0);

            // compress.
            coordinates.Compress();

            // check if everything is still there.
            Assert.AreEqual(4, coordinates.LengthCoordinates);
            Assert.AreEqual(2, coordinates.LengthIndex);
            ICoordinateCollection actual;
            Assert.IsFalse(coordinates.TryGet(0, out actual));
            Assert.IsTrue(coordinates[1].ElementAt(0).Latitude == 2);
            Assert.IsTrue(coordinates[1].ElementAt(0).Longitude == 2);
            Assert.IsTrue(coordinates[1].ElementAt(1).Latitude == 3);
            Assert.IsTrue(coordinates[1].ElementAt(1).Longitude == 3);
        }