changeset 103:8022850f7fd7

Re #48: Collection equality * Add method for dictionary equality
author IBBoard <dev@ibboard.co.uk>
date Tue, 26 Apr 2011 14:32:18 +0000
parents 797aa3d2caa4
children 80df73deb8fc
files Collections/Collections.cs
diffstat 1 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Collections/Collections.cs	Tue Apr 26 14:16:27 2011 +0000
+++ b/Collections/Collections.cs	Tue Apr 26 14:32:18 2011 +0000
@@ -12,7 +12,7 @@
 		{
 		}
 
-		public static bool AreEqual (IList<int> list1, IList<int> list2)
+		public static bool AreEqual(IList<int> list1, IList<int> list2)
 		{
 			bool equal = true;
 
@@ -25,7 +25,7 @@
 				else
 				{
 					int length = list1.Count;
-					
+
 					for (int i = 0; i < length; i++)
 					{
 						if (!EqualityChecker.AreEqual(list1[i], list2[i]))
@@ -39,6 +39,32 @@
 
 			return equal;
 		}
+
+		public static bool AreEqual(IDictionary<string, int> dict1, IDictionary<string, int> dict2)
+		{
+			bool equal = true;
+
+			if (!EqualityChecker.AreEqual(dict1, dict2))
+			{
+				if (dict1.Count != dict2.Count)
+				{
+					equal = false;
+				}
+				else
+				{
+					foreach (KeyValuePair<string, int> pair in dict1)
+					{
+						if (!dict2.ContainsKey(pair.Key) || !EqualityChecker.AreEqual(pair.Value, dict2[pair.Key]))
+						{
+							equal = false;
+							break;
+						}
+					}
+				}
+			}
+
+			return equal;
+		}
 	}
 }