/// <summary> /// Tests an empty tags collection. /// </summary> protected void TestTagsCollectionSimple() { TagsCollectionBase collection = new TagsCollection(); collection["simple"] = "yes"; Assert.IsTrue(collection.ContainsKey("simple")); Assert.IsTrue(collection.ContainsKeyValue("simple", "yes")); Assert.AreEqual("yes", collection["simple"]); Assert.AreEqual(1, collection.Count); }
public void TestSimpleTagsCollectionSimple() { var collection = new TagsCollection(); collection["simple"] = "yes"; Assert.IsTrue(collection.ContainsKey("simple")); Assert.IsTrue(collection.ContainsKeyValue("simple", "yes")); Assert.AreEqual("yes", collection["simple"]); Assert.AreEqual(1, collection.Count); }
/// <summary> /// Compares two tag collection for indentical content. /// </summary> /// <param name="expectedTags"></param> /// <param name="foundTags"></param> private void CompareTags(TagsCollection expectedTags, TagsCollection foundTags) { if (expectedTags == null) { Assert.IsNull(foundTags); } else { Assert.IsNotNull(foundTags); Assert.AreEqual(expectedTags.Count, foundTags.Count); foreach (Tag expectedTag in expectedTags) { Assert.IsTrue(foundTags.ContainsKeyValue(expectedTag.Key, expectedTag.Value)); } } }
/// <summary> /// Tests the given tags collection index. /// </summary> /// <param name="tagsCollectionIndex"></param> protected void TestTagsCollectionIndex(ITagsCollectionIndex tagsCollectionIndex) { Dictionary <uint, TagsCollection> addedTags = new Dictionary <uint, TagsCollection>(); for (int i = 0; i < 100; i++) { SimpleTagsCollection tagsCollection = new SimpleTagsCollection(); int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3) + 1; for (int idx = 0; idx < tagCollectionSize; idx++) { int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3); tagsCollection.Add( string.Format("key_{0}", tagValue), string.Format("value_{0}", tagValue)); } int addCount = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(2) + 1; for (int idx = 0; idx < addCount; idx++) { uint tagsId = tagsCollectionIndex.Add(tagsCollection); addedTags[tagsId] = tagsCollection; TagsCollection indexTags = tagsCollectionIndex.Get(tagsId); Assert.AreEqual(tagsCollection.Count, indexTags.Count); foreach (Tag tag in tagsCollection) { Assert.IsTrue(indexTags.ContainsKeyValue(tag.Key, tag.Value)); } } } // check the index. foreach (KeyValuePair <uint, TagsCollection> pair in addedTags) { TagsCollection indexTags = tagsCollectionIndex.Get(pair.Key); Assert.AreEqual(pair.Value.Count, indexTags.Count); foreach (Tag tag in pair.Value) { Assert.IsTrue(indexTags.ContainsKeyValue(tag.Key, tag.Value)); } } }
public void Scene2DSimpleSerializeDeserializeTest() { // create the MapCSS image source. var imageSource = new MapCSSDictionaryImageSource(); // load mapcss style interpreter. var mapCSSInterpreter = new MapCSSInterpreter( Assembly.GetExecutingAssembly().GetManifestResourceStream( "OsmSharp.UI.Test.Unittests.Data.MapCSS.test.mapcss"), imageSource); // initialize the data source. var xmlSource = new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream( "OsmSharp.UI.Test.Unittests.Data.test.osm")); IEnumerable <OsmGeo> dataSource = xmlSource; MemoryDataSource source = MemoryDataSource.CreateFrom(xmlSource); // get data. var scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16); var projection = new WebMercator(); GeoCoordinateBox box = null; foreach (var osmGeo in dataSource) { CompleteOsmGeo completeOsmGeo = null; switch (osmGeo.Type) { case OsmGeoType.Node: completeOsmGeo = CompleteNode.CreateFrom(osmGeo as Node); break; case OsmGeoType.Way: completeOsmGeo = CompleteWay.CreateFrom(osmGeo as Way, source); break; case OsmGeoType.Relation: completeOsmGeo = CompleteRelation.CreateFrom(osmGeo as Relation, source); break; } // update box. if (completeOsmGeo != null) { if (box == null) { box = completeOsmGeo.BoundingBox; } else if (completeOsmGeo.BoundingBox != null) { box = box + completeOsmGeo.BoundingBox; } } // translate each object into scene object. mapCSSInterpreter.Translate(scene, projection, source, osmGeo as OsmGeo); } // create the stream. TagsCollectionBase metaTags = new TagsCollection(); metaTags.Add("SomeTestKey", "SomeTestValue"); var stream = new MemoryStream(); scene.Serialize(stream, true, metaTags); // deserialize the stream. metaTags = null; stream.Seek(0, SeekOrigin.Begin); IPrimitives2DSource sceneSource = Scene2D.Deserialize(stream, true, out metaTags); // test meta tags. Assert.IsTrue(metaTags.ContainsKeyValue("SomeTestKey", "SomeTestValue")); if (box != null) { // query both and get the same results. int counter = 100; var rand = new Random(); while (counter > 0) { var queryBox = new GeoCoordinateBox( box.GenerateRandomIn(rand), box.GenerateRandomIn(rand)); var zoomFactor = (float)projection.ToZoomFactor(15); View2D testView = View2D.CreateFromBounds( projection.LatitudeToY(queryBox.MaxLat), projection.LongitudeToX(queryBox.MinLon), projection.LatitudeToY(queryBox.MinLat), projection.LongitudeToX(queryBox.MaxLon)); var testScene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16); IEnumerable <Primitive2D> primitives = sceneSource.Get(testView, zoomFactor); // var resultIndex = new HashSet<Scene2DPrimitive>(testScene.Get(testView, zoomFactor)); // var resultReference = new HashSet<Scene2DPrimitive>(scene.Get(testView, zoomFactor)); //Assert.AreEqual(resultReference.Count, resultIndex.Count); //foreach (var data in resultIndex) //{ // Assert.IsTrue(resultReference.Contains(data)); //} //foreach (var data in resultReference) //{ // Assert.IsTrue(resultIndex.Contains(data)); //} counter--; } } }