public void TestWeakHashTavleAddsValuesCorrectly() { ISimpleHashTable <string, string> dictionary = new WeakHashTable <string, string>(1000); dictionary.SetValue("Hello", "World"); Assert.Equal("World", dictionary.GetValue("Hello")); }
public void TestEmptyWeakHashTableDoesNotReturnValues() { // ReSharper disable once CollectionNeverUpdated.Local ISimpleHashTable <string, string> dictionary = new WeakHashTable <string, string>(1000); Assert.False(dictionary.TryGetValue("John", out string _)); Assert.False(dictionary.TryGetValue(string.Empty, out string _)); }
public void TestEmptyWeakHashTableThrowsExceptionOnKeyNotFoud() { // ReSharper disable once CollectionNeverUpdated.Local ISimpleHashTable <string, string> dictionary = new WeakHashTable <string, string>(1000); Assert.Throws <KeyNotFoundException>(() => dictionary.GetValue("Kirill")); Assert.Throws <KeyNotFoundException>(() => dictionary.GetValue("Hello")); }
public void TestEmptyWeakHashTableDoesNotContainKeys() { // ReSharper disable once CollectionNeverUpdated.Local ISimpleHashTable <string, string> dictionary = new WeakHashTable <string, string>(1000); Assert.False(dictionary.ContainsKey("John")); Assert.False(dictionary.ContainsKey(string.Empty)); }
public void TestWeakHashTableReplacesKeysOverShortTime() { ISimpleHashTable <string, string> dictionary = new WeakHashTable <string, string>(1000); dictionary.SetValue("Hello", "World"); dictionary.SetValue("Hello", "Kirill"); Assert.Equal("Kirill", dictionary.GetValue("Hello")); }
public void TestWeakHashTableOnValuesAddedOverLongPeriodOfTime() { ISimpleHashTable <string, MyCustomClass> dictionary = new WeakHashTable <string, MyCustomClass>(1000); dictionary.SetValue("Kirill", new MyCustomClass("Glazyrin")); dictionary.SetValue("Hello", new MyCustomClass("World")); Thread.Sleep(2000); GC.Collect(); Assert.False(dictionary.ContainsKey("Kirill")); Assert.False(dictionary.ContainsKey("Hello")); }
public void TestWeakHashTableOnValuesAddedOverShortPeriodOfTime() { ISimpleHashTable <string, MyCustomClass> dictionary = new WeakHashTable <string, MyCustomClass>(1000); dictionary.SetValue("Kirill", new MyCustomClass("Glazyrin")); dictionary.SetValue("Hello", new MyCustomClass("World")); Assert.True(dictionary.ContainsKey("Kirill")); Assert.True(dictionary.ContainsKey("Hello")); Assert.Equal(new MyCustomClass("Glazyrin"), dictionary.GetValue("Kirill")); Assert.Equal(new MyCustomClass("World"), dictionary.GetValue("Hello")); }
public void TestWeakHashTableHasValidTimeToStore(int duration) { WeakHashTable <string, string> table = new WeakHashTable <string, string>(duration); Assert.Equal(duration, table.TimeToStore); }