public void TestSerialize()
        {
            OsmSharp.Math.Random.StaticRandomGenerator.Set(116542346);

            var box = new GeoCoordinateBox(
                new GeoCoordinate(90, 180),
                new GeoCoordinate(-90, -180));
            var size = 5;
            var maxCollectionSize = 4;
            var referenceDictionary = new Dictionary<long, ICoordinateCollection>();
            var coordinates = new HugeCoordinateCollectionIndex(100);
            for (int idx = 0; idx < size; idx++)
            {
                var currentSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(maxCollectionSize) + 1;
                var coordinatesArray = new GeoCoordinate[currentSize];
                while (currentSize > 0)
                {
                    coordinatesArray[currentSize - 1] = box.GenerateRandomIn(OsmSharp.Math.Random.StaticRandomGenerator.Get());
                    currentSize--;
                }
                var coordinatesCollection = new CoordinateArrayCollection<GeoCoordinate>(coordinatesArray);
                referenceDictionary[idx] = coordinatesCollection;
                coordinates[idx] = coordinatesCollection;
            }

            coordinates.Trim();
            coordinates.Compress();

            byte[] data = null;
            using(var stream = new MemoryStream())
            {
                long length = coordinates.Serialize(stream);
                data = stream.ToArray();

                Assert.AreEqual(168, length);
                Assert.AreEqual(data.Length, length);
            }

            var result = HugeCoordinateCollectionIndex.Deserialize(new MemoryStream(data));

            // check result.
            for (int idx = 0; idx < size; idx++)
            {
                var referenceCollection = referenceDictionary[idx];
                var collection = result[idx];

                referenceCollection.Reset();
                collection.Reset();

                while (referenceCollection.MoveNext())
                {
                    Assert.IsTrue(collection.MoveNext());
                    Assert.AreEqual(referenceCollection.Latitude, collection.Latitude);
                    Assert.AreEqual(referenceCollection.Longitude, collection.Longitude);
                }
                Assert.IsFalse(collection.MoveNext());
            }

            result = HugeCoordinateCollectionIndex.Deserialize(new MemoryStream(data), true);

            // check result.
            for (int idx = 0; idx < size; idx++)
            {
                var referenceCollection = referenceDictionary[idx];
                var collection = result[idx];

                referenceCollection.Reset();
                collection.Reset();

                while (referenceCollection.MoveNext())
                {
                    Assert.IsTrue(collection.MoveNext());
                    Assert.AreEqual(referenceCollection.Latitude, collection.Latitude);
                    Assert.AreEqual(referenceCollection.Longitude, collection.Longitude);
                }
                Assert.IsFalse(collection.MoveNext());
            }
        }
        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);
        }