public void TestTrim() { OsmSharp.Math.Random.StaticRandomGenerator.Set(116542346); var box = new GeoCoordinateBox( new GeoCoordinate(90, 180), new GeoCoordinate(-90, -180)); var size = 100; var maxCollectionSize = 4; var referenceDictionary = new Dictionary<long, ICoordinateCollection>(); var coordinates = new HugeCoordinateCollectionIndex(400); 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; } // execute the trim. coordinates.Trim(); // check result. for (int idx = 0; idx < size; idx++) { var referenceCollection = referenceDictionary[idx]; var collection = coordinates[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 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()); } }