public void DictionariesAreEqualWhenBothAreEmpty() { var dict1 = new Dictionary <int, int>(); var dict2 = new Dictionary <int, int>(); Assert.IsTrue(DictionaryUtility.AreEqual(dict1, dict2)); }
public void GetOrAddItemAddCustom() { var dict = new Dictionary <int, int>(); Assert.AreEqual(3, DictionaryUtility.GetOrAddValue(dict, 2, () => 3)); Assert.AreEqual(3, dict[2]); }
public void GetOrAddItemAdd() { var dict = new Dictionary <int, List <int> >(); Assert.AreEqual(0, DictionaryUtility.GetOrAddValue(dict, 1).Count); Assert.AreEqual(0, dict[1].Count); }
public void GetOrAddItemAddValue() { var dict = new Dictionary <int, int>(); Assert.AreEqual(0, DictionaryUtility.GetOrAddValue(dict, 0)); Assert.AreEqual(0, dict[0]); }
public void DictionaryUtility_MergeLastValues_1() { Dictionary <string, int> first = new Dictionary <string, int> { { "one", 1 }, { "two", 2 }, { "three", 3 } }; Dictionary <string, int> second = new Dictionary <string, int> { { "three", 4 }, { "four", 5 }, { "five", 6 } }; Dictionary <string, int> result = DictionaryUtility.MergeLastValues ( first, second ); Assert.AreEqual(5, result.Count); Assert.AreEqual(4, result["three"]); }
public void DictionaryUtility_MergeLastValues_2() { Dictionary <string, int> first = new Dictionary <string, int>(); Dictionary <string, int> second = null; DictionaryUtility.MergeLastValues(first, second); }
public void DictionaryUtility_MergeWithConflicts_3() { Dictionary <string, int> first = new Dictionary <string, int>(); Dictionary <string, int> second = null; DictionaryUtility.MergeWithConflicts(first, second); }
public void GetOrAddItemExistingCustom() { var dict = new Dictionary <int, int>(); dict[2] = 4; Assert.AreEqual(4, DictionaryUtility.GetOrAddValue(dict, 2, () => 3)); Assert.AreEqual(4, dict[2]); }
public void DictionariesAreEqualWhenSameInstance() { var dict1 = new Dictionary <int, int> { { 1, 1 }, { 2, 2 }, { 3, 3 } }; Assert.IsTrue(DictionaryUtility.AreEqual(dict1, dict1)); }
public static void ToDictionary_Should_Throws_Exception_With_Null_Value() { // arrange / act / assert ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => DictionaryUtility.ToDictionary(null)); Assert.Equal(ex.ParamName, "source"); }
public void GetOrAddItemExists() { var dict = new Dictionary <int, List <int> >(); var list = new List <int>(); dict[2] = list; Assert.AreSame(list, DictionaryUtility.GetOrAddValue(dict, 2)); Assert.AreSame(list, dict[2]); }
public void GetValueOrDefaultWithDefault() { Dictionary <int, int> dict = new Dictionary <int, int> { { 2, 4 }, { 3, 6 } }; Assert.AreEqual(4, DictionaryUtility.GetValueOrDefault(dict, 2, -1)); Assert.AreEqual(-1, DictionaryUtility.GetValueOrDefault(dict, 1, -1)); }
public void GetValueOrDefaultWithFunc() { var dict = new Dictionary <int, int> { { 2, 4 }, { 3, 6 } }; Assert.AreEqual(4, DictionaryUtility.GetValueOrDefault(dict, 2, () => - 2)); Assert.AreEqual(-2, DictionaryUtility.GetValueOrDefault(dict, 1, () => - 2)); }
public void DictionariesAreEqual() { Dictionary <int, int> dict1 = new Dictionary <int, int> { { 1, 1 }, { 2, 2 }, { 3, 3 } }; Dictionary <int, int> dict2 = new Dictionary <int, int> { { 1, 1 }, { 2, 2 }, { 3, 3 } }; Assert.IsTrue(DictionaryUtility.AreEqual(dict1, dict2)); }
public void ReadOnlyDictionariesAreNotEqualWhenValueIsDifferent() { var dict1 = new Dictionary <int, int> { { 1, 1 }, { 2, 2 }, { 3, 3 } }.AsReadOnly(); var dict2 = new Dictionary <int, int> { { 1, 2 }, { 2, 2 }, { 3, 3 } }.AsReadOnly(); Assert.IsFalse(DictionaryUtility.AreEqual(dict1, dict2)); }
public void ReadOnlyDictionariesAreEqual() { var dict1 = new Dictionary <int, int> { { 1, 1 }, { 2, 2 }, { 3, 3 } }.AsReadOnly(); var dict2 = new Dictionary <int, int> { { 1, 1 }, { 2, 2 }, { 3, 3 } }.AsReadOnly(); Assert.IsTrue(DictionaryUtility.AreEqual(dict1, dict2)); }
public void DictionariesAreEqualWhenUsingCustomComparer() { var dict1 = new Dictionary <int, int> { { 1, 1 }, { 2, 2 }, { 3, 3 } }; var dict2 = new Dictionary <int, int> { { 1, 1 }, { 2, 2 }, { 3, 3 } }; Assert.IsTrue(DictionaryUtility.AreEqual(dict1, dict2, new GenericEqualityComparer <int>((x, y) => x == y))); }
public void DictionariesAreEqualWhenItemsAreAddedOutOfOrder() { var dict1 = new Dictionary <int, int> { { 1, 1 }, { 2, 2 }, { 3, 3 } }; var dict2 = new Dictionary <int, int> { { 1, 1 }, { 3, 3 }, { 2, 2 } }; Assert.IsTrue(DictionaryUtility.AreEqual(dict1, dict2)); }
public void GetValueOrDefaultWithDefault() { var dict = new Dictionary <int, int> { { 2, 4 }, { 3, 6 } }; #pragma warning disable CS0618 // Type or member is obsolete Assert.AreEqual(4, DictionaryUtility.GetValueOrDefault(dict, 2, -1)); Assert.AreEqual(-1, DictionaryUtility.GetValueOrDefault(dict, 1, -1)); #pragma warning restore CS0618 // Type or member is obsolete }
public void DictionariesAreNotEqualWhenFirstIsMissingItem() { var dict1 = new Dictionary <int, int> { { 1, 1 }, { 2, 2 } }; var dict2 = new Dictionary <int, int> { { 1, 1 }, { 2, 2 }, { 3, 3 } }; Assert.IsFalse(DictionaryUtility.AreEqual(dict1, dict2)); }
public void DictionariesArNotEqualWhenValueIsdifferent() { var dict1 = new Dictionary <int, int> { { 1, 1 }, { 2, 2 }, { 3, 3 } }; var dict2 = new Dictionary <int, int> { { 1, 2 }, { 2, 2 }, { 3, 3 } }; Assert.IsFalse(DictionaryUtility.AreEqual(dict1, dict2)); }
public void DictionariesAreEqualWhenUsingCustomKeyComparer() { var comparer = new GenericEqualityComparer <int>((x, y) => x == y, HashCodeUtility.GetPersistentHashCode); var dict1 = new Dictionary <int, int>(comparer) { { 1, 1 }, { 2, 2 }, { 3, 3 } }; var dict2 = new Dictionary <int, int>(comparer) { { 1, 1 }, { 2, 2 }, { 3, 3 } }; Assert.IsTrue(DictionaryUtility.AreEqual(dict1, dict2)); }
public static void ToDictionary_Should_Return_A_Dictionary_With_Object_Values() { // arrange PlainObject obj = new PlainObject { TestInt = 5, TestString = "test", TestNull = null }; // act var dic = DictionaryUtility.ToDictionary(obj); // assert Assert.Equal(dic.Count, 2); Assert.Equal(dic["TestInt"], "5"); Assert.Equal(dic["TestString"], "test"); }
public void DictionaryUtility_MergeWithConflicts_1() { Dictionary <string, int> first = new Dictionary <string, int> { { "one", 1 }, { "two", 2 }, { "three", 3 } }; Dictionary <string, int> second = new Dictionary <string, int> { { "three", 3 }, { "four", 4 }, { "five", 5 } }; DictionaryUtility.MergeWithConflicts ( first, second ); }
public void DictionaryUtility_MergeWithConflicts_2() { Dictionary <string, int> first = new Dictionary <string, int> { { "one", 1 }, { "two", 2 }, { "three", 3 } }; Dictionary <string, int> second = new Dictionary <string, int> { { "four", 4 }, { "five", 5 }, { "six", 6 } }; Dictionary <string, int> result = DictionaryUtility.MergeWithConflicts ( first, second ); Assert.AreEqual(6, result.Count); }