private static void VerifyHashtable(ComparableHashtable hash1, HashtableEx hash2, IEqualityComparer ikc) { if (hash2 == null) { Assert.AreEqual(0, hash1.Count); } else { // Make sure that construtor imports all keys and values Assert.AreEqual(hash2.Count, hash1.Count); for (int i = 0; i < 100; i++) { Assert.IsTrue(hash1.ContainsKey(i)); Assert.IsTrue(hash1.ContainsValue(i)); } // Make sure the new and old hashtables are not linked hash2.Clear(); for (int i = 0; i < 100; i++) { Assert.IsTrue(hash1.ContainsKey(i)); Assert.IsTrue(hash1.ContainsValue(i)); } } Assert.AreEqual(ikc, hash1.EqualityComparer); Assert.IsFalse(hash1.IsFixedSize); Assert.IsFalse(hash1.IsReadOnly); Assert.IsFalse(hash1.IsSynchronized); // Make sure we can add to the hashtable int count = hash1.Count; for (int i = count; i < count + 100; i++) { hash1.Add(i, i); Assert.IsTrue(hash1.ContainsKey(i)); Assert.IsTrue(hash1.ContainsValue(i)); } }
public void ContainsKey_EqualObjects() { var hash1 = new HashtableEx(); Helpers.PerformActionOnAllHashtableWrappers(hash1, hash2 => { var foo1 = new Foo() { StringValue = "Goodbye" }; var foo2 = new Foo() { StringValue = "Goodbye" }; hash2.Add(foo1, 101); Assert.IsTrue(hash2.ContainsKey(foo2)); Assert.IsTrue(hash2.Contains(foo2)); int i1 = 0x10; int i2 = 0x100; long l1 = (((long)i1) << 32) + i2; // Create two longs with same hashcode long l2 = (((long)i2) << 32) + i1; hash2.Add(l1, 101); hash2.Add(l2, 101); // This will cause collision bit of the first entry to be set Assert.IsTrue(hash2.ContainsKey(l1)); Assert.IsTrue(hash2.Contains(l1)); hash2.Remove(l1); // Remove the first item Assert.IsFalse(hash2.ContainsKey(l1)); Assert.IsFalse(hash2.Contains(l1)); Assert.IsTrue(hash2.ContainsKey(l2)); Assert.IsTrue(hash2.Contains(l2)); }); }
public void Ctor_IDictionary_IEqualityComparer() { // No exception var hash1 = new ComparableHashtable(new HashtableEx(), null); Assert.AreEqual(0, hash1.Count); hash1 = new ComparableHashtable(new HashtableEx(new HashtableEx(new HashtableEx(new HashtableEx(new HashtableEx(), null), null), null), null), null); Assert.AreEqual(0, hash1.Count); // Null comparer HashtableEx hash2 = Helpers.CreateIntHashtable(100); hash1 = new ComparableHashtable(hash2, null); VerifyHashtable(hash1, hash2, null); // Custom comparer hash2 = Helpers.CreateIntHashtable(100); IEqualityComparer comparer = StringComparer.CurrentCulture; hash1 = new ComparableHashtable(hash2, comparer); VerifyHashtable(hash1, hash2, comparer); }
public void Clone(int count) { HashtableEx hash1 = Helpers.CreateStringHashtable(count); Helpers.PerformActionOnAllHashtableWrappers(hash1, hash2 => { HashtableEx clone = (HashtableEx)hash2.Clone(); Assert.AreEqual(hash2.Count, clone.Count); Assert.AreEqual(hash2.IsSynchronized, clone.IsSynchronized); Assert.AreEqual(hash2.IsFixedSize, clone.IsFixedSize); Assert.AreEqual(hash2.IsReadOnly, clone.IsReadOnly); for (int i = 0; i < clone.Count; i++) { string key = "Key_" + i; string value = "Value_" + i; Assert.IsTrue(clone.ContainsKey(key)); Assert.IsTrue(clone.ContainsValue(value)); Assert.AreEqual(value, clone[key]); } }); }
public void AddRemove_LargeAmountNumbers() { // Generate a random 100,000 array of ints as test data var inputData = new int[100000]; var random = new Random(341553); for (int i = 0; i < inputData.Length; i++) { inputData[i] = random.Next(7500000, int.MaxValue); } var hash = new HashtableEx(); int count = 0; foreach (long number in inputData) { hash.Add(number, count++); } count = 0; foreach (long number in inputData) { Assert.AreEqual(hash[number], count); Assert.IsTrue(hash.ContainsKey(number)); count++; } foreach (long number in inputData) { hash.Remove(number); } Assert.AreEqual(0, hash.Count); }
public ComparableHashtable(HashtableEx d, float loadFactor, IEqualityComparer ikc) : base(d, loadFactor, ikc) { }
public ComparableHashtable(HashtableEx d, IEqualityComparer ikc) : base(d, ikc) { }
public ComparableHashtable(HashtableEx d, float loadFactor) : base(d, loadFactor) { }
public ComparableHashtable(HashtableEx h) : base(h) { }