From 440c1c62f1a1b71dc51e252e616860f69daa6233 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 22 Aug 2019 10:17:32 -0400 Subject: [PATCH 1/2] fix: Fixed a bug with the IcdOrderedDict index setter that was creating additional values --- CHANGELOG.md | 3 +++ .../Collections/IcdOrderedDictionaryTest.cs | 24 +++++++++++++------ .../Collections/IcdOrderedDictionary.cs | 16 ++++++------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 188161c..572ca47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + - Fixed a bug with the IcdOrderedDict index setter that was creating additional values + ## [8.7.0] - 2019-06-24 ### Added - IcdXmlException exposes line number and position properties diff --git a/ICD.Common.Utils.Tests/Collections/IcdOrderedDictionaryTest.cs b/ICD.Common.Utils.Tests/Collections/IcdOrderedDictionaryTest.cs index dc6effd..65b6931 100644 --- a/ICD.Common.Utils.Tests/Collections/IcdOrderedDictionaryTest.cs +++ b/ICD.Common.Utils.Tests/Collections/IcdOrderedDictionaryTest.cs @@ -69,16 +69,26 @@ namespace ICD.Common.Utils.Tests.Collections [Test] public void IndexerTest() { - IcdOrderedDictionary dict = new IcdOrderedDictionary - { - {0, 0}, - {1, 10}, - {-1, -10} - }; + // ReSharper disable UseObjectOrCollectionInitializer + IcdOrderedDictionary dict = new IcdOrderedDictionary(); + // ReSharper restore UseObjectOrCollectionInitializer + + dict[0] = 0; + dict[1] = 10; + dict[-1] = -10; + dict[-1] = -11; Assert.AreEqual(0, dict[0]); Assert.AreEqual(10, dict[1]); - Assert.AreEqual(-10, dict[-1]); + Assert.AreEqual(-11, dict[-1]); + + Assert.AreEqual(3, dict.Count); + + int[] expectedKeys = {-1, 0, 1 }; + int[] expectedValues = {-11, 0, 10}; + + Assert.AreEqual(expectedKeys, dict.Keys.ToArray()); + Assert.AreEqual(expectedValues, dict.Values.ToArray()); } #endregion diff --git a/ICD.Common.Utils/Collections/IcdOrderedDictionary.cs b/ICD.Common.Utils/Collections/IcdOrderedDictionary.cs index 3699b18..700cc54 100644 --- a/ICD.Common.Utils/Collections/IcdOrderedDictionary.cs +++ b/ICD.Common.Utils/Collections/IcdOrderedDictionary.cs @@ -32,13 +32,8 @@ namespace ICD.Common.Utils.Collections if (key == null) throw new ArgumentNullException("key"); - if (!ContainsKey(key)) - { - int index = m_OrderedKeys.AddSorted(key, m_Comparer); - m_ValuesOrderedByKey.Insert(index, value); - } - - m_Dictionary[key] = value; + Remove(key); + Add(key, value); } } @@ -109,9 +104,12 @@ namespace ICD.Common.Utils.Collections throw new ArgumentNullException("key"); if (m_Dictionary.ContainsKey(key)) - throw new ArgumentException("An item with the same key has already been added.", "key"); + throw new ArgumentOutOfRangeException("key", "An item with the same key has already been added."); - this[key] = value; + int index = m_OrderedKeys.AddSorted(key, m_Comparer); + m_ValuesOrderedByKey.Insert(index, value); + + m_Dictionary[key] = value; } public void Clear() From 5900f5974b844cd272aa8fe2ba31ccc23c8d96b9 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 22 Aug 2019 10:41:00 -0400 Subject: [PATCH 2/2] chore: Updating changelog, incrementing patch version --- CHANGELOG.md | 1 + ICD.Common.Utils/Properties/AssemblyInfo.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 572ca47..2f79dda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [8.7.1] - 2019-08-22 ### Changed - Fixed a bug with the IcdOrderedDict index setter that was creating additional values diff --git a/ICD.Common.Utils/Properties/AssemblyInfo.cs b/ICD.Common.Utils/Properties/AssemblyInfo.cs index 4c7d0d4..dc12f0d 100644 --- a/ICD.Common.Utils/Properties/AssemblyInfo.cs +++ b/ICD.Common.Utils/Properties/AssemblyInfo.cs @@ -4,4 +4,4 @@ using System.Reflection; [assembly: AssemblyCompany("ICD Systems")] [assembly: AssemblyProduct("ICD.Common.Utils")] [assembly: AssemblyCopyright("Copyright © ICD Systems 2019")] -[assembly: AssemblyVersion("8.7.0.0")] +[assembly: AssemblyVersion("8.7.1.0")]