public void Dispose_ShouldClear() { // Arrange Dictionary <int, string> dictionary = new(SampleDictionary.Reverse()); Fictionary <int, string, GenericEqualityComparer <int> > fictionary = DefaultFictionary <int, string> .Create(); foreach (KeyValuePair <int, string> item in SampleItems) { fictionary.TryAdd(item.Key, item.Value); fictionary.TryAdd(-item.Key, item.Key.ToString(CultureInfo.InvariantCulture)); } // Act fictionary.Dispose(); Assert.Empty(fictionary); foreach (KeyValuePair <int, string> kv in SampleDictionary.ToList().Mix()) { fictionary.Add(kv.Key, kv.Value); } // Assert Assert.Empty(dictionary.Except(fictionary)); Assert.Empty(fictionary.Except(dictionary)); }
public int Fictionary() { int count = _fictionaries.Length; for (int i = 0; i != count; ++i) { _fictionaries[i] = DefaultFictionary <DateTimeOffset, long> .Create(); } return(PopulateDictionaries(_fictionaries)); }
public void RecycledFictionaries_ShouldBehaveCorrectly() { // Arrange const int count = 13; var dictionaries = new Dictionary <DateTimeOffset, long> [count]; var fictionaries = new Fictionary <DateTimeOffset, long, GenericEqualityComparer <DateTimeOffset> > [count]; for (int i = 0; i != count; ++i) { dictionaries[i] = new Dictionary <DateTimeOffset, long>(); fictionaries[i] = DefaultFictionary <DateTimeOffset, long> .Create(); } // Act for (int upper = 1; upper <= count; ++upper) { for (int i = 0; i < upper; ++i) { Dictionary <DateTimeOffset, long> d = dictionaries[i]; int newItemCount = Math.Max(1, d.Count); Fictionary <DateTimeOffset, long, GenericEqualityComparer <DateTimeOffset> > f = fictionaries[i]; for (int k = 0; k != newItemCount; ++k) { long value = (upper << 24) | (i << 16) | k; d.TryAdd(DateTimeOffset.FromFileTime(value), value); f.TryAdd(DateTimeOffset.FromFileTime(value), value); } } } // Assert for (int i = 0; i != count; ++i) { Dictionary <DateTimeOffset, long> d = dictionaries[i]; Fictionary <DateTimeOffset, long, GenericEqualityComparer <DateTimeOffset> > f = fictionaries[i]; Assert.Empty(d.Except(f)); Assert.Empty(f.Except(d)); } }