public void TestRandomBlockTagSerializatonNonBeginPositionLimitedStreamRegression() { TagsTableCollectionIndex tagsIndex = new TagsTableCollectionIndex(); TagsCollection tagsCollection = new TagsCollection(); for (int i = 0; i < 101; i++) { int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10) + 1; for (int idx = 0; idx < tagCollectionSize; idx++) { int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10); tagsCollection.Add( string.Format("key_{0}", tagValue), string.Format("value_{0}", tagValue)); } uint tagsId = tagsIndex.Add(tagsCollection); } ITagsCollectionIndexReadonly tagsIndexReadonly = this.SerializeDeserializeBlockLimitedStream(tagsIndex, 10, 123); Assert.AreEqual(tagsIndex.Max, tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { ComparisonHelpers.CompareTags(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } }
public bool MatchesVisitor(string definition) { Mandate.ParameterNotNullOrEmpty(definition, "definition"); MemberProfileFieldSetting setting; try { setting = JsonConvert.DeserializeObject <MemberProfileFieldSetting>(definition); } catch (JsonReaderException) { throw new ArgumentException(string.Format("Provided definition is not valid JSON: {0}", definition)); } var value = _memberProfileFieldProvider.GetMemberProfileFieldValue(setting.Alias); switch (setting.Match) { case MemberProfileFieldSettingMatch.MatchesValue: return(string.Equals(setting.Value, value, StringComparison.InvariantCultureIgnoreCase)); case MemberProfileFieldSettingMatch.DoesNotMatchValue: return(!string.Equals(setting.Value, value, StringComparison.InvariantCultureIgnoreCase)); case MemberProfileFieldSettingMatch.GreaterThanValue: case MemberProfileFieldSettingMatch.GreaterThanOrEqualToValue: case MemberProfileFieldSettingMatch.LessThanValue: case MemberProfileFieldSettingMatch.LessThanOrEqualToValue: return(ComparisonHelpers.CompareValues(value, setting.Value, GetComparison(setting.Match))); default: return(false); } }
/// <summary> /// Compares what is in the complete list against the objects in the reference source. /// </summary> /// <param name="expected"></param> /// <param name="actual"></param> private void Compare(MemoryDataSource expected, List <ICompleteOsmGeo> actual) { var exectedList = new List <ICompleteOsmGeo>(); foreach (var node in expected.GetNodes()) { var completeNode = node; if (completeNode != null) { exectedList.Add(completeNode); } } foreach (var way in expected.GetWays()) { var completeWay = CompleteWay.CreateFrom(way, expected); if (completeWay != null) { exectedList.Add(completeWay); } } foreach (var relation in expected.GetRelations()) { var completeRelation = CompleteRelation.CreateFrom(relation, expected); if (completeRelation != null) { exectedList.Add(completeRelation); } } ComparisonHelpers.CompareComplete(exectedList, actual); }
public bool MatchesVisitor(string definition) { Mandate.ParameterNotNullOrEmpty(definition, "definition"); SessionSetting sessionSetting; try { sessionSetting = JsonConvert.DeserializeObject <SessionSetting>(definition); } catch (JsonReaderException) { throw new ArgumentException(string.Format("Provided definition is not valid JSON: {0}", definition)); } if (string.IsNullOrEmpty(sessionSetting.Key)) { throw new ArgumentNullException("key", "Session key not set"); } var keyExists = _sessionProvider.KeyExists(sessionSetting.Key); var value = string.Empty; if (keyExists) { value = _sessionProvider.GetValue(sessionSetting.Key); } switch (sessionSetting.Match) { case SessionSettingMatch.Exists: return(keyExists); case SessionSettingMatch.DoesNotExist: return(!keyExists); case SessionSettingMatch.MatchesValue: return(keyExists && value == sessionSetting.Value); case SessionSettingMatch.ContainsValue: return(keyExists && value.Contains(sessionSetting.Value)); case SessionSettingMatch.GreaterThanValue: case SessionSettingMatch.GreaterThanOrEqualToValue: case SessionSettingMatch.LessThanValue: case SessionSettingMatch.LessThanOrEqualToValue: return(keyExists && ComparisonHelpers.CompareValues(value, sessionSetting.Value, GetComparison(sessionSetting.Match))); default: return(false); } }
public void TestSimpleTagSerializatonNonBeginPosition() { TagsTableCollectionIndex tagsIndex = new TagsTableCollectionIndex(); TagsCollection tagsCollection = new TagsCollection(); tagsCollection.Add("key1", "value1"); uint tagsId = tagsIndex.Add(tagsCollection); ITagsCollectionIndexReadonly tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, 1201); Assert.AreEqual(tagsIndex.Max, tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { ComparisonHelpers.CompareTags(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } }
public void ComparisonHelpers_CompareValues_StringComparisons_ReturnsCorrectValues() { // Arrange const string value1 = "a"; const string value2 = "b"; const string value3 = "c"; // Act var result = ComparisonHelpers.CompareValues(value2, value1, Comparison.GreaterThan); var result2 = ComparisonHelpers.CompareValues(value2, value2, Comparison.GreaterThan); var result3 = ComparisonHelpers.CompareValues(value2, value3, Comparison.GreaterThan); var result4 = ComparisonHelpers.CompareValues(value2, value1, Comparison.GreaterThanOrEqual); var result5 = ComparisonHelpers.CompareValues(value2, value2, Comparison.GreaterThanOrEqual); var result6 = ComparisonHelpers.CompareValues(value2, value3, Comparison.GreaterThanOrEqual); var result7 = ComparisonHelpers.CompareValues(value2, value1, Comparison.LessThan); var result8 = ComparisonHelpers.CompareValues(value2, value2, Comparison.LessThan); var result9 = ComparisonHelpers.CompareValues(value2, value3, Comparison.LessThan); var result10 = ComparisonHelpers.CompareValues(value2, value1, Comparison.LessThanOrEqual); var result11 = ComparisonHelpers.CompareValues(value2, value2, Comparison.LessThanOrEqual); var result12 = ComparisonHelpers.CompareValues(value2, value3, Comparison.LessThanOrEqual); // Assert Assert.IsTrue(result); Assert.IsFalse(result2); Assert.IsFalse(result3); Assert.IsTrue(result4); Assert.IsTrue(result5); Assert.IsFalse(result6); Assert.IsFalse(result7); Assert.IsFalse(result8); Assert.IsTrue(result9); Assert.IsFalse(result10); Assert.IsTrue(result11); Assert.IsTrue(result12); }
public void TestRandomPartialTagSerializaton() { TagsTableCollectionIndex tagsIndex = new TagsTableCollectionIndex(); TagsCollection tagsCollection = new TagsCollection(); for (int i = 0; i < 100; i++) { int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10) + 1; for (int idx = 0; idx < tagCollectionSize; idx++) { int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10); tagsCollection.Add( string.Format("key_{0}", tagValue), string.Format("value_{0}", tagValue)); } uint tagsId = tagsIndex.Add(tagsCollection); } uint from = 40; uint to = 50; ITagsCollectionIndexReadonly tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to); Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { if (idx >= from && idx < to) { ComparisonHelpers.CompareTags(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } else { Assert.IsNull(tagsIndexReadonly.Get(idx)); } } from = 0; to = 100; tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to); Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { if (idx >= from && idx < to) { ComparisonHelpers.CompareTags(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } else { Assert.IsNull(tagsIndexReadonly.Get(idx)); } } from = 10; to = 1000; tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to); Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { if (idx >= from && idx < to) { ComparisonHelpers.CompareTags(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } else { Assert.IsNull(tagsIndexReadonly.Get(idx)); } } }